Fix style errors

pull/433/head
jackgr 9 years ago
parent b2570ef1a0
commit 511ac5d164

@ -30,10 +30,10 @@ type FilebasedCredentialProvider struct {
backingCredentialProvider ICredentialProvider backingCredentialProvider ICredentialProvider
} }
// NamedRepoCredential associates a name with a RepoCredential. // NamedRepoCredential associates a name with a Credential.
type NamedRepoCredential struct { type NamedRepoCredential struct {
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
RepoCredential Credential
} }
// NewFilebasedCredentialProvider creates a file based credential provider. // NewFilebasedCredentialProvider creates a file based credential provider.
@ -47,7 +47,7 @@ func NewFilebasedCredentialProvider(filename string) (ICredentialProvider, error
for _, nc := range c { for _, nc := range c {
log.Printf("Loading credential named %s", nc.Name) log.Printf("Loading credential named %s", nc.Name)
icp.SetCredential(nc.Name, &nc.RepoCredential) icp.SetCredential(nc.Name, &nc.Credential)
} }
return &FilebasedCredentialProvider{icp}, nil return &FilebasedCredentialProvider{icp}, nil
@ -72,11 +72,11 @@ func parseCredentials(bytes []byte) ([]NamedRepoCredential, error) {
} }
// GetCredential returns a credential by name. // GetCredential returns a credential by name.
func (fcp *FilebasedCredentialProvider) GetCredential(name string) (*RepoCredential, error) { func (fcp *FilebasedCredentialProvider) GetCredential(name string) (*Credential, error) {
return fcp.backingCredentialProvider.GetCredential(name) return fcp.backingCredentialProvider.GetCredential(name)
} }
// SetCredential sets a credential by name. // SetCredential sets a credential by name.
func (fcp *FilebasedCredentialProvider) SetCredential(name string, credential *RepoCredential) error { func (fcp *FilebasedCredentialProvider) SetCredential(name string, credential *Credential) error {
return fmt.Errorf("SetCredential operation not supported with FilebasedCredentialProvider") return fmt.Errorf("SetCredential operation not supported with FilebasedCredentialProvider")
} }

