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
9074ab56
Commit
9074ab56
authored
Mar 22, 2016
by
Jack Greenfield
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #433 from jackgr/public-repo
Make Repo struct public and fix style errors
parents
2724b903
511ac5d1
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
136 additions
and
136 deletions
+136
-136
filebased_credential_provider.go
pkg/repo/filebased_credential_provider.go
+7
-7
filebased_credential_provider_test.go
pkg/repo/filebased_credential_provider_test.go
+4
-4
gcs_repo.go
pkg/repo/gcs_repo.go
+16
-16
gcs_repo_test.go
pkg/repo/gcs_repo_test.go
+1
-1
inmem_credential_provider.go
pkg/repo/inmem_credential_provider.go
+6
-6
inmem_credential_provider_test.go
pkg/repo/inmem_credential_provider_test.go
+5
-5
inmem_repo_service.go
pkg/repo/inmem_repo_service.go
+9
-9
repo.go
pkg/repo/repo.go
+17
-26
repoprovider.go
pkg/repo/repoprovider.go
+23
-23
repoprovider_test.go
pkg/repo/repoprovider_test.go
+3
-3
secrets_credential_provider.go
pkg/repo/secrets_credential_provider.go
+6
-6
types.go
pkg/repo/types.go
+39
-30
No files found.
pkg/repo/filebased_credential_provider.go
View file @
9074ab56
...
@@ -27,17 +27,17 @@ import (
...
@@ -27,17 +27,17 @@ import (
// FilebasedCredentialProvider provides credentials for registries.
// FilebasedCredentialProvider provides credentials for registries.
type
FilebasedCredentialProvider
struct
{
type
FilebasedCredentialProvider
struct
{
// Actual backing store
// Actual backing store
backingCredentialProvider
CredentialProvider
backingCredentialProvider
I
CredentialProvider
}
}
// NamedRepoCredential associates a name with a
Repo
Credential.
// NamedRepoCredential associates a name with a Credential.
type
NamedRepoCredential
struct
{
type
NamedRepoCredential
struct
{
Name
string
`json:"name,omitempty"`
Name
string
`json:"name,omitempty"`
Repo
Credential
Credential
}
}
// NewFilebasedCredentialProvider creates a file based credential provider.
// NewFilebasedCredentialProvider creates a file based credential provider.
func
NewFilebasedCredentialProvider
(
filename
string
)
(
CredentialProvider
,
error
)
{
func
NewFilebasedCredentialProvider
(
filename
string
)
(
I
CredentialProvider
,
error
)
{
icp
:=
NewInmemCredentialProvider
()
icp
:=
NewInmemCredentialProvider
()
log
.
Printf
(
"Using credentials file %s"
,
filename
)
log
.
Printf
(
"Using credentials file %s"
,
filename
)
c
,
err
:=
readCredentialsFile
(
filename
)
c
,
err
:=
readCredentialsFile
(
filename
)
...
@@ -47,7 +47,7 @@ func NewFilebasedCredentialProvider(filename string) (CredentialProvider, error)
...
@@ -47,7 +47,7 @@ func NewFilebasedCredentialProvider(filename string) (CredentialProvider, 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
.
Repo
Credential
)
icp
.
SetCredential
(
nc
.
Name
,
&
nc
.
Credential
)
}
}
return
&
FilebasedCredentialProvider
{
icp
},
nil
return
&
FilebasedCredentialProvider
{
icp
},
nil
...
@@ -72,11 +72,11 @@ func parseCredentials(bytes []byte) ([]NamedRepoCredential, error) {
...
@@ -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
)
(
*
Repo
Credential
,
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
*
Repo
Credential
)
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"
)
}
}
pkg/repo/filebased_credential_provider_test.go
View file @
9074ab56
...
@@ -24,7 +24,7 @@ var filename = "./testdata/test_credentials_file.yaml"
...
@@ -24,7 +24,7 @@ var filename = "./testdata/test_credentials_file.yaml"
type
filebasedTestCase
struct
{
type
filebasedTestCase
struct
{
name
string
name
string
exp
*
Repo
Credential
exp
*
Credential
expErr
error
expErr
error
}
}
...
@@ -36,18 +36,18 @@ func TestNotExistFilebased(t *testing.T) {
...
@@ -36,18 +36,18 @@ func TestNotExistFilebased(t *testing.T) {
func
TestGetApiTokenFilebased
(
t
*
testing
.
T
)
{
func
TestGetApiTokenFilebased
(
t
*
testing
.
T
)
{
cp
:=
getProvider
(
t
)
cp
:=
getProvider
(
t
)
tc
:=
&
testCase
{
"test1"
,
&
Repo
Credential
{
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"
,
&
Repo
Credential
{
BasicAuth
:
ba
},
nil
}
tc
:=
&
testCase
{
"test2"
,
&
Credential
{
BasicAuth
:
ba
},
nil
}
testGetCredential
(
t
,
cp
,
tc
)
testGetCredential
(
t
,
cp
,
tc
)
}
}
func
getProvider
(
t
*
testing
.
T
)
CredentialProvider
{
func
getProvider
(
t
*
testing
.
T
)
I
CredentialProvider
{
cp
,
err
:=
NewFilebasedCredentialProvider
(
filename
)
cp
,
err
:=
NewFilebasedCredentialProvider
(
filename
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"cannot create a new provider from file %s: %s"
,
filename
,
err
)
t
.
Fatalf
(
"cannot create a new provider from file %s: %s"
,
filename
,
err
)
...
...
pkg/repo/gcs_repo.go
View file @
9074ab56
...
@@ -37,7 +37,7 @@ var GCSChartURLMatcher = regexp.MustCompile("gs://(.*)/(.*)-(.*).tgz")
...
@@ -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
=
E
RepoType
(
"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.
...
@@ -53,21 +53,21 @@ const (
...
@@ -53,21 +53,21 @@ const (
GCSPublicRepoBucket
=
GCSPublicRepoName
GCSPublicRepoBucket
=
GCSPublicRepoName
)
)
//
gcsRepo implements the Object
StorageRepo interface for Google Cloud Storage.
//
GCSRepo implements the I
StorageRepo interface for Google Cloud Storage.
type
gcs
Repo
struct
{
type
GCS
Repo
struct
{
r
epo
R
epo
bucket
string
bucket
string
httpClient
*
http
.
Client
httpClient
*
http
.
Client
service
*
storage
.
Service
service
*
storage
.
Service
}
}
// NewPublicGCSRepo creates a new an
Object
StorageRepo for the public GCS repository.
// NewPublicGCSRepo creates a new an
I
StorageRepo for the public GCS repository.
func
NewPublicGCSRepo
(
httpClient
*
http
.
Client
)
(
Object
StorageRepo
,
error
)
{
func
NewPublicGCSRepo
(
httpClient
*
http
.
Client
)
(
I
StorageRepo
,
error
)
{
return
NewGCSRepo
(
GCSPublicRepoName
,
GCSPublicRepoURL
,
""
,
nil
)
return
NewGCSRepo
(
GCSPublicRepoName
,
GCSPublicRepoURL
,
""
,
nil
)
}
}
// NewGCSRepo creates a new
Object
StorageRepo for a given GCS repository.
// NewGCSRepo creates a new
I
StorageRepo for a given GCS repository.
func
NewGCSRepo
(
name
,
URL
,
credentialName
string
,
httpClient
*
http
.
Client
)
(
Object
StorageRepo
,
error
)
{
func
NewGCSRepo
(
name
,
URL
,
credentialName
string
,
httpClient
*
http
.
Client
)
(
I
StorageRepo
,
error
)
{
r
,
err
:=
newRepo
(
name
,
URL
,
credentialName
,
GCSRepoFormat
,
GCSRepoType
)
r
,
err
:=
newRepo
(
name
,
URL
,
credentialName
,
GCSRepoFormat
,
GCSRepoType
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -76,7 +76,7 @@ func NewGCSRepo(name, URL, credentialName string, httpClient *http.Client) (Obje
...
@@ -76,7 +76,7 @@ func NewGCSRepo(name, URL, credentialName string, httpClient *http.Client) (Obje
return
newGCSRepo
(
r
,
httpClient
)
return
newGCSRepo
(
r
,
httpClient
)
}
}
func
newGCSRepo
(
r
*
repo
,
httpClient
*
http
.
Client
)
(
*
gcs
Repo
,
error
)
{
func
newGCSRepo
(
r
*
Repo
,
httpClient
*
http
.
Client
)
(
*
GCS
Repo
,
error
)
{
URL
:=
r
.
GetURL
()
URL
:=
r
.
GetURL
()
m
:=
GCSRepoURLMatcher
.
FindStringSubmatch
(
URL
)
m
:=
GCSRepoURLMatcher
.
FindStringSubmatch
(
URL
)
if
len
(
m
)
!=
2
{
if
len
(
m
)
!=
2
{
...
@@ -96,8 +96,8 @@ func newGCSRepo(r *repo, httpClient *http.Client) (*gcsRepo, error) {
...
@@ -96,8 +96,8 @@ func newGCSRepo(r *repo, httpClient *http.Client) (*gcsRepo, error) {
return
nil
,
fmt
.
Errorf
(
"cannot create storage service for %s: %s"
,
URL
,
err
)
return
nil
,
fmt
.
Errorf
(
"cannot create storage service for %s: %s"
,
URL
,
err
)
}
}
gcsr
:=
&
gcs
Repo
{
gcsr
:=
&
GCS
Repo
{
r
epo
:
*
r
,
R
epo
:
*
r
,
httpClient
:
httpClient
,
httpClient
:
httpClient
,
service
:
gcs
,
service
:
gcs
,
bucket
:
m
[
1
],
bucket
:
m
[
1
],
...
@@ -106,7 +106,7 @@ func newGCSRepo(r *repo, httpClient *http.Client) (*gcsRepo, error) {
...
@@ -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
E
RepoType
)
error
{
switch
repoType
{
switch
repoType
{
case
GCSRepoType
:
case
GCSRepoType
:
return
nil
return
nil
...
@@ -117,7 +117,7 @@ func validateRepoType(repoType RepoType) error {
...
@@ -117,7 +117,7 @@ func validateRepoType(repoType RepoType) error {
// ListCharts lists charts in this chart repository whose string values conform to the
// ListCharts lists charts in this chart repository whose string values conform to the
// supplied regular expression, or all charts, if the regular expression is nil.
// supplied regular expression, or all charts, if the regular expression is nil.
func
(
g
*
gcs
Repo
)
ListCharts
(
regex
*
regexp
.
Regexp
)
([]
string
,
error
)
{
func
(
g
*
GCS
Repo
)
ListCharts
(
regex
*
regexp
.
Regexp
)
([]
string
,
error
)
{
charts
:=
[]
string
{}
charts
:=
[]
string
{}
// List all objects in a bucket using pagination
// List all objects in a bucket using pagination
...
@@ -155,7 +155,7 @@ func (g *gcsRepo) ListCharts(regex *regexp.Regexp) ([]string, error) {
...
@@ -155,7 +155,7 @@ func (g *gcsRepo) ListCharts(regex *regexp.Regexp) ([]string, error) {
}
}
// GetChart retrieves, unpacks and returns a chart by name.
// GetChart retrieves, unpacks and returns a chart by name.
func
(
g
*
gcs
Repo
)
GetChart
(
name
string
)
(
*
chart
.
Chart
,
error
)
{
func
(
g
*
GCS
Repo
)
GetChart
(
name
string
)
(
*
chart
.
Chart
,
error
)
{
// Charts should be named bucket/chart-X.Y.Z.tgz, so check that the name matches
// Charts should be named bucket/chart-X.Y.Z.tgz, so check that the name matches
if
!
ChartNameMatcher
.
MatchString
(
name
)
{
if
!
ChartNameMatcher
.
MatchString
(
name
)
{
return
nil
,
fmt
.
Errorf
(
"name must be of the form <name>-<version>.tgz, was %s"
,
name
)
return
nil
,
fmt
.
Errorf
(
"name must be of the form <name>-<version>.tgz, was %s"
,
name
)
...
@@ -184,11 +184,11 @@ func (g *gcsRepo) GetChart(name string) (*chart.Chart, error) {
...
@@ -184,11 +184,11 @@ func (g *gcsRepo) GetChart(name string) (*chart.Chart, error) {
}
}
// GetBucket returns the repository bucket.
// GetBucket returns the repository bucket.
func
(
g
*
gcs
Repo
)
GetBucket
()
string
{
func
(
g
*
GCS
Repo
)
GetBucket
()
string
{
return
g
.
bucket
return
g
.
bucket
}
}
// Do performs an HTTP operation on the receiver's httpClient.
// Do performs an HTTP operation on the receiver's httpClient.
func
(
g
*
gcs
Repo
)
Do
(
req
*
http
.
Request
)
(
resp
*
http
.
Response
,
err
error
)
{
func
(
g
*
GCS
Repo
)
Do
(
req
*
http
.
Request
)
(
resp
*
http
.
Response
,
err
error
)
{
return
g
.
httpClient
.
Do
(
req
)
return
g
.
httpClient
.
Do
(
req
)
}
}
pkg/repo/gcs_repo_test.go
View file @
9074ab56
...
@@ -125,7 +125,7 @@ func TestGetChartWithInvalidName(t *testing.T) {
...
@@ -125,7 +125,7 @@ func TestGetChartWithInvalidName(t *testing.T) {
}
}
}
}
func
getTestRepo
(
t
*
testing
.
T
)
Object
StorageRepo
{
func
getTestRepo
(
t
*
testing
.
T
)
I
StorageRepo
{
tr
,
err
:=
NewGCSRepo
(
TestRepoName
,
TestRepoURL
,
TestRepoCredentialName
,
nil
)
tr
,
err
:=
NewGCSRepo
(
TestRepoName
,
TestRepoURL
,
TestRepoCredentialName
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
...
...
pkg/repo/inmem_credential_provider.go
View file @
9074ab56
...
@@ -24,16 +24,16 @@ import (
...
@@ -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
]
*
Repo
Credential
credentials
map
[
string
]
*
Credential
}
}
// NewInmemCredentialProvider creates a new memory based credential provider.
// NewInmemCredentialProvider creates a new memory based credential provider.
func
NewInmemCredentialProvider
()
CredentialProvider
{
func
NewInmemCredentialProvider
()
I
CredentialProvider
{
return
&
InmemCredentialProvider
{
credentials
:
make
(
map
[
string
]
*
Repo
Credential
)}
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
)
(
*
Repo
Credential
,
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,
...
@@ -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
*
Repo
Credential
)
error
{
func
(
fcp
*
InmemCredentialProvider
)
SetCredential
(
name
string
,
credential
*
Credential
)
error
{
fcp
.
Lock
()
fcp
.
Lock
()
defer
fcp
.
Unlock
()
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
return
nil
}
}
pkg/repo/inmem_credential_provider_test.go
View file @
9074ab56
...
@@ -24,7 +24,7 @@ import (
...
@@ -24,7 +24,7 @@ import (
type
testCase
struct
{
type
testCase
struct
{
name
string
name
string
exp
*
Repo
Credential
exp
*
Credential
expErr
error
expErr
error
}
}
...
@@ -32,7 +32,7 @@ func createMissingError(name string) error {
...
@@ -32,7 +32,7 @@ func createMissingError(name string) error {
return
fmt
.
Errorf
(
"no such credential: %s"
,
name
)
return
fmt
.
Errorf
(
"no such credential: %s"
,
name
)
}
}
func
testGetCredential
(
t
*
testing
.
T
,
cp
CredentialProvider
,
tc
*
testCase
)
{
func
testGetCredential
(
t
*
testing
.
T
,
cp
I
CredentialProvider
,
tc
*
testCase
)
{
actual
,
actualErr
:=
cp
.
GetCredential
(
tc
.
name
)
actual
,
actualErr
:=
cp
.
GetCredential
(
tc
.
name
)
if
!
reflect
.
DeepEqual
(
actual
,
tc
.
exp
)
{
if
!
reflect
.
DeepEqual
(
actual
,
tc
.
exp
)
{
t
.
Fatalf
(
"test case %s failed: want: %#v, have: %#v"
,
tc
.
name
,
tc
.
exp
,
actual
)
t
.
Fatalf
(
"test case %s failed: want: %#v, have: %#v"
,
tc
.
name
,
tc
.
exp
,
actual
)
...
@@ -43,7 +43,7 @@ func testGetCredential(t *testing.T, cp CredentialProvider, tc *testCase) {
...
@@ -43,7 +43,7 @@ func testGetCredential(t *testing.T, cp CredentialProvider, tc *testCase) {
}
}
}
}
func
verifySetAndGetCredential
(
t
*
testing
.
T
,
cp
CredentialProvider
,
tc
*
testCase
)
{
func
verifySetAndGetCredential
(
t
*
testing
.
T
,
cp
I
CredentialProvider
,
tc
*
testCase
)
{
err
:=
cp
.
SetCredential
(
tc
.
name
,
tc
.
exp
)
err
:=
cp
.
SetCredential
(
tc
.
name
,
tc
.
exp
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"test case %s failed: cannot set credential: %v"
,
tc
.
name
,
err
)
t
.
Fatalf
(
"test case %s failed: cannot set credential: %v"
,
tc
.
name
,
err
)
...
@@ -60,13 +60,13 @@ func TestNotExist(t *testing.T) {
...
@@ -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"
,
&
Repo
Credential
{
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"
,
&
Repo
Credential
{
BasicAuth
:
ba
},
nil
}
tc
:=
&
testCase
{
"testcredential"
,
&
Credential
{
BasicAuth
:
ba
},
nil
}
verifySetAndGetCredential
(
t
,
cp
,
tc
)
verifySetAndGetCredential
(
t
,
cp
,
tc
)
}
}
pkg/repo/inmem_repo_service.go
View file @
9074ab56
...
@@ -24,13 +24,13 @@ import (
...
@@ -24,13 +24,13 @@ import (
type
inmemRepoService
struct
{
type
inmemRepoService
struct
{
sync
.
RWMutex
sync
.
RWMutex
repositories
map
[
string
]
Repo
repositories
map
[
string
]
I
Repo
}
}
// NewInmemRepoService returns a new memory based repository service.
// NewInmemRepoService returns a new memory based repository service.
func
NewInmemRepoService
()
Service
{
func
NewInmemRepoService
()
IRepo
Service
{
rs
:=
&
inmemRepoService
{
rs
:=
&
inmemRepoService
{
repositories
:
make
(
map
[
string
]
Repo
),
repositories
:
make
(
map
[
string
]
I
Repo
),
}
}
r
,
err
:=
NewPublicGCSRepo
(
nil
)
r
,
err
:=
NewPublicGCSRepo
(
nil
)
...
@@ -42,11 +42,11 @@ func NewInmemRepoService() Service {
...
@@ -42,11 +42,11 @@ func NewInmemRepoService() Service {
}
}
// List returns the list of all known chart repositories
// List returns the list of all known chart repositories
func
(
rs
*
inmemRepoService
)
List
()
([]
Repo
,
error
)
{
func
(
rs
*
inmemRepoService
)
List
()
([]
I
Repo
,
error
)
{
rs
.
RLock
()
rs
.
RLock
()
defer
rs
.
RUnlock
()
defer
rs
.
RUnlock
()
ret
:=
[]
Repo
{}
ret
:=
[]
I
Repo
{}
for
_
,
r
:=
range
rs
.
repositories
{
for
_
,
r
:=
range
rs
.
repositories
{
ret
=
append
(
ret
,
r
)
ret
=
append
(
ret
,
r
)
}
}
...
@@ -55,7 +55,7 @@ func (rs *inmemRepoService) List() ([]Repo, error) {
...
@@ -55,7 +55,7 @@ func (rs *inmemRepoService) List() ([]Repo, error) {
}
}
// Create adds a known repository to the list
// Create adds a known repository to the list
func
(
rs
*
inmemRepoService
)
Create
(
repository
Repo
)
error
{
func
(
rs
*
inmemRepoService
)
Create
(
repository
I
Repo
)
error
{
rs
.
Lock
()
rs
.
Lock
()
defer
rs
.
Unlock
()
defer
rs
.
Unlock
()
...
@@ -70,7 +70,7 @@ func (rs *inmemRepoService) Create(repository Repo) error {
...
@@ -70,7 +70,7 @@ func (rs *inmemRepoService) Create(repository Repo) error {
}
}
// Get returns the repository with the given name
// Get returns the repository with the given name
func
(
rs
*
inmemRepoService
)
Get
(
name
string
)
(
Repo
,
error
)
{
func
(
rs
*
inmemRepoService
)
Get
(
name
string
)
(
I
Repo
,
error
)
{
rs
.
RLock
()
rs
.
RLock
()
defer
rs
.
RUnlock
()
defer
rs
.
RUnlock
()
...
@@ -83,11 +83,11 @@ func (rs *inmemRepoService) Get(name string) (Repo, error) {
...
@@ -83,11 +83,11 @@ func (rs *inmemRepoService) Get(name string) (Repo, error) {
}
}
// GetByURL returns the repository that backs the given URL
// GetByURL returns the repository that backs the given URL
func
(
rs
*
inmemRepoService
)
GetByURL
(
URL
string
)
(
Repo
,
error
)
{
func
(
rs
*
inmemRepoService
)
GetByURL
(
URL
string
)
(
I
Repo
,
error
)
{
rs
.
RLock
()
rs
.
RLock
()
defer
rs
.
RUnlock
()
defer
rs
.
RUnlock
()
var
found
Repo
var
found
I
Repo
for
_
,
r
:=
range
rs
.
repositories
{
for
_
,
r
:=
range
rs
.
repositories
{
rURL
:=
r
.
GetURL
()
rURL
:=
r
.
GetURL
()
if
strings
.
HasPrefix
(
URL
,
rURL
)
{
if
strings
.
HasPrefix
(
URL
,
rURL
)
{
...
...
pkg/repo/repo.go
View file @
9074ab56
...
@@ -21,21 +21,12 @@ import (
...
@@ -21,21 +21,12 @@ import (
"net/url"
"net/url"
)
)
// repo describes a repository
// NewRepo takes params and returns a IRepo
type
repo
struct
{
func
NewRepo
(
name
,
URL
,
credentialName
,
repoFormat
,
repoType
string
)
(
IRepo
,
error
)
{
Name
string
`json:"name"`
// Friendly name for this repository
return
newRepo
(
name
,
URL
,
credentialName
,
ERepoFormat
(
repoFormat
),
ERepoType
(
repoType
))
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
}
}
// NewRepo takes params and returns a Repo
func
newRepo
(
name
,
URL
,
credentialName
string
,
repoFormat
ERepoFormat
,
repoType
ERepoType
)
(
*
Repo
,
error
)
{
func
NewRepo
(
name
,
URL
,
credentialName
,
repoFormat
,
repoType
string
)
(
Repo
,
error
)
{
return
newRepo
(
name
,
URL
,
credentialName
,
RepoFormat
(
repoFormat
),
RepoType
(
repoType
))
}
func
newRepo
(
name
,
URL
,
credentialName
string
,
repoFormat
RepoFormat
,
repoType
RepoType
)
(
*
repo
,
error
)
{
if
name
==
""
{
if
name
==
""
{
return
nil
,
fmt
.
Errorf
(
"name must not be empty"
)
return
nil
,
fmt
.
Errorf
(
"name must not be empty"
)
}
}
...
@@ -53,7 +44,7 @@ func newRepo(name, URL, credentialName string, repoFormat RepoFormat, repoType R
...
@@ -53,7 +44,7 @@ func newRepo(name, URL, credentialName string, repoFormat RepoFormat, repoType R
return
nil
,
err
return
nil
,
err
}
}
r
:=
&
r
epo
{
r
:=
&
R
epo
{
Name
:
name
,
Name
:
name
,
Type
:
repoType
,
Type
:
repoType
,
URL
:
URL
,
URL
:
URL
,
...
@@ -65,7 +56,7 @@ func newRepo(name, URL, credentialName string, repoFormat RepoFormat, repoType R
...
@@ -65,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
E
RepoFormat
)
error
{
switch
repoFormat
{
switch
repoFormat
{
case
FlatRepoFormat
:
case
FlatRepoFormat
:
return
nil
return
nil
...
@@ -75,39 +66,39 @@ func validateRepoFormat(repoFormat RepoFormat) error {
...
@@ -75,39 +66,39 @@ func validateRepoFormat(repoFormat RepoFormat) error {
}
}
// GetName returns the friendly name of this repository.
// GetName returns the friendly name of this repository.
func
(
r
*
r
epo
)
GetName
()
string
{
func
(
r
*
R
epo
)
GetName
()
string
{
return
r
.
Name
return
r
.
Name
}
}
// GetType returns the technology implementing this repository.
// GetType returns the technology implementing this repository.
func
(
r
*
repo
)
GetType
()
RepoType
{
func
(
r
*
Repo
)
GetType
()
E
RepoType
{
return
r
.
Type
return
r
.
Type
}
}
// GetURL returns the URL to the root of this repository.
// GetURL returns the URL to the root of this repository.
func
(
r
*
r
epo
)
GetURL
()
string
{
func
(
r
*
R
epo
)
GetURL
()
string
{
return
r
.
URL
return
r
.
URL
}
}
// GetFormat returns the format of this repository.
// GetFormat returns the format of this repository.
func
(
r
*
repo
)
GetFormat
()
RepoFormat
{
func
(
r
*
Repo
)
GetFormat
()
E
RepoFormat
{
return
r
.
Format
return
r
.
Format
}
}
// GetCredentialName returns the credential name used to access this repository.
// GetCredentialName returns the credential name used to access this repository.
func
(
r
*
r
epo
)
GetCredentialName
()
string
{
func
(
r
*
R
epo
)
GetCredentialName
()
string
{
return
r
.
CredentialName
return
r
.
CredentialName
}
}
func
validateRepo
(
tr
Repo
,
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
()
haveName
:=
tr
.
GetName
()
if
haveName
!=
wantName
{
if
haveName
!=
wantName
{
return
fmt
.
Errorf
(
"unexpected repo name; want: %s, have %s"
,
wantName
,
haveName
)
return
fmt
.
Errorf
(
"unexpected repo
sitory
name; want: %s, have %s"
,
wantName
,
haveName
)
}
}
haveURL
:=
tr
.
GetURL
()
haveURL
:=
tr
.
GetURL
()
if
haveURL
!=
wantURL
{
if
haveURL
!=
wantURL
{
return
fmt
.
Errorf
(
"unexpected repo url; want: %s, have %s"
,
wantURL
,
haveURL
)
return
fmt
.
Errorf
(
"unexpected repo
sitory
url; want: %s, have %s"
,
wantURL
,
haveURL
)
}
}
haveCredentialName
:=
tr
.
GetCredentialName
()
haveCredentialName
:=
tr
.
GetCredentialName
()
...
@@ -116,17 +107,17 @@ func validateRepo(tr Repo, wantName, wantURL, wantCredentialName string, wantFor
...
@@ -116,17 +107,17 @@ func validateRepo(tr Repo, wantName, wantURL, wantCredentialName string, wantFor
}
}
if
haveCredentialName
!=
wantCredentialName
{
if
haveCredentialName
!=
wantCredentialName
{
return
fmt
.
Errorf
(
"unexpected repo credential name; want: %s, have %s"
,
wantCredentialName
,
haveCredentialName
)
return
fmt
.
Errorf
(
"unexpected repo
sitory
credential name; want: %s, have %s"
,
wantCredentialName
,
haveCredentialName
)
}
}
haveFormat
:=
tr
.
GetFormat
()
haveFormat
:=
tr
.
GetFormat
()
if
haveFormat
!=
wantFormat
{
if
haveFormat
!=
wantFormat
{
return
fmt
.
Errorf
(
"unexpected repo format; want: %s, have %s"
,
wantFormat
,
haveFormat
)
return
fmt
.
Errorf
(
"unexpected repo
sitory
format; want: %s, have %s"
,
wantFormat
,
haveFormat
)
}
}
haveType
:=
tr
.
GetType
()
haveType
:=
tr
.
GetType
()
if
haveType
!=
wantType
{
if
haveType
!=
wantType
{
return
fmt
.
Errorf
(
"unexpected repo type; want: %s, have %s"
,
wantType
,
haveType
)
return
fmt
.
Errorf
(
"unexpected repo
sitory
type; want: %s, have %s"
,
wantType
,
haveType
)
}
}
return
nil
return
nil
...
...
pkg/repo/repoprovider.go
View file @
9074ab56
...
@@ -29,28 +29,28 @@ import (
...
@@ -29,28 +29,28 @@ import (
"sync"
"sync"
)
)
//
RepoProvider is a factory for
ChartRepo instances.
//
IRepoProvider is a factory for I
ChartRepo instances.
type
RepoProvider
interface
{
type
I
RepoProvider
interface
{
GetRepoByURL
(
URL
string
)
(
ChartRepo
,
error
)
GetRepoByURL
(
URL
string
)
(
I
ChartRepo
,
error
)
GetRepoByName
(
repoName
string
)
(
ChartRepo
,
error
)
GetRepoByName
(
repoName
string
)
(
I
ChartRepo
,
error
)
GetChartByReference
(
reference
string
)
(
*
chart
.
Chart
,
error
)
GetChartByReference
(
reference
string
)
(
*
chart
.
Chart
,
error
)
}
}
type
repoProvider
struct
{
type
repoProvider
struct
{
sync
.
RWMutex
sync
.
RWMutex
rs
Service
rs
IRepo
Service
cp
CredentialProvider
cp
I
CredentialProvider
gcsrp
GCSRepoProvider
gcsrp
GCSRepoProvider
repos
map
[
string
]
ChartRepo
repos
map
[
string
]
I
ChartRepo
}
}
// NewRepoProvider creates a new repository provider.
// NewRepoProvider creates a new repository provider.
func
NewRepoProvider
(
rs
Service
,
gcsrp
GCSRepoProvider
,
cp
CredentialProvider
)
RepoProvider
{
func
NewRepoProvider
(
rs
IRepoService
,
gcsrp
GCSRepoProvider
,
cp
ICredentialProvider
)
I
RepoProvider
{
return
newRepoProvider
(
rs
,
gcsrp
,
cp
)
return
newRepoProvider
(
rs
,
gcsrp
,
cp
)
}
}
// newRepoProvider creates a new repository provider.
// newRepoProvider creates a new repository provider.
func
newRepoProvider
(
rs
Service
,
gcsrp
GCSRepoProvider
,
cp
CredentialProvider
)
*
repoProvider
{
func
newRepoProvider
(
rs
IRepoService
,
gcsrp
GCSRepoProvider
,
cp
I
CredentialProvider
)
*
repoProvider
{
if
rs
==
nil
{
if
rs
==
nil
{
rs
=
NewInmemRepoService
()
rs
=
NewInmemRepoService
()
}
}
...
@@ -63,18 +63,18 @@ func newRepoProvider(rs Service, gcsrp GCSRepoProvider, cp CredentialProvider) *
...
@@ -63,18 +63,18 @@ func newRepoProvider(rs Service, gcsrp GCSRepoProvider, cp CredentialProvider) *
gcsrp
=
NewGCSRepoProvider
(
cp
)
gcsrp
=
NewGCSRepoProvider
(
cp
)
}
}
repos
:=
make
(
map
[
string
]
ChartRepo
)
repos
:=
make
(
map
[
string
]
I
ChartRepo
)
rp
:=
&
repoProvider
{
rs
:
rs
,
gcsrp
:
gcsrp
,
cp
:
cp
,
repos
:
repos
}
rp
:=
&
repoProvider
{
rs
:
rs
,
gcsrp
:
gcsrp
,
cp
:
cp
,
repos
:
repos
}
return
rp
return
rp
}
}
// GetRepoService returns the repository service used by this repository provider.
// GetRepoService returns the repository service used by this repository provider.
func
(
rp
*
repoProvider
)
GetRepoService
()
Service
{
func
(
rp
*
repoProvider
)
GetRepoService
()
IRepo
Service
{
return
rp
.
rs
return
rp
.
rs
}
}
// GetCredentialProvider returns the credential provider used by this repository provider.
// GetCredentialProvider returns the credential provider used by this repository provider.
func
(
rp
*
repoProvider
)
GetCredentialProvider
()
CredentialProvider
{
func
(
rp
*
repoProvider
)
GetCredentialProvider
()
I
CredentialProvider
{
return
rp
.
cp
return
rp
.
cp
}
}
...
@@ -84,7 +84,7 @@ func (rp *repoProvider) GetGCSRepoProvider() GCSRepoProvider {
...
@@ -84,7 +84,7 @@ func (rp *repoProvider) GetGCSRepoProvider() GCSRepoProvider {
}
}
// GetRepoByName returns the repository with the given name.
// GetRepoByName returns the repository with the given name.
func
(
rp
*
repoProvider
)
GetRepoByName
(
repoName
string
)
(
ChartRepo
,
error
)
{
func
(
rp
*
repoProvider
)
GetRepoByName
(
repoName
string
)
(
I
ChartRepo
,
error
)
{
rp
.
Lock
()
rp
.
Lock
()
defer
rp
.
Unlock
()
defer
rp
.
Unlock
()
...
@@ -100,7 +100,7 @@ func (rp *repoProvider) GetRepoByName(repoName string) (ChartRepo, error) {
...
@@ -100,7 +100,7 @@ func (rp *repoProvider) GetRepoByName(repoName string) (ChartRepo, error) {
return
rp
.
createRepoByType
(
cr
)
return
rp
.
createRepoByType
(
cr
)
}
}
func
(
rp
*
repoProvider
)
createRepoByType
(
r
Repo
)
(
ChartRepo
,
error
)
{
func
(
rp
*
repoProvider
)
createRepoByType
(
r
IRepo
)
(
I
ChartRepo
,
error
)
{
switch
r
.
GetType
()
{
switch
r
.
GetType
()
{
case
GCSRepoType
:
case
GCSRepoType
:
cr
,
err
:=
rp
.
gcsrp
.
GetGCSRepo
(
r
)
cr
,
err
:=
rp
.
gcsrp
.
GetGCSRepo
(
r
)
...
@@ -114,7 +114,7 @@ func (rp *repoProvider) createRepoByType(r Repo) (ChartRepo, error) {
...
@@ -114,7 +114,7 @@ func (rp *repoProvider) createRepoByType(r Repo) (ChartRepo, error) {
return
nil
,
fmt
.
Errorf
(
"unknown repository type: %s"
,
r
.
GetType
())
return
nil
,
fmt
.
Errorf
(
"unknown repository type: %s"
,
r
.
GetType
())
}
}
func
(
rp
*
repoProvider
)
createRepo
(
cr
ChartRepo
)
(
ChartRepo
,
error
)
{
func
(
rp
*
repoProvider
)
createRepo
(
cr
IChartRepo
)
(
I
ChartRepo
,
error
)
{
name
:=
cr
.
GetName
()
name
:=
cr
.
GetName
()
if
_
,
ok
:=
rp
.
repos
[
name
];
ok
{
if
_
,
ok
:=
rp
.
repos
[
name
];
ok
{
return
nil
,
fmt
.
Errorf
(
"respository named %s already exists"
,
name
)
return
nil
,
fmt
.
Errorf
(
"respository named %s already exists"
,
name
)
...
@@ -125,7 +125,7 @@ func (rp *repoProvider) createRepo(cr ChartRepo) (ChartRepo, error) {
...
@@ -125,7 +125,7 @@ func (rp *repoProvider) createRepo(cr ChartRepo) (ChartRepo, error) {
}
}
// GetRepoByURL returns the repository whose URL is a prefix of the given URL.
// GetRepoByURL returns the repository whose URL is a prefix of the given URL.
func
(
rp
*
repoProvider
)
GetRepoByURL
(
URL
string
)
(
ChartRepo
,
error
)
{
func
(
rp
*
repoProvider
)
GetRepoByURL
(
URL
string
)
(
I
ChartRepo
,
error
)
{
rp
.
Lock
()
rp
.
Lock
()
defer
rp
.
Unlock
()
defer
rp
.
Unlock
()
...
@@ -141,8 +141,8 @@ func (rp *repoProvider) GetRepoByURL(URL string) (ChartRepo, error) {
...
@@ -141,8 +141,8 @@ func (rp *repoProvider) GetRepoByURL(URL string) (ChartRepo, error) {
return
rp
.
createRepoByType
(
cr
)
return
rp
.
createRepoByType
(
cr
)
}
}
func
(
rp
*
repoProvider
)
findRepoByURL
(
URL
string
)
ChartRepo
{
func
(
rp
*
repoProvider
)
findRepoByURL
(
URL
string
)
I
ChartRepo
{
var
found
ChartRepo
var
found
I
ChartRepo
for
_
,
r
:=
range
rp
.
repos
{
for
_
,
r
:=
range
rp
.
repos
{
rURL
:=
r
.
GetURL
()
rURL
:=
r
.
GetURL
()
if
strings
.
HasPrefix
(
URL
,
rURL
)
{
if
strings
.
HasPrefix
(
URL
,
rURL
)
{
...
@@ -178,17 +178,17 @@ func (rp *repoProvider) GetChartByReference(reference string) (*chart.Chart, err
...
@@ -178,17 +178,17 @@ func (rp *repoProvider) GetChartByReference(reference string) (*chart.Chart, err
return
r
.
GetChart
(
name
)
return
r
.
GetChart
(
name
)
}
}
// GCSRepoProvider is a factory for GCS Repo instances.
// GCSRepoProvider is a factory for GCS
I
Repo instances.
type
GCSRepoProvider
interface
{
type
GCSRepoProvider
interface
{
GetGCSRepo
(
r
Repo
)
(
Object
StorageRepo
,
error
)
GetGCSRepo
(
r
IRepo
)
(
I
StorageRepo
,
error
)
}
}
type
gcsRepoProvider
struct
{
type
gcsRepoProvider
struct
{
cp
CredentialProvider
cp
I
CredentialProvider
}
}
// NewGCSRepoProvider creates a GCSRepoProvider.
// NewGCSRepoProvider creates a GCSRepoProvider.
func
NewGCSRepoProvider
(
cp
CredentialProvider
)
GCSRepoProvider
{
func
NewGCSRepoProvider
(
cp
I
CredentialProvider
)
GCSRepoProvider
{
if
cp
==
nil
{
if
cp
==
nil
{
cp
=
NewInmemCredentialProvider
()
cp
=
NewInmemCredentialProvider
()
}
}
...
@@ -198,7 +198,7 @@ func NewGCSRepoProvider(cp CredentialProvider) GCSRepoProvider {
...
@@ -198,7 +198,7 @@ func NewGCSRepoProvider(cp CredentialProvider) GCSRepoProvider {
// GetGCSRepo returns a new Google Cloud Storage repository. If a credential is specified, it will try to
// GetGCSRepo returns a new Google Cloud Storage repository. If a credential is specified, it will try to
// fetch it and use it, and if the credential isn't found, it will fall back to an unauthenticated client.
// fetch it and use it, and if the credential isn't found, it will fall back to an unauthenticated client.
func
(
gcsrp
gcsRepoProvider
)
GetGCSRepo
(
r
Repo
)
(
Object
StorageRepo
,
error
)
{
func
(
gcsrp
gcsRepoProvider
)
GetGCSRepo
(
r
IRepo
)
(
I
StorageRepo
,
error
)
{
client
,
err
:=
gcsrp
.
createGCSClient
(
r
.
GetCredentialName
())
client
,
err
:=
gcsrp
.
createGCSClient
(
r
.
GetCredentialName
())
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
...
pkg/repo/repoprovider_test.go
View file @
9074ab56
...
@@ -50,9 +50,9 @@ func TestRepoProvider(t *testing.T) {
...
@@ -50,9 +50,9 @@ func TestRepoProvider(t *testing.T) {
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
castRepo
,
ok
:=
haveRepo
.
(
Object
StorageRepo
)
castRepo
,
ok
:=
haveRepo
.
(
I
StorageRepo
)
if
!
ok
{
if
!
ok
{
t
.
Fatalf
(
"invalid repo type, want:
Object
StorageRepo, have: %T."
,
haveRepo
)
t
.
Fatalf
(
"invalid repo type, want:
I
StorageRepo, have: %T."
,
haveRepo
)
}
}
wantBucket
:=
GCSPublicRepoBucket
wantBucket
:=
GCSPublicRepoBucket
...
@@ -112,7 +112,7 @@ func TestGetChartByReferenceWithValidReferences(t *testing.T) {
...
@@ -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
)
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
)
...
...
pkg/repo/secrets_credential_provider.go
View file @
9074ab56
...
@@ -53,7 +53,7 @@ type SecretsCredentialProvider struct {
...
@@ -53,7 +53,7 @@ type SecretsCredentialProvider struct {
}
}
// NewSecretsCredentialProvider creates a new secrets credential provider.
// NewSecretsCredentialProvider creates a new secrets credential provider.
func
NewSecretsCredentialProvider
()
CredentialProvider
{
func
NewSecretsCredentialProvider
()
I
CredentialProvider
{
kubernetesConfig
:=
&
util
.
KubernetesConfig
{
kubernetesConfig
:=
&
util
.
KubernetesConfig
{
KubePath
:
*
kubePath
,
KubePath
:
*
kubePath
,
KubeService
:
*
kubeService
,
KubeService
:
*
kubeService
,
...
@@ -70,7 +70,7 @@ func NewSecretsCredentialProvider() CredentialProvider {
...
@@ -70,7 +70,7 @@ func NewSecretsCredentialProvider() CredentialProvider {
return
&
SecretsCredentialProvider
{
util
.
NewKubernetesKubectl
(
kubernetesConfig
)}
return
&
SecretsCredentialProvider
{
util
.
NewKubernetesKubectl
(
kubernetesConfig
)}
}
}
func
parseCredential
(
credential
string
)
(
*
Repo
Credential
,
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) {
...
@@ -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
Repo
Credential
// And then finally unmarshal it from yaml to Credential
r
:=
&
Repo
Credential
{}
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) {
...
@@ -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
)
(
*
Repo
Credential
,
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
...
@@ -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
*
Repo
Credential
)
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
{
...
...
pkg/repo/types.go
View file @
9074ab56
...
@@ -37,39 +37,48 @@ type APITokenCredential string
...
@@ -37,39 +37,48 @@ type APITokenCredential string
// JWTTokenCredential defines a JWT token.
// JWTTokenCredential defines a JWT token.
type
JWTTokenCredential
string
type
JWTTokenCredential
string
//
Repo
Credential holds a credential used to access a repository.
// Credential holds a credential used to access a repository.
type
Repo
Credential
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"`
}
}
// CredentialProvider provides credentials for chart repositories.
//
I
CredentialProvider provides credentials for chart repositories.
type
CredentialProvider
interface
{
type
I
CredentialProvider
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
*
Repo
Credential
)
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
)
(
*
Repo
Credential
,
error
)
GetCredential
(
name
string
)
(
*
Credential
,
error
)
}
}
// RepoType defines the technology that implements a repository.
//
E
RepoType defines the technology that implements a repository.
type
RepoType
string
type
E
RepoType
string
// RepoFormat is a semi-colon delimited string that describes the format of a repository.
//
E
RepoFormat is a semi-colon delimited string that describes the format of a repository.
type
RepoFormat
string
type
E
RepoFormat
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
=
E
RepoFormat
(
"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
=
E
RepoFormat
(
"flat"
)
)
)
// Repo abstracts a repository.
// Repo describes a repository
type
Repo
interface
{
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
ERepoFormat
`json:"format"`
// Format of this repository
Type
ERepoType
`json:"type"`
// Technology implementing this repository
}
// IRepo abstracts a repository.
type
IRepo
interface
{
// GetName returns the friendly name of this repository.
// GetName returns the friendly name of this repository.
GetName
()
string
GetName
()
string
// GetURL returns the URL to the root of this repository.
// GetURL returns the URL to the root of this repository.
...
@@ -77,15 +86,15 @@ type Repo interface {
...
@@ -77,15 +86,15 @@ type Repo 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
()
E
RepoFormat
// GetType returns the technology implementing this repository.
// GetType returns the technology implementing this repository.
GetType
()
RepoType
GetType
()
E
RepoType
}
}
// ChartRepo abstracts a place that holds charts.
//
I
ChartRepo abstracts a place that holds charts.
type
ChartRepo
interface
{
type
I
ChartRepo
interface
{
// A
ChartRepo is a
Repo
// A
IChartRepo is a I
Repo
Repo
I
Repo
// ListCharts lists charts in this repository whose string values
// ListCharts lists charts in this repository whose string values
// conform to the supplied regular expression, or all charts if regex is nil
// conform to the supplied regular expression, or all charts if regex is nil
...
@@ -95,27 +104,27 @@ type ChartRepo interface {
...
@@ -95,27 +104,27 @@ type ChartRepo interface {
GetChart
(
name
string
)
(
*
chart
.
Chart
,
error
)
GetChart
(
name
string
)
(
*
chart
.
Chart
,
error
)
}
}
//
Object
StorageRepo abstracts a repository that resides in Object Storage,
//
I
StorageRepo abstracts a repository that resides in Object Storage,
// such as Google Cloud Storage, AWS S3, etc.
// such as Google Cloud Storage, AWS S3, etc.
type
Object
StorageRepo
interface
{
type
I
StorageRepo
interface
{
// An
ObjectStorageRepo is a
ChartRepo
// An
IStorageRepo is a I
ChartRepo
ChartRepo
I
ChartRepo
// GetBucket returns the name of the bucket that contains this repository.
// GetBucket returns the name of the bucket that contains this repository.
GetBucket
()
string
GetBucket
()
string
}
}
// Service maintains a list of chart repositories that defines the scope of all
//
IRepo
Service maintains a list of chart repositories that defines the scope of all
// repository based operations, such as search and chart reference resolution.
// repository based operations, such as search and chart reference resolution.
type
Service
interface
{
type
IRepo
Service
interface
{
// List returns the list of all known chart repositories
// List returns the list of all known chart repositories
List
()
([]
Repo
,
error
)
List
()
([]
I
Repo
,
error
)
// Create adds a known repository to the list
// Create adds a known repository to the list
Create
(
repository
Repo
)
error
Create
(
repository
I
Repo
)
error
// Get returns the repository with the given name
// Get returns the repository with the given name
Get
(
name
string
)
(
Repo
,
error
)
Get
(
name
string
)
(
I
Repo
,
error
)
// GetByURL returns the repository that backs the given URL
// GetByURL returns the repository that backs the given URL
GetByURL
(
URL
string
)
(
Repo
,
error
)
GetByURL
(
URL
string
)
(
I
Repo
,
error
)
// Delete removes a known repository from the list
// Delete removes a known repository from the list
Delete
(
name
string
)
error
Delete
(
name
string
)
error
}
}
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