Commit 686bb9ba authored by Jack Greenfield's avatar Jack Greenfield

Merge pull request #423 from jackgr/credential-provider

Fix race condition
parents fccd1ba5 216c8308
......@@ -18,10 +18,12 @@ package repo
import (
"fmt"
"sync"
)
// InmemCredentialProvider is a memory based credential provider.
type InmemCredentialProvider struct {
sync.RWMutex
credentials map[string]*RepoCredential
}
......@@ -32,14 +34,21 @@ func NewInmemCredentialProvider() CredentialProvider {
// GetCredential returns a credential by name.
func (fcp *InmemCredentialProvider) GetCredential(name string) (*RepoCredential, error) {
fcp.RLock()
defer fcp.RUnlock()
if val, ok := fcp.credentials[name]; ok {
return val, nil
}
return nil, fmt.Errorf("no such credential: %s", name)
}
// SetCredential sets a credential by name.
func (fcp *InmemCredentialProvider) SetCredential(name string, credential *RepoCredential) error {
fcp.Lock()
defer fcp.Unlock()
fcp.credentials[name] = &RepoCredential{APIToken: credential.APIToken, BasicAuth: credential.BasicAuth, ServiceAccount: credential.ServiceAccount}
return nil
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment