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
511ac5d1
Commit
511ac5d1
authored
Mar 22, 2016
by
jackgr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix style errors
parent
b2570ef1
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
50 additions
and
50 deletions
+50
-50
filebased_credential_provider.go
pkg/repo/filebased_credential_provider.go
+5
-5
filebased_credential_provider_test.go
pkg/repo/filebased_credential_provider_test.go
+3
-3
gcs_repo.go
pkg/repo/gcs_repo.go
+2
-2
inmem_credential_provider.go
pkg/repo/inmem_credential_provider.go
+5
-5
inmem_credential_provider_test.go
pkg/repo/inmem_credential_provider_test.go
+3
-3
repo.go
pkg/repo/repo.go
+6
-6
repoprovider.go
pkg/repo/repoprovider.go
+3
-3
repoprovider_test.go
pkg/repo/repoprovider_test.go
+1
-1
secrets_credential_provider.go
pkg/repo/secrets_credential_provider.go
+5
-5
types.go
pkg/repo/types.go
+17
-17
No files found.
pkg/repo/filebased_credential_provider.go
View file @
511ac5d1
...
...
@@ -30,10 +30,10 @@ type FilebasedCredentialProvider struct {
backingCredentialProvider
ICredentialProvider
}
// NamedRepoCredential associates a name with a
Repo
Credential.
// NamedRepoCredential associates a name with a Credential.
type
NamedRepoCredential
struct
{
Name
string
`json:"name,omitempty"`
Repo
Credential
Credential
}
// NewFilebasedCredentialProvider creates a file based credential provider.
...
...
@@ -47,7 +47,7 @@ func NewFilebasedCredentialProvider(filename string) (ICredentialProvider, error
for
_
,
nc
:=
range
c
{
log
.
Printf
(
"Loading credential named %s"
,
nc
.
Name
)
icp
.
SetCredential
(
nc
.
Name
,
&
nc
.
Repo
Credential
)
icp
.
SetCredential
(
nc
.
Name
,
&
nc
.
Credential
)
}
return
&
FilebasedCredentialProvider
{
icp
},
nil
...
...
@@ -72,11 +72,11 @@ func parseCredentials(bytes []byte) ([]NamedRepoCredential, error) {
}
// GetCredential returns a credential by name.
func
(
fcp
*
FilebasedCredentialProvider
)
GetCredential
(
name
string
)
(
*
Repo
Credential
,
error
)
{
func
(
fcp
*
FilebasedCredentialProvider
)
GetCredential
(
name
string
)
(
*
Credential
,
error
)
{
return
fcp
.
backingCredentialProvider
.
GetCredential
(
name
)
}
// SetCredential sets a credential by name.
func
(
fcp
*
FilebasedCredentialProvider
)
SetCredential
(
name
string
,
credential
*
Repo
Credential
)
error
{
func
(
fcp
*
FilebasedCredentialProvider
)
SetCredential
(
name
string
,
credential
*
Credential
)
error
{
return
fmt
.
Errorf
(
"SetCredential operation not supported with FilebasedCredentialProvider"
)
}
pkg/repo/filebased_credential_provider_test.go
View file @
511ac5d1
...
...
@@ -24,7 +24,7 @@ var filename = "./testdata/test_credentials_file.yaml"
type
filebasedTestCase
struct
{
name
string
exp
*
Repo
Credential
exp
*
Credential
expErr
error
}
...
...
@@ -36,14 +36,14 @@ func TestNotExistFilebased(t *testing.T) {
func
TestGetApiTokenFilebased
(
t
*
testing
.
T
)
{
cp
:=
getProvider
(
t
)
tc
:=
&
testCase
{
"test1"
,
&
Repo
Credential
{
APIToken
:
"token"
},
nil
}
tc
:=
&
testCase
{
"test1"
,
&
Credential
{
APIToken
:
"token"
},
nil
}
testGetCredential
(
t
,
cp
,
tc
)
}
func
TestSetAndGetBasicAuthFilebased
(
t
*
testing
.
T
)
{
cp
:=
getProvider
(
t
)
ba
:=
BasicAuthCredential
{
Username
:
"user"
,
Password
:
"password"
}
tc
:=
&
testCase
{
"test2"
,
&
Repo
Credential
{
BasicAuth
:
ba
},
nil
}
tc
:=
&
testCase
{
"test2"
,
&
Credential
{
BasicAuth
:
ba
},
nil
}
testGetCredential
(
t
,
cp
,
tc
)
}
...
...
pkg/repo/gcs_repo.go
View file @
511ac5d1
...
...
@@ -37,7 +37,7 @@ var GCSChartURLMatcher = regexp.MustCompile("gs://(.*)/(.*)-(.*).tgz")
const
(
// GCSRepoType identifies the GCS repository type.
GCSRepoType
=
RepoType
(
"gcs"
)
GCSRepoType
=
E
RepoType
(
"gcs"
)
// GCSRepoFormat identifies the GCS repository format.
// In a GCS repository all charts appear at the top level.
...
...
@@ -106,7 +106,7 @@ func newGCSRepo(r *Repo, httpClient *http.Client) (*GCSRepo, error) {
return
gcsr
,
nil
}
func
validateRepoType
(
repoType
RepoType
)
error
{
func
validateRepoType
(
repoType
E
RepoType
)
error
{
switch
repoType
{
case
GCSRepoType
:
return
nil
...
...
pkg/repo/inmem_credential_provider.go
View file @
511ac5d1
...
...
@@ -24,16 +24,16 @@ import (
// InmemCredentialProvider is a memory based credential provider.
type
InmemCredentialProvider
struct
{
sync
.
RWMutex
credentials
map
[
string
]
*
Repo
Credential
credentials
map
[
string
]
*
Credential
}
// NewInmemCredentialProvider creates a new memory based credential provider.
func
NewInmemCredentialProvider
()
ICredentialProvider
{
return
&
InmemCredentialProvider
{
credentials
:
make
(
map
[
string
]
*
Repo
Credential
)}
return
&
InmemCredentialProvider
{
credentials
:
make
(
map
[
string
]
*
Credential
)}
}
// GetCredential returns a credential by name.
func
(
fcp
*
InmemCredentialProvider
)
GetCredential
(
name
string
)
(
*
Repo
Credential
,
error
)
{
func
(
fcp
*
InmemCredentialProvider
)
GetCredential
(
name
string
)
(
*
Credential
,
error
)
{
fcp
.
RLock
()
defer
fcp
.
RUnlock
()
...
...
@@ -45,10 +45,10 @@ func (fcp *InmemCredentialProvider) GetCredential(name string) (*RepoCredential,
}
// SetCredential sets a credential by name.
func
(
fcp
*
InmemCredentialProvider
)
SetCredential
(
name
string
,
credential
*
Repo
Credential
)
error
{
func
(
fcp
*
InmemCredentialProvider
)
SetCredential
(
name
string
,
credential
*
Credential
)
error
{
fcp
.
Lock
()
defer
fcp
.
Unlock
()
fcp
.
credentials
[
name
]
=
&
Repo
Credential
{
APIToken
:
credential
.
APIToken
,
BasicAuth
:
credential
.
BasicAuth
,
ServiceAccount
:
credential
.
ServiceAccount
}
fcp
.
credentials
[
name
]
=
&
Credential
{
APIToken
:
credential
.
APIToken
,
BasicAuth
:
credential
.
BasicAuth
,
ServiceAccount
:
credential
.
ServiceAccount
}
return
nil
}
pkg/repo/inmem_credential_provider_test.go
View file @
511ac5d1
...
...
@@ -24,7 +24,7 @@ import (
type
testCase
struct
{
name
string
exp
*
Repo
Credential
exp
*
Credential
expErr
error
}
...
...
@@ -60,13 +60,13 @@ func TestNotExist(t *testing.T) {
func
TestSetAndGetApiToken
(
t
*
testing
.
T
)
{
cp
:=
NewInmemCredentialProvider
()
tc
:=
&
testCase
{
"testcredential"
,
&
Repo
Credential
{
APIToken
:
"some token here"
},
nil
}
tc
:=
&
testCase
{
"testcredential"
,
&
Credential
{
APIToken
:
"some token here"
},
nil
}
verifySetAndGetCredential
(
t
,
cp
,
tc
)
}
func
TestSetAndGetBasicAuth
(
t
*
testing
.
T
)
{
cp
:=
NewInmemCredentialProvider
()
ba
:=
BasicAuthCredential
{
Username
:
"user"
,
Password
:
"pass"
}
tc
:=
&
testCase
{
"testcredential"
,
&
Repo
Credential
{
BasicAuth
:
ba
},
nil
}
tc
:=
&
testCase
{
"testcredential"
,
&
Credential
{
BasicAuth
:
ba
},
nil
}
verifySetAndGetCredential
(
t
,
cp
,
tc
)
}
pkg/repo/repo.go
View file @
511ac5d1
...
...
@@ -23,10 +23,10 @@ import (
// NewRepo takes params and returns a IRepo
func
NewRepo
(
name
,
URL
,
credentialName
,
repoFormat
,
repoType
string
)
(
IRepo
,
error
)
{
return
newRepo
(
name
,
URL
,
credentialName
,
RepoFormat
(
repoFormat
),
RepoType
(
repoType
))
return
newRepo
(
name
,
URL
,
credentialName
,
ERepoFormat
(
repoFormat
),
E
RepoType
(
repoType
))
}
func
newRepo
(
name
,
URL
,
credentialName
string
,
repoFormat
RepoFormat
,
repoType
RepoType
)
(
*
Repo
,
error
)
{
func
newRepo
(
name
,
URL
,
credentialName
string
,
repoFormat
ERepoFormat
,
repoType
E
RepoType
)
(
*
Repo
,
error
)
{
if
name
==
""
{
return
nil
,
fmt
.
Errorf
(
"name must not be empty"
)
}
...
...
@@ -56,7 +56,7 @@ func newRepo(name, URL, credentialName string, repoFormat RepoFormat, repoType R
}
// Currently, only flat repositories are supported.
func
validateRepoFormat
(
repoFormat
RepoFormat
)
error
{
func
validateRepoFormat
(
repoFormat
E
RepoFormat
)
error
{
switch
repoFormat
{
case
FlatRepoFormat
:
return
nil
...
...
@@ -71,7 +71,7 @@ func (r *Repo) GetName() string {
}
// GetType returns the technology implementing this repository.
func
(
r
*
Repo
)
GetType
()
RepoType
{
func
(
r
*
Repo
)
GetType
()
E
RepoType
{
return
r
.
Type
}
...
...
@@ -81,7 +81,7 @@ func (r *Repo) GetURL() string {
}
// GetFormat returns the format of this repository.
func
(
r
*
Repo
)
GetFormat
()
RepoFormat
{
func
(
r
*
Repo
)
GetFormat
()
E
RepoFormat
{
return
r
.
Format
}
...
...
@@ -90,7 +90,7 @@ func (r *Repo) GetCredentialName() string {
return
r
.
CredentialName
}
func
validateRepo
(
tr
IRepo
,
wantName
,
wantURL
,
wantCredentialName
string
,
wantFormat
RepoFormat
,
wantType
RepoType
)
error
{
func
validateRepo
(
tr
IRepo
,
wantName
,
wantURL
,
wantCredentialName
string
,
wantFormat
ERepoFormat
,
wantType
E
RepoType
)
error
{
haveName
:=
tr
.
GetName
()
if
haveName
!=
wantName
{
return
fmt
.
Errorf
(
"unexpected repository name; want: %s, have %s"
,
wantName
,
haveName
)
...
...
pkg/repo/repoprovider.go
View file @
511ac5d1
...
...
@@ -29,8 +29,8 @@ import (
"sync"
)
// RepoProvider is a factory for IChartRepo instances.
type
RepoProvider
interface
{
//
I
RepoProvider is a factory for IChartRepo instances.
type
I
RepoProvider
interface
{
GetRepoByURL
(
URL
string
)
(
IChartRepo
,
error
)
GetRepoByName
(
repoName
string
)
(
IChartRepo
,
error
)
GetChartByReference
(
reference
string
)
(
*
chart
.
Chart
,
error
)
...
...
@@ -45,7 +45,7 @@ type repoProvider struct {
}
// NewRepoProvider creates a new repository provider.
func
NewRepoProvider
(
rs
IRepoService
,
gcsrp
GCSRepoProvider
,
cp
ICredentialProvider
)
RepoProvider
{
func
NewRepoProvider
(
rs
IRepoService
,
gcsrp
GCSRepoProvider
,
cp
ICredentialProvider
)
I
RepoProvider
{
return
newRepoProvider
(
rs
,
gcsrp
,
cp
)
}
...
...
pkg/repo/repoprovider_test.go
View file @
511ac5d1
...
...
@@ -112,7 +112,7 @@ func TestGetChartByReferenceWithValidReferences(t *testing.T) {
}
}
func
getTestRepoProvider
(
t
*
testing
.
T
)
RepoProvider
{
func
getTestRepoProvider
(
t
*
testing
.
T
)
I
RepoProvider
{
rp
:=
newRepoProvider
(
nil
,
nil
,
nil
)
rs
:=
rp
.
GetRepoService
()
tr
,
err
:=
newRepo
(
TestRepoName
,
TestRepoURL
,
TestRepoCredentialName
,
TestRepoFormat
,
TestRepoType
)
...
...
pkg/repo/secrets_credential_provider.go
View file @
511ac5d1
...
...
@@ -70,7 +70,7 @@ func NewSecretsCredentialProvider() ICredentialProvider {
return
&
SecretsCredentialProvider
{
util
.
NewKubernetesKubectl
(
kubernetesConfig
)}
}
func
parseCredential
(
credential
string
)
(
*
Repo
Credential
,
error
)
{
func
parseCredential
(
credential
string
)
(
*
Credential
,
error
)
{
var
c
common
.
KubernetesSecret
if
err
:=
json
.
Unmarshal
([]
byte
(
credential
),
&
c
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"cannot unmarshal credential (%s): %s"
,
credential
,
err
)
...
...
@@ -81,8 +81,8 @@ func parseCredential(credential string) (*RepoCredential, error) {
return
nil
,
fmt
.
Errorf
(
"cannot unmarshal credential (%s): %s"
,
c
,
err
)
}
// And then finally unmarshal it from yaml to
Repo
Credential
r
:=
&
Repo
Credential
{}
// And then finally unmarshal it from yaml to Credential
r
:=
&
Credential
{}
if
err
:=
yaml
.
Unmarshal
(
d
,
&
r
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"cannot unmarshal credential %s (%#v)"
,
c
,
err
)
}
...
...
@@ -91,7 +91,7 @@ func parseCredential(credential string) (*RepoCredential, error) {
}
// GetCredential returns a credential by name.
func
(
scp
*
SecretsCredentialProvider
)
GetCredential
(
name
string
)
(
*
Repo
Credential
,
error
)
{
func
(
scp
*
SecretsCredentialProvider
)
GetCredential
(
name
string
)
(
*
Credential
,
error
)
{
o
,
err
:=
scp
.
k
.
Get
(
name
,
secretType
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -101,7 +101,7 @@ func (scp *SecretsCredentialProvider) GetCredential(name string) (*RepoCredentia
}
// SetCredential sets a credential by name.
func
(
scp
*
SecretsCredentialProvider
)
SetCredential
(
name
string
,
credential
*
Repo
Credential
)
error
{
func
(
scp
*
SecretsCredentialProvider
)
SetCredential
(
name
string
,
credential
*
Credential
)
error
{
// Marshal the credential & base64 encode it.
b
,
err
:=
yaml
.
Marshal
(
credential
)
if
err
!=
nil
{
...
...
pkg/repo/types.go
View file @
511ac5d1
...
...
@@ -37,8 +37,8 @@ type APITokenCredential string
// JWTTokenCredential defines a JWT token.
type
JWTTokenCredential
string
//
Repo
Credential holds a credential used to access a repository.
type
Repo
Credential
struct
{
// Credential holds a credential used to access a repository.
type
Credential
struct
{
APIToken
APITokenCredential
`json:"apitoken,omitempty"`
BasicAuth
BasicAuthCredential
`json:"basicauth,omitempty"`
ServiceAccount
JWTTokenCredential
`json:"serviceaccount,omitempty"`
...
...
@@ -48,33 +48,33 @@ type RepoCredential struct {
type
ICredentialProvider
interface
{
// SetCredential sets the credential for a repository.
// May not be supported by some repository services.
SetCredential
(
name
string
,
credential
*
Repo
Credential
)
error
SetCredential
(
name
string
,
credential
*
Credential
)
error
// GetCredential returns the specified credential or nil if there's no credential.
// Error is non-nil if fetching the credential failed.
GetCredential
(
name
string
)
(
*
Repo
Credential
,
error
)
GetCredential
(
name
string
)
(
*
Credential
,
error
)
}
// RepoType defines the technology that implements a repository.
type
RepoType
string
//
E
RepoType defines the technology that implements a repository.
type
E
RepoType
string
// RepoFormat is a semi-colon delimited string that describes the format of a repository.
type
RepoFormat
string
//
E
RepoFormat is a semi-colon delimited string that describes the format of a repository.
type
E
RepoFormat
string
const
(
// PathRepoFormat identfies a repository where charts are organized hierarchically.
PathRepoFormat
=
RepoFormat
(
"path"
)
PathRepoFormat
=
E
RepoFormat
(
"path"
)
// FlatRepoFormat identifies a repository where all charts appear at the top level.
FlatRepoFormat
=
RepoFormat
(
"flat"
)
FlatRepoFormat
=
E
RepoFormat
(
"flat"
)
)
// Repo describes a repository
type
Repo
struct
{
Name
string
`json:"name"`
// Friendly name for this repository
URL
string
`json:"url"`
// URL to the root of this repository
CredentialName
string
`json:"credentialname"`
// Credential name used to access this repository
Format
RepoFormat
`json:"format"`
// Format of this repository
Type
RepoType
`json:"type"`
// Technology implementing this repository
Name
string
`json:"name"`
// Friendly name for this repository
URL
string
`json:"url"`
// URL to the root of this repository
CredentialName
string
`json:"credentialname"`
// Credential name used to access this repository
Format
E
RepoFormat
`json:"format"`
// Format of this repository
Type
E
RepoType
`json:"type"`
// Technology implementing this repository
}
// IRepo abstracts a repository.
...
...
@@ -86,9 +86,9 @@ type IRepo interface {
// GetCredentialName returns the credential name used to access this repository.
GetCredentialName
()
string
// GetFormat returns the format of this repository.
GetFormat
()
RepoFormat
GetFormat
()
E
RepoFormat
// GetType returns the technology implementing this repository.
GetType
()
RepoType
GetType
()
E
RepoType
}
// IChartRepo abstracts a place that holds charts.
...
...
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