@ -24,7 +24,7 @@ var filename = "./testdata/test_credentials_file.yaml"
type filebasedTestCase struct { type filebasedTestCase struct {
name string name string
exp *RepoCredential exp *Credential
expErr error expErr error
} }
@ -36,14 +36,14 @@ func TestNotExistFilebased(t *testing.T) {
func TestGetApiTokenFilebased(t *testing.T) { func TestGetApiTokenFilebased(t *testing.T) {
cp := getProvider(t) cp := getProvider(t)
tc := &testCase{"test1", &RepoCredential{APIToken: "token"}, nil} tc := &testCase{"test1", &Credential{APIToken: "token"}, nil}
testGetCredential(t, cp, tc) testGetCredential(t, cp, tc)
} }
func TestSetAndGetBasicAuthFilebased(t *testing.T) { func TestSetAndGetBasicAuthFilebased(t *testing.T) {
cp := getProvider(t) cp := getProvider(t)
ba := BasicAuthCredential{Username: "user", Password: "password"} ba := BasicAuthCredential{Username: "user", Password: "password"}
tc := &testCase{"test2", &RepoCredential{BasicAuth: ba}, nil} tc := &testCase{"test2", &Credential{BasicAuth: ba}, nil}
testGetCredential(t, cp, tc) testGetCredential(t, cp, tc)
} }

@ -37,7 +37,7 @@ var GCSChartURLMatcher = regexp.MustCompile("gs://(.*)/(.*)-(.*).tgz")
const ( const (
// GCSRepoType identifies the GCS repository type. // GCSRepoType identifies the GCS repository type.
GCSRepoType = RepoType("gcs") GCSRepoType = ERepoType("gcs")
// GCSRepoFormat identifies the GCS repository format. // GCSRepoFormat identifies the GCS repository format.
// In a GCS repository all charts appear at the top level. // 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 return gcsr, nil
} }
func validateRepoType(repoType RepoType) error { func validateRepoType(repoType ERepoType) error {
switch repoType { switch repoType {
case GCSRepoType: case GCSRepoType:
return nil return nil

@ -24,16 +24,16 @@ import (
// InmemCredentialProvider is a memory based credential provider. // InmemCredentialProvider is a memory based credential provider.
type InmemCredentialProvider struct { type InmemCredentialProvider struct {
sync.RWMutex sync.RWMutex
credentials map[string]*RepoCredential credentials map[string]*Credential
} }
// NewInmemCredentialProvider creates a new memory based credential provider. // NewInmemCredentialProvider creates a new memory based credential provider.
func NewInmemCredentialProvider() ICredentialProvider { func NewInmemCredentialProvider() ICredentialProvider {
return &InmemCredentialProvider{credentials: make(map[string]*RepoCredential)} return &InmemCredentialProvider{credentials: make(map[string]*Credential)}
} }
// 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) (*Credential, error) {
fcp.RLock() fcp.RLock()
defer fcp.RUnlock() defer fcp.RUnlock()
@ -45,10 +45,10 @@ func (fcp *InmemCredentialProvider) GetCredential(name string) (*RepoCredential,
} }
// 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 *Credential) error {
fcp.Lock() fcp.Lock()
defer fcp.Unlock() defer fcp.Unlock()
fcp.credentials[name] = &RepoCredential{APIToken: credential.APIToken, BasicAuth: credential.BasicAuth, ServiceAccount: credential.ServiceAccount} fcp.credentials[name] = &Credential{APIToken: credential.APIToken, BasicAuth: credential.BasicAuth, ServiceAccount: credential.ServiceAccount}
return nil return nil
} }

@ -24,7 +24,7 @@ import (
type testCase struct { type testCase struct {
name string name string
exp *RepoCredential exp *Credential
expErr error expErr error
} }
@ -60,13 +60,13 @@ func TestNotExist(t *testing.T) {
func TestSetAndGetApiToken(t *testing.T) { func TestSetAndGetApiToken(t *testing.T) {
cp := NewInmemCredentialProvider() cp := NewInmemCredentialProvider()
tc := &testCase{"testcredential", &RepoCredential{APIToken: "some token here"}, nil} tc := &testCase{"testcredential", &Credential{APIToken: "some token here"}, nil}
verifySetAndGetCredential(t, cp, tc) verifySetAndGetCredential(t, cp, tc)
} }
func TestSetAndGetBasicAuth(t *testing.T) { func TestSetAndGetBasicAuth(t *testing.T) {
cp := NewInmemCredentialProvider() cp := NewInmemCredentialProvider()
ba := BasicAuthCredential{Username: "user", Password: "pass"} ba := BasicAuthCredential{Username: "user", Password: "pass"}
tc := &testCase{"testcredential", &RepoCredential{BasicAuth: ba}, nil} tc := &testCase{"testcredential", &Credential{BasicAuth: ba}, nil}
verifySetAndGetCredential(t, cp, tc) verifySetAndGetCredential(t, cp, tc)
} }

@ -23,10 +23,10 @@ import (
// NewRepo takes params and returns a IRepo // NewRepo takes params and returns a IRepo
func NewRepo(name, URL, credentialName, repoFormat, repoType string) (IRepo, error) { 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), ERepoType(repoType))
} }
func newRepo(name, URL, credentialName string, repoFormat RepoFormat, repoType RepoType) (*Repo, error) { func newRepo(name, URL, credentialName string, repoFormat ERepoFormat, repoType ERepoType) (*Repo, error) {
if name == "" { if name == "" {
return nil, fmt.Errorf("name must not be empty") 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. // Currently, only flat repositories are supported.
func validateRepoFormat(repoFormat RepoFormat) error { func validateRepoFormat(repoFormat ERepoFormat) error {
switch repoFormat { switch repoFormat {
case FlatRepoFormat: case FlatRepoFormat:
return nil return nil
@ -71,7 +71,7 @@ func (r *Repo) GetName() string {
} }
// GetType returns the technology implementing this repository. // GetType returns the technology implementing this repository.
func (r *Repo) GetType() RepoType { func (r *Repo) GetType() ERepoType {
return r.Type return r.Type
} }
@ -81,7 +81,7 @@ func (r *Repo) GetURL() string {
} }
// GetFormat returns the format of this repository. // GetFormat returns the format of this repository.
func (r *Repo) GetFormat() RepoFormat { func (r *Repo) GetFormat() ERepoFormat {
return r.Format return r.Format
} }
@ -90,7 +90,7 @@ func (r *Repo) GetCredentialName() string {
return r.CredentialName 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 ERepoType) error {
haveName := tr.GetName() haveName := tr.GetName()
if haveName != wantName { if haveName != wantName {
return fmt.Errorf("unexpected repository name; want: %s, have %s", wantName, haveName) return fmt.Errorf("unexpected repository name; want: %s, have %s", wantName, haveName)

@ -29,8 +29,8 @@ import (
"sync" "sync"
) )
// RepoProvider is a factory for IChartRepo instances. // IRepoProvider is a factory for IChartRepo instances.
type RepoProvider interface { type IRepoProvider interface {
GetRepoByURL(URL string) (IChartRepo, error) GetRepoByURL(URL string) (IChartRepo, error)
GetRepoByName(repoName string) (IChartRepo, error) GetRepoByName(repoName string) (IChartRepo, error)
GetChartByReference(reference string) (*chart.Chart, error) GetChartByReference(reference string) (*chart.Chart, error)
@ -45,7 +45,7 @@ type repoProvider struct {
} }
// NewRepoProvider creates a new repository provider. // NewRepoProvider creates a new repository provider.
func NewRepoProvider(rs IRepoService, gcsrp GCSRepoProvider, cp ICredentialProvider) RepoProvider { func NewRepoProvider(rs IRepoService, gcsrp GCSRepoProvider, cp ICredentialProvider) IRepoProvider {
return newRepoProvider(rs, gcsrp, cp) return newRepoProvider(rs, gcsrp, cp)
} }

@ -112,7 +112,7 @@ func TestGetChartByReferenceWithValidReferences(t *testing.T) {
} }
} }
func getTestRepoProvider(t *testing.T) RepoProvider { func getTestRepoProvider(t *testing.T) IRepoProvider {
rp := newRepoProvider(nil, nil, nil) rp := newRepoProvider(nil, nil, nil)
rs := rp.GetRepoService() rs := rp.GetRepoService()
tr, err := newRepo(TestRepoName, TestRepoURL, TestRepoCredentialName, TestRepoFormat, TestRepoType) tr, err := newRepo(TestRepoName, TestRepoURL, TestRepoCredentialName, TestRepoFormat, TestRepoType)

@ -70,7 +70,7 @@ func NewSecretsCredentialProvider() ICredentialProvider {
return &SecretsCredentialProvider{util.NewKubernetesKubectl(kubernetesConfig)} return &SecretsCredentialProvider{util.NewKubernetesKubectl(kubernetesConfig)}
} }
func parseCredential(credential string) (*RepoCredential, error) { func parseCredential(credential string) (*Credential, error) {
var c common.KubernetesSecret var c common.KubernetesSecret
if err := json.Unmarshal([]byte(credential), &c); err != nil { if err := json.Unmarshal([]byte(credential), &c); err != nil {
return nil, fmt.Errorf("cannot unmarshal credential (%s): %s", credential, err) 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) return nil, fmt.Errorf("cannot unmarshal credential (%s): %s", c, err)
} }
// And then finally unmarshal it from yaml to RepoCredential // And then finally unmarshal it from yaml to Credential
r := &RepoCredential{} r := &Credential{}
if err := yaml.Unmarshal(d, &r); err != nil { if err := yaml.Unmarshal(d, &r); err != nil {
return nil, fmt.Errorf("cannot unmarshal credential %s (%#v)", c, err) 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. // GetCredential returns a credential by name.
func (scp *SecretsCredentialProvider) GetCredential(name string) (*RepoCredential, error) { func (scp *SecretsCredentialProvider) GetCredential(name string) (*Credential, error) {
o, err := scp.k.Get(name, secretType) o, err := scp.k.Get(name, secretType)
if err != nil { if err != nil {
return nil, err return nil, err
@ -101,7 +101,7 @@ func (scp *SecretsCredentialProvider) GetCredential(name string) (*RepoCredentia
} }
// SetCredential sets a credential by name. // SetCredential sets a credential by name.
func (scp *SecretsCredentialProvider) SetCredential(name string, credential *RepoCredential) error { func (scp *SecretsCredentialProvider) SetCredential(name string, credential *Credential) error {
// Marshal the credential & base64 encode it. // Marshal the credential & base64 encode it.
b, err := yaml.Marshal(credential) b, err := yaml.Marshal(credential)
if err != nil { if err != nil {

@ -37,8 +37,8 @@ type APITokenCredential string
// JWTTokenCredential defines a JWT token. // JWTTokenCredential defines a JWT token.
type JWTTokenCredential string type JWTTokenCredential string
// RepoCredential holds a credential used to access a repository. // Credential holds a credential used to access a repository.
type RepoCredential struct { type Credential struct {
APIToken APITokenCredential `json:"apitoken,omitempty"` APIToken APITokenCredential `json:"apitoken,omitempty"`
BasicAuth BasicAuthCredential `json:"basicauth,omitempty"` BasicAuth BasicAuthCredential `json:"basicauth,omitempty"`
ServiceAccount JWTTokenCredential `json:"serviceaccount,omitempty"` ServiceAccount JWTTokenCredential `json:"serviceaccount,omitempty"`
@ -48,24 +48,24 @@ type RepoCredential struct {
type ICredentialProvider interface { type ICredentialProvider interface {
// SetCredential sets the credential for a repository. // SetCredential sets the credential for a repository.
// May not be supported by some repository services. // May not be supported by some repository services.
SetCredential(name string, credential *RepoCredential) error SetCredential(name string, credential *Credential) error
// GetCredential returns the specified credential or nil if there's no credential. // GetCredential returns the specified credential or nil if there's no credential.
// Error is non-nil if fetching the credential failed. // Error is non-nil if fetching the credential failed.
GetCredential(name string) (*RepoCredential, error) GetCredential(name string) (*Credential, error)
} }
// RepoType defines the technology that implements a repository. // ERepoType defines the technology that implements a repository.
type RepoType string type ERepoType string
// RepoFormat is a semi-colon delimited string that describes the format of a repository. // ERepoFormat is a semi-colon delimited string that describes the format of a repository.
type RepoFormat string type ERepoFormat string
const ( const (
// PathRepoFormat identfies a repository where charts are organized hierarchically. // PathRepoFormat identfies a repository where charts are organized hierarchically.
PathRepoFormat = RepoFormat("path") PathRepoFormat = ERepoFormat("path")
// FlatRepoFormat identifies a repository where all charts appear at the top level. // FlatRepoFormat identifies a repository where all charts appear at the top level.
FlatRepoFormat = RepoFormat("flat") FlatRepoFormat = ERepoFormat("flat")
) )
// Repo describes a repository // Repo describes a repository
@ -73,8 +73,8 @@ type Repo struct {
Name string `json:"name"` // Friendly name for this repository Name string `json:"name"` // Friendly name for this repository
URL string `json:"url"` // URL to the root of this repository URL string `json:"url"` // URL to the root of this repository
CredentialName string `json:"credentialname"` // Credential name used to access this repository CredentialName string `json:"credentialname"` // Credential name used to access this repository
Format RepoFormat `json:"format"` // Format of this repository Format ERepoFormat `json:"format"` // Format of this repository
Type RepoType `json:"type"` // Technology implementing this repository Type ERepoType `json:"type"` // Technology implementing this repository
} }
// IRepo abstracts a repository. // IRepo abstracts a repository.
@ -86,9 +86,9 @@ type IRepo interface {
// GetCredentialName returns the credential name used to access this repository. // GetCredentialName returns the credential name used to access this repository.
GetCredentialName() string GetCredentialName() string
// GetFormat returns the format of this repository. // GetFormat returns the format of this repository.
GetFormat() RepoFormat GetFormat() ERepoFormat
// GetType returns the technology implementing this repository. // GetType returns the technology implementing this repository.
GetType() RepoType GetType() ERepoType
} }
// IChartRepo abstracts a place that holds charts. // IChartRepo abstracts a place that holds charts.

Loading…
Cancel
Save