Fix style errors

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

@ -30,10 +30,10 @@ type FilebasedCredentialProvider struct {
backingCredentialProvider ICredentialProvider
}
// NamedRepoCredential associates a name with a RepoCredential.
// NamedRepoCredential associates a name with a Credential.
type NamedRepoCredential struct {
Name string `json:"name,omitempty"`
RepoCredential
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.RepoCredential)
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) (*RepoCredential, 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 *RepoCredential) error {
func (fcp *FilebasedCredentialProvider) SetCredential(name string, credential *Credential) error {
return fmt.Errorf("SetCredential operation not supported with FilebasedCredentialProvider")
}

@ -24,7 +24,7 @@ var filename = "./testdata/test_credentials_file.yaml"
type filebasedTestCase struct {
name string
exp *RepoCredential
exp *Credential
expErr error
}
@ -36,14 +36,14 @@ func TestNotExistFilebased(t *testing.T) {
func TestGetApiTokenFilebased(t *testing.T) {
cp := getProvider(t)
tc := &testCase{"test1", &RepoCredential{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", &RepoCredential{BasicAuth: ba}, nil}
tc := &testCase{"test2", &Credential{BasicAuth: ba}, nil}
testGetCredential(t, cp, tc)
}

@ -37,7 +37,7 @@ var GCSChartURLMatcher = regexp.MustCompile("gs://(.*)/(.*)-(.*).tgz")
const (
// GCSRepoType identifies the GCS repository type.
GCSRepoType = RepoType("gcs")
GCSRepoType = ERepoType("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 ERepoType) error {
switch repoType {
case GCSRepoType:
return nil

@ -24,16 +24,16 @@ import (
// InmemCredentialProvider is a memory based credential provider.
type InmemCredentialProvider struct {
sync.RWMutex
credentials map[string]*RepoCredential
credentials map[string]*Credential
}
// NewInmemCredentialProvider creates a new memory based credential provider.
func NewInmemCredentialProvider() ICredentialProvider {
return &InmemCredentialProvider{credentials: make(map[string]*RepoCredential)}
return &InmemCredentialProvider{credentials: make(map[string]*Credential)}
}
// GetCredential returns a credential by name.
func (fcp *InmemCredentialProvider) GetCredential(name string) (*RepoCredential, 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 *RepoCredential) error {
func (fcp *InmemCredentialProvider) SetCredential(name string, credential *Credential) error {
fcp.Lock()
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
}

@ -24,7 +24,7 @@ import (
type testCase struct {
name string
exp *RepoCredential
exp *Credential
expErr error
}
@ -60,13 +60,13 @@ func TestNotExist(t *testing.T) {
func TestSetAndGetApiToken(t *testing.T) {
cp := NewInmemCredentialProvider()
tc := &testCase{"testcredential", &RepoCredential{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", &RepoCredential{BasicAuth: ba}, nil}
tc := &testCase{"testcredential", &Credential{BasicAuth: ba}, nil}
verifySetAndGetCredential(t, cp, tc)
}

@ -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), 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 == "" {
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 ERepoFormat) 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() ERepoType {
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() ERepoFormat {
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 ERepoType) error {
haveName := tr.GetName()
if haveName != wantName {
return fmt.Errorf("unexpected repository name; want: %s, have %s", wantName, haveName)

@ -29,8 +29,8 @@ import (
"sync"
)
// RepoProvider is a factory for IChartRepo instances.
type RepoProvider interface {
// IRepoProvider is a factory for IChartRepo instances.
type IRepoProvider 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) IRepoProvider {
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)
rs := rp.GetRepoService()
tr, err := newRepo(TestRepoName, TestRepoURL, TestRepoCredentialName, TestRepoFormat, TestRepoType)

@ -70,7 +70,7 @@ func NewSecretsCredentialProvider() ICredentialProvider {
return &SecretsCredentialProvider{util.NewKubernetesKubectl(kubernetesConfig)}
}
func parseCredential(credential string) (*RepoCredential, 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 RepoCredential
r := &RepoCredential{}
// 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) (*RepoCredential, 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 *RepoCredential) error {
func (scp *SecretsCredentialProvider) SetCredential(name string, credential *Credential) error {
// Marshal the credential & base64 encode it.
b, err := yaml.Marshal(credential)
if err != nil {

@ -37,8 +37,8 @@ type APITokenCredential string
// JWTTokenCredential defines a JWT token.
type JWTTokenCredential string
// RepoCredential holds a credential used to access a repository.
type RepoCredential 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,24 +48,24 @@ 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 *RepoCredential) 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) (*RepoCredential, error)
GetCredential(name string) (*Credential, error)
}
// RepoType defines the technology that implements a repository.
type RepoType string
// ERepoType defines the technology that implements a repository.
type ERepoType string
// RepoFormat is a semi-colon delimited string that describes the format of a repository.
type RepoFormat string
// ERepoFormat is a semi-colon delimited string that describes the format of a repository.
type ERepoFormat string
const (
// 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 = RepoFormat("flat")
FlatRepoFormat = ERepoFormat("flat")
)
// Repo describes a repository
@ -73,8 +73,8 @@ 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
Format ERepoFormat `json:"format"` // Format of this repository
Type ERepoType `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() ERepoFormat
// GetType returns the technology implementing this repository.
GetType() RepoType
GetType() ERepoType
}
// IChartRepo abstracts a place that holds charts.

Loading…
Cancel
Save