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
e065ebcc
Commit
e065ebcc
authored
Mar 24, 2016
by
jackgr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove repo name
parent
c14b92bd
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
170 additions
and
174 deletions
+170
-174
gcs_repo.go
pkg/repo/gcs_repo.go
+9
-12
gcs_repo_test.go
pkg/repo/gcs_repo_test.go
+3
-3
inmem_repo_service.go
pkg/repo/inmem_repo_service.go
+22
-22
inmem_repo_service_test.go
pkg/repo/inmem_repo_service_test.go
+25
-24
repo.go
pkg/repo/repo.go
+6
-21
repo_test.go
pkg/repo/repo_test.go
+6
-14
repoprovider.go
pkg/repo/repoprovider.go
+60
-49
repoprovider_test.go
pkg/repo/repoprovider_test.go
+13
-12
types.go
pkg/repo/types.go
+26
-17
No files found.
pkg/repo/gcs_repo.go
View file @
e065ebcc
...
...
@@ -43,14 +43,11 @@ const (
// In a GCS repository all charts appear at the top level.
GCSRepoFormat
=
FlatRepoFormat
// GCSPublicRepo
Name is the name of the public GCS repository
.
GCSPublicRepo
Name
=
"kubernetes-charts"
// GCSPublicRepo
Bucket is the name of the public GCS repository bucket
.
GCSPublicRepo
Bucket
=
"kubernetes-charts"
// GCSPublicRepoURL is the URL for the public GCS repository.
GCSPublicRepoURL
=
"gs://"
+
GCSPublicRepoName
// GCSPublicRepoBucket is the name of the public GCS repository bucket.
GCSPublicRepoBucket
=
GCSPublicRepoName
GCSPublicRepoURL
=
"gs://"
+
GCSPublicRepoBucket
)
// GCSRepo implements the IStorageRepo interface for Google Cloud Storage.
...
...
@@ -63,12 +60,12 @@ type GCSRepo struct {
// NewPublicGCSRepo creates a new an IStorageRepo for the public GCS repository.
func
NewPublicGCSRepo
(
httpClient
*
http
.
Client
)
(
IStorageRepo
,
error
)
{
return
NewGCSRepo
(
GCSPublicRepo
Name
,
GCSPublicRepo
URL
,
""
,
nil
)
return
NewGCSRepo
(
GCSPublicRepoURL
,
""
,
nil
)
}
// NewGCSRepo creates a new IStorageRepo for a given GCS repository.
func
NewGCSRepo
(
name
,
URL
,
credentialName
string
,
httpClient
*
http
.
Client
)
(
IStorageRepo
,
error
)
{
r
,
err
:=
newRepo
(
name
,
URL
,
credentialName
,
GCSRepoFormat
,
GCSRepoType
)
func
NewGCSRepo
(
URL
,
credentialName
string
,
httpClient
*
http
.
Client
)
(
IStorageRepo
,
error
)
{
r
,
err
:=
newRepo
(
URL
,
credentialName
,
GCSRepoFormat
,
GCSRepoType
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -120,7 +117,7 @@ func validateRepoType(repoType ERepoType) error {
func
(
g
*
GCSRepo
)
ListCharts
(
regex
*
regexp
.
Regexp
)
([]
string
,
error
)
{
charts
:=
[]
string
{}
// List all objects in a bucket using pagination
// List
Repos
all objects in a bucket using pagination
pageToken
:=
""
for
{
call
:=
g
.
service
.
Objects
.
List
(
g
.
bucket
)
...
...
@@ -135,7 +132,7 @@ func (g *GCSRepo) ListCharts(regex *regexp.Regexp) ([]string, error) {
}
for
_
,
object
:=
range
res
.
Items
{
// Charts should be named
bucket/
chart-X.Y.Z.tgz, so tease apart the name
// Charts should be named chart-X.Y.Z.tgz, so tease apart the name
m
:=
ChartNameMatcher
.
FindStringSubmatch
(
object
.
Name
)
if
len
(
m
)
!=
3
{
continue
...
...
@@ -156,7 +153,7 @@ func (g *GCSRepo) ListCharts(regex *regexp.Regexp) ([]string, error) {
// GetChart retrieves, unpacks and returns a chart by name.
func
(
g
*
GCSRepo
)
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 chart-X.Y.Z.tgz, so check that the name matches
if
!
ChartNameMatcher
.
MatchString
(
name
)
{
return
nil
,
fmt
.
Errorf
(
"name must be of the form <name>-<version>.tgz, was %s"
,
name
)
}
...
...
pkg/repo/gcs_repo_test.go
View file @
e065ebcc
...
...
@@ -37,7 +37,7 @@ var (
func
TestValidGSURL
(
t
*
testing
.
T
)
{
tr
:=
getTestRepo
(
t
)
err
:=
validateRepo
(
tr
,
TestRepo
Name
,
TestRepo
URL
,
TestRepoCredentialName
,
TestRepoFormat
,
TestRepoType
)
err
:=
validateRepo
(
tr
,
TestRepoURL
,
TestRepoCredentialName
,
TestRepoFormat
,
TestRepoType
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -51,7 +51,7 @@ func TestValidGSURL(t *testing.T) {
func
TestInvalidGSURL
(
t
*
testing
.
T
)
{
var
invalidGSURL
=
"https://valid.url/wrong/scheme"
_
,
err
:=
NewGCSRepo
(
TestRepoName
,
invalidGSURL
,
TestRepoCredentialName
,
nil
)
_
,
err
:=
NewGCSRepo
(
invalidGSURL
,
TestRepoCredentialName
,
nil
)
if
err
==
nil
{
t
.
Fatalf
(
"expected error did not occur for invalid GS URL"
)
}
...
...
@@ -126,7 +126,7 @@ func TestGetChartWithInvalidName(t *testing.T) {
}
func
getTestRepo
(
t
*
testing
.
T
)
IStorageRepo
{
tr
,
err
:=
NewGCSRepo
(
TestRepo
Name
,
TestRepo
URL
,
TestRepoCredentialName
,
nil
)
tr
,
err
:=
NewGCSRepo
(
TestRepoURL
,
TestRepoCredentialName
,
nil
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
pkg/repo/inmem_repo_service.go
View file @
e065ebcc
...
...
@@ -35,55 +35,55 @@ func NewInmemRepoService() IRepoService {
r
,
err
:=
NewPublicGCSRepo
(
nil
)
if
err
==
nil
{
rs
.
Create
(
r
)
rs
.
Create
Repo
(
r
)
}
return
rs
}
// List returns the list of all known chart repositories
func
(
rs
*
inmemRepoService
)
List
()
([]
string
,
error
)
{
// List
Repos
returns the list of all known chart repositories
func
(
rs
*
inmemRepoService
)
List
Repos
()
([]
string
,
error
)
{
rs
.
RLock
()
defer
rs
.
RUnlock
()
ret
:=
[]
string
{}
for
_
,
r
:=
range
rs
.
repositories
{
ret
=
append
(
ret
,
r
.
Get
Name
())
ret
=
append
(
ret
,
r
.
Get
URL
())
}
return
ret
,
nil
}
// Create adds a known repository to the list
func
(
rs
*
inmemRepoService
)
Create
(
repository
IRepo
)
error
{
// Create
Repo
adds a known repository to the list
func
(
rs
*
inmemRepoService
)
Create
Repo
(
repository
IRepo
)
error
{
rs
.
Lock
()
defer
rs
.
Unlock
()
name
:=
repository
.
GetName
()
_
,
ok
:=
rs
.
repositories
[
name
]
URL
:=
repository
.
GetURL
()
_
,
ok
:=
rs
.
repositories
[
URL
]
if
ok
{
return
fmt
.
Errorf
(
"Repository
named %s already exists"
,
name
)
return
fmt
.
Errorf
(
"Repository
with URL %s already exists"
,
URL
)
}
rs
.
repositories
[
name
]
=
repository
rs
.
repositories
[
URL
]
=
repository
return
nil
}
// Get
returns the repository with the given name
func
(
rs
*
inmemRepoService
)
Get
(
name
string
)
(
IRepo
,
error
)
{
// Get
RepoByURL returns the repository with the given URL
func
(
rs
*
inmemRepoService
)
Get
RepoByURL
(
URL
string
)
(
IRepo
,
error
)
{
rs
.
RLock
()
defer
rs
.
RUnlock
()
r
,
ok
:=
rs
.
repositories
[
name
]
r
,
ok
:=
rs
.
repositories
[
URL
]
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"
Failed to find repository named %s"
,
name
)
return
nil
,
fmt
.
Errorf
(
"
No repository with URL %s"
,
URL
)
}
return
r
,
nil
}
// Get
ByURL returns the repository that backs the given
URL
func
(
rs
*
inmemRepoService
)
Get
By
URL
(
URL
string
)
(
IRepo
,
error
)
{
// Get
RepoByChartURL returns the repository that backs the given chart
URL
func
(
rs
*
inmemRepoService
)
Get
RepoByChart
URL
(
URL
string
)
(
IRepo
,
error
)
{
rs
.
RLock
()
defer
rs
.
RUnlock
()
...
...
@@ -98,22 +98,22 @@ func (rs *inmemRepoService) GetByURL(URL string) (IRepo, error) {
}
if
found
==
nil
{
return
nil
,
fmt
.
Errorf
(
"
Failed to find repository for url:
%s"
,
URL
)
return
nil
,
fmt
.
Errorf
(
"
No repository for url
%s"
,
URL
)
}
return
found
,
nil
}
// Delete removes a known repository from the list
func
(
rs
*
inmemRepoService
)
Delete
(
name
string
)
error
{
// Delete
Repo
removes a known repository from the list
func
(
rs
*
inmemRepoService
)
Delete
Repo
(
URL
string
)
error
{
rs
.
Lock
()
defer
rs
.
Unlock
()
_
,
ok
:=
rs
.
repositories
[
name
]
_
,
ok
:=
rs
.
repositories
[
URL
]
if
!
ok
{
return
fmt
.
Errorf
(
"
Failed to find repository named %s"
,
name
)
return
fmt
.
Errorf
(
"
No repository with URL %s"
,
URL
)
}
delete
(
rs
.
repositories
,
name
)
delete
(
rs
.
repositories
,
URL
)
return
nil
}
pkg/repo/inmem_repo_service_test.go
View file @
e065ebcc
...
...
@@ -23,7 +23,7 @@ import (
func
TestService
(
t
*
testing
.
T
)
{
rs
:=
NewInmemRepoService
()
repos
,
err
:=
rs
.
List
()
repos
,
err
:=
rs
.
List
Repos
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -32,16 +32,16 @@ func TestService(t *testing.T) {
t
.
Fatalf
(
"unexpected repo count; want: %d, have %d."
,
1
,
len
(
repos
))
}
tr
,
err
:=
rs
.
Get
(
repos
[
0
])
tr
,
err
:=
rs
.
Get
RepoByURL
(
repos
[
0
])
if
err
!=
nil
{
t
.
Fatal
f
(
"cannot get repo named %s: %s"
,
repos
[
0
],
err
)
t
.
Fatal
(
err
)
}
if
err
:=
validateRepo
(
tr
,
GCSPublicRepo
Name
,
GCSPublicRepo
URL
,
""
,
GCSRepoFormat
,
GCSRepoType
);
err
!=
nil
{
if
err
:=
validateRepo
(
tr
,
GCSPublicRepoURL
,
""
,
GCSRepoFormat
,
GCSRepoType
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
r1
,
err
:=
rs
.
Get
(
GCSPublicRepoName
)
r1
,
err
:=
rs
.
Get
RepoByURL
(
GCSPublicRepoURL
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -50,7 +50,8 @@ func TestService(t *testing.T) {
t
.
Fatalf
(
"invalid repo returned; want: %#v, have %#v."
,
tr
,
r1
)
}
r2
,
err
:=
rs
.
GetByURL
(
GCSPublicRepoURL
)
URL
:=
GCSPublicRepoURL
+
TestArchiveName
r2
,
err
:=
rs
.
GetRepoByChartURL
(
URL
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -59,50 +60,50 @@ func TestService(t *testing.T) {
t
.
Fatalf
(
"invalid repo returned; want: %#v, have %#v."
,
tr
,
r2
)
}
if
err
:=
rs
.
Delete
(
GCSPublicRepoName
);
err
!=
nil
{
if
err
:=
rs
.
Delete
Repo
(
GCSPublicRepoURL
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
_
,
err
:=
rs
.
Get
(
GCSPublicRepoName
);
err
==
nil
{
t
.
Fatalf
(
"deleted repo
named %s returned"
,
GCSPublicRepoName
)
if
_
,
err
:=
rs
.
Get
RepoByURL
(
GCSPublicRepoURL
);
err
==
nil
{
t
.
Fatalf
(
"deleted repo
with URL %s returned"
,
GCSPublicRepoURL
)
}
}
func
TestCreateRepoWithDuplicate
Name
(
t
*
testing
.
T
)
{
func
TestCreateRepoWithDuplicate
URL
(
t
*
testing
.
T
)
{
rs
:=
NewInmemRepoService
()
r
,
err
:=
newRepo
(
GCSPublicRepo
Name
,
GCSPublicRepo
URL
,
""
,
GCSRepoFormat
,
GCSRepoType
)
r
,
err
:=
newRepo
(
GCSPublicRepoURL
,
""
,
GCSRepoFormat
,
GCSRepoType
)
if
err
!=
nil
{
t
.
Fatalf
(
"cannot create test repo: %s"
,
err
)
}
if
err
:=
rs
.
Create
(
r
);
err
==
nil
{
t
.
Fatalf
(
"created repo with duplicate
name: %s"
,
GCSPublicRepoName
)
if
err
:=
rs
.
Create
Repo
(
r
);
err
==
nil
{
t
.
Fatalf
(
"created repo with duplicate
URL: %s"
,
GCSPublicRepoURL
)
}
}
func
TestGetRepoWithInvalid
Name
(
t
*
testing
.
T
)
{
invalid
Name
:=
"InvalidRepoName
"
func
TestGetRepoWithInvalid
URL
(
t
*
testing
.
T
)
{
invalid
URL
:=
"https://not.a.valid/url
"
rs
:=
NewInmemRepoService
()
_
,
err
:=
rs
.
Get
(
invalidName
)
_
,
err
:=
rs
.
Get
RepoByURL
(
invalidURL
)
if
err
==
nil
{
t
.
Fatalf
(
"found repo with invalid
name: %s"
,
invalidName
)
t
.
Fatalf
(
"found repo with invalid
URL: %s"
,
invalidURL
)
}
}
func
TestGetRepoWithInvalidURL
(
t
*
testing
.
T
)
{
func
TestGetRepoWithInvalid
Chart
URL
(
t
*
testing
.
T
)
{
invalidURL
:=
"https://not.a.valid/url"
rs
:=
NewInmemRepoService
()
_
,
err
:=
rs
.
Get
By
URL
(
invalidURL
)
_
,
err
:=
rs
.
Get
RepoByChart
URL
(
invalidURL
)
if
err
==
nil
{
t
.
Fatalf
(
"found repo with invalid URL: %s"
,
invalidURL
)
t
.
Fatalf
(
"found repo with invalid
chart
URL: %s"
,
invalidURL
)
}
}
func
TestDeleteRepoWithInvalid
Name
(
t
*
testing
.
T
)
{
invalid
Name
:=
"InvalidRepoName
"
func
TestDeleteRepoWithInvalid
URL
(
t
*
testing
.
T
)
{
invalid
URL
:=
"https://not.a.valid/url
"
rs
:=
NewInmemRepoService
()
err
:=
rs
.
Delete
(
invalidName
)
err
:=
rs
.
Delete
Repo
(
invalidURL
)
if
err
==
nil
{
t
.
Fatalf
(
"deleted repo with invalid name: %s"
,
invalid
Name
)
t
.
Fatalf
(
"deleted repo with invalid name: %s"
,
invalid
URL
)
}
}
pkg/repo/repo.go
View file @
e065ebcc
...
...
@@ -22,15 +22,11 @@ import (
)
// NewRepo takes params and returns a IRepo
func
NewRepo
(
name
,
URL
,
credentialName
,
repoFormat
,
repoType
string
)
(
IRepo
,
error
)
{
return
newRepo
(
name
,
URL
,
credentialName
,
ERepoFormat
(
repoFormat
),
ERepoType
(
repoType
))
func
NewRepo
(
URL
,
credentialName
,
repoFormat
,
repoType
string
)
(
IRepo
,
error
)
{
return
newRepo
(
URL
,
credentialName
,
ERepoFormat
(
repoFormat
),
ERepoType
(
repoType
))
}
func
newRepo
(
name
,
URL
,
credentialName
string
,
repoFormat
ERepoFormat
,
repoType
ERepoType
)
(
*
Repo
,
error
)
{
if
name
==
""
{
return
nil
,
fmt
.
Errorf
(
"name must not be empty"
)
}
func
newRepo
(
URL
,
credentialName
string
,
repoFormat
ERepoFormat
,
repoType
ERepoType
)
(
*
Repo
,
error
)
{
_
,
err
:=
url
.
Parse
(
URL
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"invalid URL (%s): %s"
,
URL
,
err
)
...
...
@@ -45,11 +41,10 @@ func newRepo(name, URL, credentialName string, repoFormat ERepoFormat, repoType
}
r
:=
&
Repo
{
Name
:
name
,
Type
:
repoType
,
URL
:
URL
,
Format
:
repoFormat
,
CredentialName
:
credentialName
,
Type
:
repoType
,
Format
:
repoFormat
,
}
return
r
,
nil
...
...
@@ -65,11 +60,6 @@ func validateRepoFormat(repoFormat ERepoFormat) error {
return
fmt
.
Errorf
(
"unknown repository format: %s"
,
repoFormat
)
}
// GetName returns the friendly name of this repository.
func
(
r
*
Repo
)
GetName
()
string
{
return
r
.
Name
}
// GetType returns the technology implementing this repository.
func
(
r
*
Repo
)
GetType
()
ERepoType
{
return
r
.
Type
...
...
@@ -90,12 +80,7 @@ func (r *Repo) GetCredentialName() string {
return
r
.
CredentialName
}
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
)
}
func
validateRepo
(
tr
IRepo
,
wantURL
,
wantCredentialName
string
,
wantFormat
ERepoFormat
,
wantType
ERepoType
)
error
{
haveURL
:=
tr
.
GetURL
()
if
haveURL
!=
wantURL
{
return
fmt
.
Errorf
(
"unexpected repository url; want: %s, have %s"
,
wantURL
,
haveURL
)
...
...
pkg/repo/repo_test.go
View file @
e065ebcc
...
...
@@ -21,8 +21,7 @@ import (
)
var
(
TestRepoName
=
"kubernetes-charts-testing"
TestRepoBucket
=
TestRepoName
TestRepoBucket
=
"kubernetes-charts-testing"
TestRepoURL
=
"gs://"
+
TestRepoBucket
TestRepoType
=
GCSRepoType
TestRepoFormat
=
GCSRepoFormat
...
...
@@ -30,32 +29,25 @@ var (
)
func
TestValidRepoURL
(
t
*
testing
.
T
)
{
tr
,
err
:=
NewRepo
(
TestRepo
Name
,
TestRepo
URL
,
TestRepoCredentialName
,
string
(
TestRepoFormat
),
string
(
TestRepoType
))
tr
,
err
:=
NewRepo
(
TestRepoURL
,
TestRepoCredentialName
,
string
(
TestRepoFormat
),
string
(
TestRepoType
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
err
:=
validateRepo
(
tr
,
TestRepo
Name
,
TestRepo
URL
,
TestRepoCredentialName
,
TestRepoFormat
,
TestRepoType
);
err
!=
nil
{
if
err
:=
validateRepo
(
tr
,
TestRepoURL
,
TestRepoCredentialName
,
TestRepoFormat
,
TestRepoType
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
func
TestInvalidRepoName
(
t
*
testing
.
T
)
{
_
,
err
:=
newRepo
(
""
,
TestRepoURL
,
TestRepoCredentialName
,
TestRepoFormat
,
TestRepoType
)
if
err
==
nil
{
t
.
Fatalf
(
"expected error did not occur for invalid name"
)
}
}
func
TestInvalidRepoURL
(
t
*
testing
.
T
)
{
_
,
err
:=
newRepo
(
TestRepoName
,
"%:invalid&url:%"
,
TestRepoCredentialName
,
TestRepoFormat
,
TestRepoType
)
_
,
err
:=
newRepo
(
"%:invalid&url:%"
,
TestRepoCredentialName
,
TestRepoFormat
,
TestRepoType
)
if
err
==
nil
{
t
.
Fatalf
(
"expected error did not occur for invalid URL"
)
}
}
func
TestDefaultCredentialName
(
t
*
testing
.
T
)
{
tr
,
err
:=
newRepo
(
TestRepo
Name
,
TestRepo
URL
,
""
,
TestRepoFormat
,
TestRepoType
)
tr
,
err
:=
newRepo
(
TestRepoURL
,
""
,
TestRepoFormat
,
TestRepoType
)
if
err
!=
nil
{
t
.
Fatalf
(
"cannot create repo using default credential name"
)
}
...
...
@@ -68,7 +60,7 @@ func TestDefaultCredentialName(t *testing.T) {
}
func
TestInvalidRepoFormat
(
t
*
testing
.
T
)
{
_
,
err
:=
newRepo
(
TestRepo
Name
,
TestRepo
URL
,
TestRepoCredentialName
,
""
,
TestRepoType
)
_
,
err
:=
newRepo
(
TestRepoURL
,
TestRepoCredentialName
,
""
,
TestRepoType
)
if
err
==
nil
{
t
.
Fatalf
(
"expected error did not occur for invalid format"
)
}
...
...
pkg/repo/repoprovider.go
View file @
e065ebcc
...
...
@@ -29,28 +29,21 @@ import (
"sync"
)
// 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
,
IChartRepo
,
error
)
}
type
repoProvider
struct
{
sync
.
RWMutex
rs
IRepoService
cp
ICredentialProvider
gcsrp
GCSRepoProvider
gcsrp
I
GCSRepoProvider
repos
map
[
string
]
IChartRepo
}
// NewRepoProvider creates a new repository provider.
func
NewRepoProvider
(
rs
IRepoService
,
gcsrp
GCSRepoProvider
,
cp
ICredentialProvider
)
IRepoProvider
{
func
NewRepoProvider
(
rs
IRepoService
,
gcsrp
I
GCSRepoProvider
,
cp
ICredentialProvider
)
IRepoProvider
{
return
newRepoProvider
(
rs
,
gcsrp
,
cp
)
}
// newRepoProvider creates a new repository provider.
func
newRepoProvider
(
rs
IRepoService
,
gcsrp
GCSRepoProvider
,
cp
ICredentialProvider
)
*
repoProvider
{
func
newRepoProvider
(
rs
IRepoService
,
gcsrp
I
GCSRepoProvider
,
cp
ICredentialProvider
)
*
repoProvider
{
if
rs
==
nil
{
rs
=
NewInmemRepoService
()
}
...
...
@@ -79,20 +72,20 @@ func (rp *repoProvider) GetCredentialProvider() ICredentialProvider {
}
// GetGCSRepoProvider returns the GCS repository provider used by this repository provider.
func
(
rp
*
repoProvider
)
GetGCSRepoProvider
()
GCSRepoProvider
{
func
(
rp
*
repoProvider
)
GetGCSRepoProvider
()
I
GCSRepoProvider
{
return
rp
.
gcsrp
}
// GetRepoBy
Name
returns the repository with the given name.
func
(
rp
*
repoProvider
)
GetRepoBy
Name
(
repoName
string
)
(
IChartRepo
,
error
)
{
// GetRepoBy
URL
returns the repository with the given name.
func
(
rp
*
repoProvider
)
GetRepoBy
URL
(
URL
string
)
(
IChartRepo
,
error
)
{
rp
.
Lock
()
defer
rp
.
Unlock
()
if
r
,
ok
:=
rp
.
repos
[
repoName
];
ok
{
if
r
,
ok
:=
rp
.
repos
[
URL
];
ok
{
return
r
,
nil
}
cr
,
err
:=
rp
.
rs
.
Get
(
repoName
)
cr
,
err
:=
rp
.
rs
.
Get
RepoByURL
(
URL
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -115,25 +108,25 @@ func (rp *repoProvider) createRepoByType(r IRepo) (IChartRepo, error) {
}
func
(
rp
*
repoProvider
)
createRepo
(
cr
IChartRepo
)
(
IChartRepo
,
error
)
{
name
:=
cr
.
GetName
()
if
_
,
ok
:=
rp
.
repos
[
name
];
ok
{
return
nil
,
fmt
.
Errorf
(
"respository
named %s already exists"
,
name
)
URL
:=
cr
.
GetURL
()
if
_
,
ok
:=
rp
.
repos
[
URL
];
ok
{
return
nil
,
fmt
.
Errorf
(
"respository
with URL %s already exists"
,
URL
)
}
rp
.
repos
[
name
]
=
cr
rp
.
repos
[
URL
]
=
cr
return
cr
,
nil
}
// GetRepoByURL returns the repository whose URL is a prefix of the given URL.
func
(
rp
*
repoProvider
)
GetRepoByURL
(
URL
string
)
(
IChartRepo
,
error
)
{
// GetRepoBy
Chart
URL returns the repository whose URL is a prefix of the given URL.
func
(
rp
*
repoProvider
)
GetRepoBy
Chart
URL
(
URL
string
)
(
IChartRepo
,
error
)
{
rp
.
Lock
()
defer
rp
.
Unlock
()
if
r
:=
rp
.
findRepoByURL
(
URL
);
r
!=
nil
{
if
r
:=
rp
.
findRepoBy
Chart
URL
(
URL
);
r
!=
nil
{
return
r
,
nil
}
cr
,
err
:=
rp
.
rs
.
Get
By
URL
(
URL
)
cr
,
err
:=
rp
.
rs
.
Get
RepoByChart
URL
(
URL
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -141,7 +134,7 @@ func (rp *repoProvider) GetRepoByURL(URL string) (IChartRepo, error) {
return
rp
.
createRepoByType
(
cr
)
}
func
(
rp
*
repoProvider
)
findRepoByURL
(
URL
string
)
IChartRepo
{
func
(
rp
*
repoProvider
)
findRepoBy
Chart
URL
(
URL
string
)
IChartRepo
{
var
found
IChartRepo
for
_
,
r
:=
range
rp
.
repos
{
rURL
:=
r
.
GetURL
()
...
...
@@ -157,19 +150,14 @@ func (rp *repoProvider) findRepoByURL(URL string) IChartRepo {
// GetChartByReference maps the supplied chart reference into a fully qualified
// URL, uses the URL to find the repository it references, queries the repository
// for the chart
by URL, and
returns the chart and the repository that backs it.
// for the chart
, and then
returns the chart and the repository that backs it.
func
(
rp
*
repoProvider
)
GetChartByReference
(
reference
string
)
(
*
chart
.
Chart
,
IChartRepo
,
error
)
{
l
,
err
:=
ParseGCS
ChartReference
(
reference
)
l
,
URL
,
err
:=
parse
ChartReference
(
reference
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
URL
,
err
:=
l
.
Long
(
true
)
if
err
!=
nil
{
return
nil
,
nil
,
fmt
.
Errorf
(
"invalid reference %s: %s"
,
reference
,
err
)
}
r
,
err
:=
rp
.
GetRepoByURL
(
URL
)
r
,
err
:=
rp
.
GetRepoByChartURL
(
URL
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
...
...
@@ -183,17 +171,45 @@ func (rp *repoProvider) GetChartByReference(reference string) (*chart.Chart, ICh
return
c
,
r
,
nil
}
// GCSRepoProvider is a factory for GCS IRepo instances.
type
GCSRepoProvider
interface
{
GetGCSRepo
(
r
IRepo
)
(
IStorageRepo
,
error
)
// IsChartReference returns true if the supplied string is a reference to a chart in a repository
func
IsChartReference
(
reference
string
)
bool
{
if
_
,
err
:=
ParseChartReference
(
reference
);
err
!=
nil
{
return
false
}
return
true
}
// ParseChartReference parses a reference to a chart in a repository and returns the URL for the chart
func
ParseChartReference
(
reference
string
)
(
*
chart
.
Locator
,
error
)
{
l
,
_
,
err
:=
parseChartReference
(
reference
)
if
err
!=
nil
{
return
nil
,
err
}
return
l
,
nil
}
func
parseChartReference
(
reference
string
)
(
*
chart
.
Locator
,
string
,
error
)
{
l
,
err
:=
chart
.
Parse
(
reference
)
if
err
!=
nil
{
return
nil
,
""
,
fmt
.
Errorf
(
"cannot parse chart reference %s: %s"
,
reference
,
err
)
}
URL
,
err
:=
l
.
Long
(
true
)
if
err
!=
nil
{
return
nil
,
""
,
fmt
.
Errorf
(
"chart reference %s does not resolve to a URL: %s"
,
reference
,
err
)
}
return
l
,
URL
,
nil
}
type
gcsRepoProvider
struct
{
cp
ICredentialProvider
}
// NewGCSRepoProvider creates a GCSRepoProvider.
func
NewGCSRepoProvider
(
cp
ICredentialProvider
)
GCSRepoProvider
{
// NewGCSRepoProvider creates a
I
GCSRepoProvider.
func
NewGCSRepoProvider
(
cp
ICredentialProvider
)
I
GCSRepoProvider
{
if
cp
==
nil
{
cp
=
NewInmemCredentialProvider
()
}
...
...
@@ -209,7 +225,7 @@ func (gcsrp gcsRepoProvider) GetGCSRepo(r IRepo) (IStorageRepo, error) {
return
nil
,
err
}
return
NewGCSRepo
(
r
.
Get
Name
(),
r
.
Get
URL
(),
r
.
GetCredentialName
(),
client
)
return
NewGCSRepo
(
r
.
GetURL
(),
r
.
GetCredentialName
(),
client
)
}
func
(
gcsrp
gcsRepoProvider
)
createGCSClient
(
credentialName
string
)
(
*
http
.
Client
,
error
)
{
...
...
@@ -233,8 +249,8 @@ func (gcsrp gcsRepoProvider) createGCSClient(credentialName string) (*http.Clien
}
// IsGCSChartReference returns true if the supplied string is a reference to a chart in a GCS repository
func
IsGCSChartReference
(
r
string
)
bool
{
if
_
,
err
:=
ParseGCSChartReference
(
r
);
err
!=
nil
{
func
IsGCSChartReference
(
r
eference
string
)
bool
{
if
_
,
err
:=
ParseGCSChartReference
(
r
eference
);
err
!=
nil
{
return
false
}
...
...
@@ -242,20 +258,15 @@ func IsGCSChartReference(r string) bool {
}
// ParseGCSChartReference parses a reference to a chart in a GCS repository and returns the URL for the chart
func
ParseGCSChartReference
(
r
string
)
(
*
chart
.
Locator
,
error
)
{
l
,
err
:=
chart
.
Parse
(
r
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"cannot parse chart reference %s: %s"
,
r
,
err
)
}
URL
,
err
:=
l
.
Long
(
true
)
func
ParseGCSChartReference
(
reference
string
)
(
*
chart
.
Locator
,
error
)
{
l
,
URL
,
err
:=
parseChartReference
(
reference
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"chart reference %s does not resolve to a URL: %s"
,
r
,
err
)
return
nil
,
err
}
m
:=
GCSChartURLMatcher
.
FindStringSubmatch
(
URL
)
if
len
(
m
)
!=
4
{
return
nil
,
fmt
.
Errorf
(
"chart reference %s resolve to invalid URL: %s"
,
r
,
URL
)
return
nil
,
fmt
.
Errorf
(
"chart reference %s resolve to invalid URL: %s"
,
r
eference
,
URL
)
}
return
l
,
nil
...
...
pkg/repo/repoprovider_test.go
View file @
e065ebcc
...
...
@@ -41,12 +41,12 @@ var InvalidChartReferences = []string{
func
TestRepoProvider
(
t
*
testing
.
T
)
{
rp
:=
NewRepoProvider
(
nil
,
nil
,
nil
)
haveRepo
,
err
:=
rp
.
GetRepoBy
Name
(
GCSPublicRepoName
)
haveRepo
,
err
:=
rp
.
GetRepoBy
URL
(
GCSPublicRepoURL
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
err
:=
validateRepo
(
haveRepo
,
GCSPublicRepo
Name
,
GCSPublicRepo
URL
,
""
,
GCSRepoFormat
,
GCSRepoType
);
err
!=
nil
{
if
err
:=
validateRepo
(
haveRepo
,
GCSPublicRepoURL
,
""
,
GCSRepoFormat
,
GCSRepoType
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -62,7 +62,8 @@ func TestRepoProvider(t *testing.T) {
}
wantRepo
:=
haveRepo
haveRepo
,
err
=
rp
.
GetRepoByURL
(
GCSPublicRepoURL
)
URL
:=
GCSPublicRepoURL
+
TestArchiveName
haveRepo
,
err
=
rp
.
GetRepoByChartURL
(
URL
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -72,21 +73,21 @@ func TestRepoProvider(t *testing.T) {
}
}
func
TestGetRepoBy
NameWithInvalidName
(
t
*
testing
.
T
)
{
var
invalid
Name
=
"InvalidRepoNa
me"
func
TestGetRepoBy
URLWithInvalidURL
(
t
*
testing
.
T
)
{
var
invalid
URL
=
"https://valid.url/wrong/sche
me"
rp
:=
NewRepoProvider
(
nil
,
nil
,
nil
)
_
,
err
:=
rp
.
GetRepoBy
Name
(
invalidName
)
_
,
err
:=
rp
.
GetRepoBy
URL
(
invalidURL
)
if
err
==
nil
{
t
.
Fatalf
(
"found repo using invalid
name: %s"
,
invalidName
)
t
.
Fatalf
(
"found repo using invalid
URL: %s"
,
invalidURL
)
}
}
func
TestGetRepoBy
URLWithInvalid
URL
(
t
*
testing
.
T
)
{
func
TestGetRepoBy
ChartURLWithInvalidChart
URL
(
t
*
testing
.
T
)
{
var
invalidURL
=
"https://valid.url/wrong/scheme"
rp
:=
NewRepoProvider
(
nil
,
nil
,
nil
)
_
,
err
:=
rp
.
GetRepoByURL
(
invalidURL
)
_
,
err
:=
rp
.
GetRepoBy
Chart
URL
(
invalidURL
)
if
err
==
nil
{
t
.
Fatalf
(
"found repo using invalid URL: %s"
,
invalidURL
)
t
.
Fatalf
(
"found repo using invalid
chart
URL: %s"
,
invalidURL
)
}
}
...
...
@@ -115,12 +116,12 @@ func TestGetChartByReferenceWithValidReferences(t *testing.T) {
func
getTestRepoProvider
(
t
*
testing
.
T
)
IRepoProvider
{
rp
:=
newRepoProvider
(
nil
,
nil
,
nil
)
rs
:=
rp
.
GetRepoService
()
tr
,
err
:=
newRepo
(
TestRepo
Name
,
TestRepo
URL
,
TestRepoCredentialName
,
TestRepoFormat
,
TestRepoType
)
tr
,
err
:=
newRepo
(
TestRepoURL
,
TestRepoCredentialName
,
TestRepoFormat
,
TestRepoType
)
if
err
!=
nil
{
t
.
Fatalf
(
"cannot create test repository: %s"
,
err
)
}
if
err
:=
rs
.
Create
(
tr
);
err
!=
nil
{
if
err
:=
rs
.
Create
Repo
(
tr
);
err
!=
nil
{
t
.
Fatalf
(
"cannot initialize repository service: %s"
,
err
)
}
...
...
pkg/repo/types.go
View file @
e065ebcc
...
...
@@ -70,17 +70,14 @@ const (
// 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
ERepoFormat
`json:"format"`
// Format of this repository
Type
ERepoType
`json:"type"`
// Technology implementing this repository
CredentialName
string
`json:"credentialname
,omitempty
"`
// Credential name used to access this repository
Format
ERepoFormat
`json:"format
,omitempty
"`
// Format of this repository
Type
ERepoType
`json:"type
,omitempty
"`
// Technology implementing this repository
}
// IRepo abstracts a repository.
type
IRepo
interface
{
// GetName returns the friendly name of this repository.
GetName
()
string
// GetURL returns the URL to the root of this repository.
GetURL
()
string
// GetCredentialName returns the credential name used to access this repository.
...
...
@@ -96,7 +93,7 @@ type IChartRepo interface {
// A IChartRepo is a IRepo
IRepo
// ListCharts lists
charts in this repository whose string values
// ListCharts lists
the URLs for charts in this repository that
// conform to the supplied regular expression, or all charts if regex is nil
ListCharts
(
regex
*
regexp
.
Regexp
)
([]
string
,
error
)
...
...
@@ -117,14 +114,26 @@ type IStorageRepo interface {
// IRepoService maintains a list of chart repositories that defines the scope of all
// repository based operations, such as search and chart reference resolution.
type
IRepoService
interface
{
// List returns the list of all known chart repositories
List
()
([]
string
,
error
)
// Create adds a known repository to the list
Create
(
repository
IRepo
)
error
// Get returns the repository with the given name
Get
(
name
string
)
(
IRepo
,
error
)
// GetByURL returns the repository that backs the given URL
GetByURL
(
URL
string
)
(
IRepo
,
error
)
// Delete removes a known repository from the list
Delete
(
name
string
)
error
// ListRepos returns the list of all known chart repositories
ListRepos
()
([]
string
,
error
)
// CreateRepo adds a known repository to the list
CreateRepo
(
repository
IRepo
)
error
// GetRepoByURL returns the repository with the given name
GetRepoByURL
(
name
string
)
(
IRepo
,
error
)
// GetRepoByChartURL returns the repository that backs the given URL
GetRepoByChartURL
(
URL
string
)
(
IRepo
,
error
)
// DeleteRepo removes a known repository from the list
DeleteRepo
(
name
string
)
error
}
// IRepoProvider is a factory for IChartRepo instances.
type
IRepoProvider
interface
{
GetChartByReference
(
reference
string
)
(
*
chart
.
Chart
,
IChartRepo
,
error
)
GetRepoByChartURL
(
URL
string
)
(
IChartRepo
,
error
)
GetRepoByURL
(
URL
string
)
(
IChartRepo
,
error
)
}
// IGCSRepoProvider is a factory for GCS IRepo instances.
type
IGCSRepoProvider
interface
{
GetGCSRepo
(
r
IRepo
)
(
IStorageRepo
,
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