Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
helm3
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
helm3
Commits
686bb9ba
Commit
686bb9ba
authored
Mar 21, 2016
by
Jack Greenfield
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #423 from jackgr/credential-provider
Fix race condition
parents
fccd1ba5
216c8308
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
0 deletions
+9
-0
inmem_credential_provider.go
pkg/repo/inmem_credential_provider.go
+9
-0
No files found.
pkg/repo/inmem_credential_provider.go
View file @
686bb9ba
...
@@ -18,10 +18,12 @@ package repo
...
@@ -18,10 +18,12 @@ package repo
import
(
import
(
"fmt"
"fmt"
"sync"
)
)
// InmemCredentialProvider is a memory based credential provider.
// InmemCredentialProvider is a memory based credential provider.
type
InmemCredentialProvider
struct
{
type
InmemCredentialProvider
struct
{
sync
.
RWMutex
credentials
map
[
string
]
*
RepoCredential
credentials
map
[
string
]
*
RepoCredential
}
}
...
@@ -32,14 +34,21 @@ func NewInmemCredentialProvider() CredentialProvider {
...
@@ -32,14 +34,21 @@ func NewInmemCredentialProvider() CredentialProvider {
// GetCredential returns a credential by name.
// GetCredential returns a credential by name.
func
(
fcp
*
InmemCredentialProvider
)
GetCredential
(
name
string
)
(
*
RepoCredential
,
error
)
{
func
(
fcp
*
InmemCredentialProvider
)
GetCredential
(
name
string
)
(
*
RepoCredential
,
error
)
{
fcp
.
RLock
()
defer
fcp
.
RUnlock
()
if
val
,
ok
:=
fcp
.
credentials
[
name
];
ok
{
if
val
,
ok
:=
fcp
.
credentials
[
name
];
ok
{
return
val
,
nil
return
val
,
nil
}
}
return
nil
,
fmt
.
Errorf
(
"no such credential: %s"
,
name
)
return
nil
,
fmt
.
Errorf
(
"no such credential: %s"
,
name
)
}
}
// SetCredential sets a credential by name.
// SetCredential sets a credential by name.
func
(
fcp
*
InmemCredentialProvider
)
SetCredential
(
name
string
,
credential
*
RepoCredential
)
error
{
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
}
fcp
.
credentials
[
name
]
=
&
RepoCredential
{
APIToken
:
credential
.
APIToken
,
BasicAuth
:
credential
.
BasicAuth
,
ServiceAccount
:
credential
.
ServiceAccount
}
return
nil
return
nil
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment