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
f7e66da9
Commit
f7e66da9
authored
Mar 25, 2016
by
Michelle Noorali
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #448 from michelleN/helm-repo-ref
feat(repo): remove repo by name + refactors
parents
1d3b93ef
4df486e3
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
128 additions
and
64 deletions
+128
-64
repository.go
cmd/helm/repository.go
+36
-30
chartrepos.go
cmd/manager/chartrepos.go
+9
-5
manager.go
cmd/manager/manager/manager.go
+8
-4
testutil.go
cmd/manager/testutil.go
+2
-2
gcs_repo.go
pkg/repo/gcs_repo.go
+3
-3
gcs_repo_test.go
pkg/repo/gcs_repo_test.go
+3
-2
inmem_repo_service.go
pkg/repo/inmem_repo_service.go
+21
-6
inmem_repo_service_test.go
pkg/repo/inmem_repo_service_test.go
+25
-2
repo.go
pkg/repo/repo.go
+9
-3
repo_test.go
pkg/repo/repo_test.go
+4
-4
repoprovider.go
pkg/repo/repoprovider.go
+1
-1
repoprovider_test.go
pkg/repo/repoprovider_test.go
+1
-1
types.go
pkg/repo/types.go
+6
-1
No files found.
cmd/helm/repository.go
View file @
f7e66da9
...
@@ -17,51 +17,44 @@ limitations under the License.
...
@@ -17,51 +17,44 @@ limitations under the License.
package
main
package
main
import
(
import
(
"encoding/json"
"errors"
"errors"
"path/filepath"
"github.com/codegangsta/cli"
"github.com/codegangsta/cli"
"github.com/kubernetes/helm/pkg/format"
"github.com/kubernetes/helm/pkg/format"
"github.com/kubernetes/helm/pkg/repo"
)
)
func
init
()
{
func
init
()
{
addCommands
(
repoCommands
())
addCommands
(
repoCommands
())
}
}
const
chartRepoPath
=
"
chart_
repositories"
const
chartRepoPath
=
"repositories"
func
repoCommands
()
cli
.
Command
{
func
repoCommands
()
cli
.
Command
{
return
cli
.
Command
{
return
cli
.
Command
{
Name
:
"repository"
,
Name
:
"repository"
,
Aliases
:
[]
string
{
"repo"
},
Aliases
:
[]
string
{
"repo"
},
Usage
:
"Perform repository operations."
,
Usage
:
"Perform
chart
repository operations."
,
Subcommands
:
[]
cli
.
Command
{
Subcommands
:
[]
cli
.
Command
{
{
{
Name
:
"add"
,
Name
:
"add"
,
Usage
:
"Add a repository to the remote manager."
,
Usage
:
"Add a chart repository to the remote manager."
,
ArgsUsage
:
"REPOSITORY"
,
ArgsUsage
:
"[NAME] [REPOSITORY_URL]"
,
Flags
:
[]
cli
.
Flag
{
Action
:
func
(
c
*
cli
.
Context
)
{
run
(
c
,
addRepo
)
},
cli
.
StringFlag
{
Name
:
"cred"
,
Usage
:
"The name of the credential."
,
},
},
Action
:
func
(
c
*
cli
.
Context
)
{
run
(
c
,
addRepo
)
},
},
{
Name
:
"show"
,
Usage
:
"Show the repository details for a given repository."
,
ArgsUsage
:
"REPOSITORY"
,
},
},
{
{
Name
:
"list"
,
Name
:
"list"
,
Usage
:
"List the repositories on the remote manager."
,
Usage
:
"List the
chart
repositories on the remote manager."
,
ArgsUsage
:
""
,
ArgsUsage
:
""
,
Action
:
func
(
c
*
cli
.
Context
)
{
run
(
c
,
listRepos
)
},
Action
:
func
(
c
*
cli
.
Context
)
{
run
(
c
,
listRepos
)
},
},
},
{
{
Name
:
"remove"
,
Name
:
"remove"
,
Aliases
:
[]
string
{
"rm"
},
Aliases
:
[]
string
{
"rm"
},
Usage
:
"Remove a repository from the remote manager."
,
Usage
:
"Remove a
chart
repository from the remote manager."
,
ArgsUsage
:
"REPOSITORY"
,
ArgsUsage
:
"REPOSITORY
_URL
"
,
Action
:
func
(
c
*
cli
.
Context
)
{
run
(
c
,
removeRepo
)
},
Action
:
func
(
c
*
cli
.
Context
)
{
run
(
c
,
removeRepo
)
},
},
},
},
},
...
@@ -70,35 +63,48 @@ func repoCommands() cli.Command {
...
@@ -70,35 +63,48 @@ func repoCommands() cli.Command {
func
addRepo
(
c
*
cli
.
Context
)
error
{
func
addRepo
(
c
*
cli
.
Context
)
error
{
args
:=
c
.
Args
()
args
:=
c
.
Args
()
if
len
(
args
)
<
1
{
if
len
(
args
)
<
2
{
return
errors
.
New
(
"'helm repo add' requires a
repository as an argument
"
)
return
errors
.
New
(
"'helm repo add' requires a
name and repository url as arguments
"
)
}
}
dest
:=
""
name
:=
args
[
0
]
if
_
,
err
:=
NewClient
(
c
)
.
Post
(
chartRepoPath
,
nil
,
&
dest
);
err
!=
nil
{
repoURL
:=
args
[
1
]
payload
,
_
:=
json
.
Marshal
(
repo
.
Repo
{
URL
:
repoURL
,
Name
:
name
})
msg
:=
""
if
_
,
err
:=
NewClient
(
c
)
.
Post
(
chartRepoPath
,
payload
,
&
msg
);
err
!=
nil
{
//TODO: Return more specific errors to the user
return
err
return
err
}
}
format
.
Msg
(
dest
)
format
.
Info
(
name
+
" has been added to your chart repositories!"
)
return
nil
return
nil
}
}
func
listRepos
(
c
*
cli
.
Context
)
error
{
func
listRepos
(
c
*
cli
.
Context
)
error
{
dest
:=
""
dest
:=
map
[
string
]
string
{}
if
_
,
err
:=
NewClient
(
c
)
.
Get
(
chartRepoPath
,
&
dest
);
err
!=
nil
{
if
_
,
err
:=
NewClient
(
c
)
.
Get
(
chartRepoPath
,
&
dest
);
err
!=
nil
{
return
err
return
err
}
}
format
.
Msg
(
dest
)
if
len
(
dest
)
<
1
{
format
.
Info
(
"Looks like you don't have any chart repositories."
)
format
.
Info
(
"Add a chart repository using the `helm repo add [REPOSITORY_URL]` command."
)
}
else
{
format
.
Msg
(
"Chart Repositories:
\n
"
)
for
k
,
v
:=
range
dest
{
//TODO: make formatting pretty
format
.
Msg
(
k
+
"
\t
"
+
v
+
"
\n
"
)
}
}
return
nil
return
nil
}
}
func
removeRepo
(
c
*
cli
.
Context
)
error
{
func
removeRepo
(
c
*
cli
.
Context
)
error
{
args
:=
c
.
Args
()
args
:=
c
.
Args
()
if
len
(
args
)
<
1
{
if
len
(
args
)
<
1
{
return
errors
.
New
(
"'helm repo remove' requires a repository as an argument"
)
return
errors
.
New
(
"'helm repo remove' requires a repository
name
as an argument"
)
}
}
dest
:=
""
name
:=
args
[
0
]
if
_
,
err
:=
NewClient
(
c
)
.
Delete
(
chartRepoPath
,
&
dest
);
err
!=
nil
{
if
_
,
err
:=
NewClient
(
c
)
.
Delete
(
filepath
.
Join
(
chartRepoPath
,
name
),
nil
);
err
!=
nil
{
return
err
return
err
}
}
format
.
Msg
(
dest
)
format
.
Msg
(
name
+
" has been removed.
\n
"
)
return
nil
return
nil
}
}
cmd/manager/chartrepos.go
View file @
f7e66da9
...
@@ -22,6 +22,7 @@ import (
...
@@ -22,6 +22,7 @@ import (
"github.com/kubernetes/helm/pkg/repo"
"github.com/kubernetes/helm/pkg/repo"
"github.com/kubernetes/helm/pkg/util"
"github.com/kubernetes/helm/pkg/util"
"encoding/json"
"net/http"
"net/http"
"net/url"
"net/url"
"regexp"
"regexp"
...
@@ -33,7 +34,7 @@ func registerChartRepoRoutes(c *router.Context, h *router.Handler) {
...
@@ -33,7 +34,7 @@ func registerChartRepoRoutes(c *router.Context, h *router.Handler) {
h
.
Add
(
"GET /repositories/*/charts"
,
listRepoChartsHandlerFunc
)
h
.
Add
(
"GET /repositories/*/charts"
,
listRepoChartsHandlerFunc
)
h
.
Add
(
"GET /repositories/*/charts/*"
,
getRepoChartHandlerFunc
)
h
.
Add
(
"GET /repositories/*/charts/*"
,
getRepoChartHandlerFunc
)
h
.
Add
(
"POST /repositories"
,
addChartRepoHandlerFunc
)
h
.
Add
(
"POST /repositories"
,
addChartRepoHandlerFunc
)
h
.
Add
(
"DELETE /repositories"
,
removeChartRepoHandlerFunc
)
h
.
Add
(
"DELETE /repositories
/*
"
,
removeChartRepoHandlerFunc
)
}
}
func
listChartReposHandlerFunc
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
c
*
router
.
Context
)
error
{
func
listChartReposHandlerFunc
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
c
*
router
.
Context
)
error
{
...
@@ -62,24 +63,27 @@ func addChartRepoHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.C
...
@@ -62,24 +63,27 @@ func addChartRepoHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.C
return
nil
return
nil
}
}
util
.
LogHandlerExitWithText
(
handler
,
w
,
"added"
,
http
.
StatusOK
)
msg
,
_
:=
json
.
Marshal
(
cr
.
Name
+
" has been added to the list of chart repositories."
)
util
.
LogHandlerExitWithJSON
(
handler
,
w
,
msg
,
http
.
StatusCreated
)
return
nil
return
nil
}
}
func
removeChartRepoHandlerFunc
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
c
*
router
.
Context
)
error
{
func
removeChartRepoHandlerFunc
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
c
*
router
.
Context
)
error
{
handler
:=
"manager: remove chart repository"
handler
:=
"manager: remove chart repository"
util
.
LogHandlerEntry
(
handler
,
r
)
util
.
LogHandlerEntry
(
handler
,
r
)
URL
,
err
:=
pos
(
w
,
r
,
2
)
defer
r
.
Body
.
Close
()
name
,
err
:=
pos
(
w
,
r
,
2
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
err
=
c
.
Manager
.
RemoveChartRepo
(
URL
)
err
=
c
.
Manager
.
RemoveChartRepo
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
util
.
LogHandlerExitWithText
(
handler
,
w
,
"removed"
,
http
.
StatusOK
)
msg
,
_
:=
json
.
Marshal
(
name
+
" has been removed from the list of chart repositories."
)
util
.
LogHandlerExitWithJSON
(
handler
,
w
,
msg
,
http
.
StatusOK
)
return
nil
return
nil
}
}
...
...
cmd/manager/manager/manager.go
View file @
f7e66da9
...
@@ -58,7 +58,7 @@ type Manager interface {
...
@@ -58,7 +58,7 @@ type Manager interface {
GetCredential
(
name
string
)
(
*
repo
.
Credential
,
error
)
GetCredential
(
name
string
)
(
*
repo
.
Credential
,
error
)
// Chart Repositories
// Chart Repositories
ListChartRepos
()
(
[
]
string
,
error
)
ListChartRepos
()
(
map
[
string
]
string
,
error
)
AddChartRepo
(
addition
repo
.
IRepo
)
error
AddChartRepo
(
addition
repo
.
IRepo
)
error
RemoveChartRepo
(
name
string
)
error
RemoveChartRepo
(
name
string
)
error
GetChartRepo
(
URL
string
)
(
repo
.
IRepo
,
error
)
GetChartRepo
(
URL
string
)
(
repo
.
IRepo
,
error
)
...
@@ -367,7 +367,7 @@ func (m *manager) GetChart(reference string) (*chart.Chart, error) {
...
@@ -367,7 +367,7 @@ func (m *manager) GetChart(reference string) (*chart.Chart, error) {
}
}
// ListChartRepos returns the list of available chart repository URLs
// ListChartRepos returns the list of available chart repository URLs
func
(
m
*
manager
)
ListChartRepos
()
(
[
]
string
,
error
)
{
func
(
m
*
manager
)
ListChartRepos
()
(
map
[
string
]
string
,
error
)
{
return
m
.
service
.
ListRepos
()
return
m
.
service
.
ListRepos
()
}
}
...
@@ -377,8 +377,12 @@ func (m *manager) AddChartRepo(addition repo.IRepo) error {
...
@@ -377,8 +377,12 @@ func (m *manager) AddChartRepo(addition repo.IRepo) error {
}
}
// RemoveChartRepo removes a chart repository from the list by URL
// RemoveChartRepo removes a chart repository from the list by URL
func
(
m
*
manager
)
RemoveChartRepo
(
URL
string
)
error
{
func
(
m
*
manager
)
RemoveChartRepo
(
name
string
)
error
{
return
m
.
service
.
DeleteRepo
(
URL
)
url
,
err
:=
m
.
service
.
GetRepoURLByName
(
name
)
if
err
!=
nil
{
return
err
}
return
m
.
service
.
DeleteRepo
(
url
)
}
}
// GetChartRepo returns the chart repository with the given URL
// GetChartRepo returns the chart repository with the given URL
...
...
cmd/manager/testutil.go
View file @
f7e66da9
...
@@ -111,8 +111,8 @@ func (m *mockManager) AddChartRepo(addition repo.IRepo) error {
...
@@ -111,8 +111,8 @@ func (m *mockManager) AddChartRepo(addition repo.IRepo) error {
return
nil
return
nil
}
}
func
(
m
*
mockManager
)
ListChartRepos
()
(
[
]
string
,
error
)
{
func
(
m
*
mockManager
)
ListChartRepos
()
(
map
[
string
]
string
,
error
)
{
return
[
]
string
{},
nil
return
map
[
string
]
string
{},
nil
}
}
func
(
m
*
mockManager
)
RemoveChartRepo
(
name
string
)
error
{
func
(
m
*
mockManager
)
RemoveChartRepo
(
name
string
)
error
{
...
...
pkg/repo/gcs_repo.go
View file @
f7e66da9
...
@@ -60,12 +60,12 @@ type GCSRepo struct {
...
@@ -60,12 +60,12 @@ type GCSRepo struct {
// NewPublicGCSRepo creates a new an IStorageRepo for the public GCS repository.
// NewPublicGCSRepo creates a new an IStorageRepo for the public GCS repository.
func
NewPublicGCSRepo
(
httpClient
*
http
.
Client
)
(
IStorageRepo
,
error
)
{
func
NewPublicGCSRepo
(
httpClient
*
http
.
Client
)
(
IStorageRepo
,
error
)
{
return
NewGCSRepo
(
GCSPublicRepoURL
,
""
,
nil
)
return
NewGCSRepo
(
GCSPublicRepoURL
,
""
,
GCSPublicRepoBucket
,
nil
)
}
}
// NewGCSRepo creates a new IStorageRepo for a given GCS repository.
// NewGCSRepo creates a new IStorageRepo for a given GCS repository.
func
NewGCSRepo
(
URL
,
credentialName
string
,
httpClient
*
http
.
Client
)
(
IStorageRepo
,
error
)
{
func
NewGCSRepo
(
URL
,
credentialName
,
repoName
string
,
httpClient
*
http
.
Client
)
(
IStorageRepo
,
error
)
{
r
,
err
:=
newRepo
(
URL
,
credentialName
,
GCSRepoFormat
,
GCSRepoType
)
r
,
err
:=
newRepo
(
URL
,
credentialName
,
repoName
,
GCSRepoFormat
,
GCSRepoType
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
pkg/repo/gcs_repo_test.go
View file @
f7e66da9
...
@@ -33,6 +33,7 @@ var (
...
@@ -33,6 +33,7 @@ var (
TestChartFile
=
"testdata/frobnitz/Chart.yaml"
TestChartFile
=
"testdata/frobnitz/Chart.yaml"
TestShouldFindRegex
=
regexp
.
MustCompile
(
TestArchiveName
)
TestShouldFindRegex
=
regexp
.
MustCompile
(
TestArchiveName
)
TestShouldNotFindRegex
=
regexp
.
MustCompile
(
"foobar"
)
TestShouldNotFindRegex
=
regexp
.
MustCompile
(
"foobar"
)
TestName
=
"bucket-name"
)
)
func
TestValidGSURL
(
t
*
testing
.
T
)
{
func
TestValidGSURL
(
t
*
testing
.
T
)
{
...
@@ -51,7 +52,7 @@ func TestValidGSURL(t *testing.T) {
...
@@ -51,7 +52,7 @@ func TestValidGSURL(t *testing.T) {
func
TestInvalidGSURL
(
t
*
testing
.
T
)
{
func
TestInvalidGSURL
(
t
*
testing
.
T
)
{
var
invalidGSURL
=
"https://valid.url/wrong/scheme"
var
invalidGSURL
=
"https://valid.url/wrong/scheme"
_
,
err
:=
NewGCSRepo
(
invalidGSURL
,
TestRepoCredentialName
,
nil
)
_
,
err
:=
NewGCSRepo
(
invalidGSURL
,
TestRepoCredentialName
,
TestName
,
nil
)
if
err
==
nil
{
if
err
==
nil
{
t
.
Fatalf
(
"expected error did not occur for invalid GS URL"
)
t
.
Fatalf
(
"expected error did not occur for invalid GS URL"
)
}
}
...
@@ -126,7 +127,7 @@ func TestGetChartWithInvalidName(t *testing.T) {
...
@@ -126,7 +127,7 @@ func TestGetChartWithInvalidName(t *testing.T) {
}
}
func
getTestRepo
(
t
*
testing
.
T
)
IStorageRepo
{
func
getTestRepo
(
t
*
testing
.
T
)
IStorageRepo
{
tr
,
err
:=
NewGCSRepo
(
TestRepoURL
,
TestRepoCredentialName
,
nil
)
tr
,
err
:=
NewGCSRepo
(
TestRepoURL
,
TestRepoCredentialName
,
TestName
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
...
pkg/repo/inmem_repo_service.go
View file @
f7e66da9
...
@@ -42,13 +42,13 @@ func NewInmemRepoService() IRepoService {
...
@@ -42,13 +42,13 @@ func NewInmemRepoService() IRepoService {
}
}
// ListRepos returns the list of all known chart repositories
// ListRepos returns the list of all known chart repositories
func
(
rs
*
inmemRepoService
)
ListRepos
()
(
[
]
string
,
error
)
{
func
(
rs
*
inmemRepoService
)
ListRepos
()
(
map
[
string
]
string
,
error
)
{
rs
.
RLock
()
rs
.
RLock
()
defer
rs
.
RUnlock
()
defer
rs
.
RUnlock
()
ret
:=
[]
string
{}
ret
:=
make
(
map
[
string
]
string
)
for
_
,
r
:=
range
rs
.
repositories
{
for
_
,
r
:=
range
rs
.
repositories
{
ret
=
append
(
ret
,
r
.
GetURL
()
)
ret
[
r
.
GetName
()]
=
r
.
GetURL
(
)
}
}
return
ret
,
nil
return
ret
,
nil
...
@@ -60,9 +60,14 @@ func (rs *inmemRepoService) CreateRepo(repository IRepo) error {
...
@@ -60,9 +60,14 @@ func (rs *inmemRepoService) CreateRepo(repository IRepo) error {
defer
rs
.
Unlock
()
defer
rs
.
Unlock
()
URL
:=
repository
.
GetURL
()
URL
:=
repository
.
GetURL
()
_
,
ok
:=
rs
.
repositories
[
URL
]
name
:=
repository
.
GetName
()
if
ok
{
return
fmt
.
Errorf
(
"Repository with URL %s already exists"
,
URL
)
for
u
,
r
:=
range
rs
.
repositories
{
if
u
==
URL
{
return
fmt
.
Errorf
(
"Repository with URL %s already exists"
,
URL
)
}
else
if
r
.
GetName
()
==
name
{
return
fmt
.
Errorf
(
"Repository with Name %s already exists"
,
name
)
}
}
}
rs
.
repositories
[
URL
]
=
repository
rs
.
repositories
[
URL
]
=
repository
...
@@ -117,3 +122,13 @@ func (rs *inmemRepoService) DeleteRepo(URL string) error {
...
@@ -117,3 +122,13 @@ func (rs *inmemRepoService) DeleteRepo(URL string) error {
delete
(
rs
.
repositories
,
URL
)
delete
(
rs
.
repositories
,
URL
)
return
nil
return
nil
}
}
func
(
rs
*
inmemRepoService
)
GetRepoURLByName
(
name
string
)
(
string
,
error
)
{
for
url
,
r
:=
range
rs
.
repositories
{
if
r
.
GetName
()
==
name
{
return
url
,
nil
}
}
err
:=
fmt
.
Errorf
(
"No repository url found with name %s"
,
name
)
return
""
,
err
}
pkg/repo/inmem_repo_service_test.go
View file @
f7e66da9
...
@@ -32,7 +32,11 @@ func TestService(t *testing.T) {
...
@@ -32,7 +32,11 @@ func TestService(t *testing.T) {
t
.
Fatalf
(
"unexpected repo count; want: %d, have %d."
,
1
,
len
(
repos
))
t
.
Fatalf
(
"unexpected repo count; want: %d, have %d."
,
1
,
len
(
repos
))
}
}
tr
,
err
:=
rs
.
GetRepoByURL
(
repos
[
0
])
u
:=
""
for
_
,
url
:=
range
repos
{
u
=
url
}
tr
,
err
:=
rs
.
GetRepoByURL
(
u
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
@@ -71,7 +75,7 @@ func TestService(t *testing.T) {
...
@@ -71,7 +75,7 @@ func TestService(t *testing.T) {
func
TestCreateRepoWithDuplicateURL
(
t
*
testing
.
T
)
{
func
TestCreateRepoWithDuplicateURL
(
t
*
testing
.
T
)
{
rs
:=
NewInmemRepoService
()
rs
:=
NewInmemRepoService
()
r
,
err
:=
newRepo
(
GCSPublicRepoURL
,
""
,
GCSRepoFormat
,
GCSRepoType
)
r
,
err
:=
newRepo
(
GCSPublicRepoURL
,
""
,
TestName
,
GCSRepoFormat
,
GCSRepoType
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"cannot create test repo: %s"
,
err
)
t
.
Fatalf
(
"cannot create test repo: %s"
,
err
)
}
}
...
@@ -90,6 +94,25 @@ func TestGetRepoWithInvalidURL(t *testing.T) {
...
@@ -90,6 +94,25 @@ func TestGetRepoWithInvalidURL(t *testing.T) {
}
}
}
}
func
TestGetRepoURLByName
(
t
*
testing
.
T
)
{
rs
:=
NewInmemRepoService
()
testURL
:=
"gcs://helm-test-charts"
r
,
err
:=
newRepo
(
testURL
,
""
,
TestName
,
GCSRepoFormat
,
GCSRepoType
)
err
=
rs
.
CreateRepo
(
r
)
if
err
!=
nil
{
t
.
Fatalf
(
"Error creating repo: %s"
,
err
)
}
expectedURL
:=
testURL
actualURL
,
err
:=
rs
.
GetRepoURLByName
(
TestName
)
if
err
!=
nil
{
t
.
Fatalf
(
"%v"
,
err
)
}
if
expectedURL
!=
actualURL
{
t
.
Fatalf
(
"Incorrect resulting URL. Expected %s. Got %s"
,
expectedURL
,
actualURL
)
}
}
func
TestGetRepoWithInvalidChartURL
(
t
*
testing
.
T
)
{
func
TestGetRepoWithInvalidChartURL
(
t
*
testing
.
T
)
{
invalidURL
:=
"https://not.a.valid/url"
invalidURL
:=
"https://not.a.valid/url"
rs
:=
NewInmemRepoService
()
rs
:=
NewInmemRepoService
()
...
...
pkg/repo/repo.go
View file @
f7e66da9
...
@@ -22,11 +22,11 @@ import (
...
@@ -22,11 +22,11 @@ import (
)
)
// NewRepo takes params and returns a IRepo
// NewRepo takes params and returns a IRepo
func
NewRepo
(
URL
,
credentialName
,
repoFormat
,
repoType
string
)
(
IRepo
,
error
)
{
func
NewRepo
(
URL
,
credentialName
,
repo
Name
,
repo
Format
,
repoType
string
)
(
IRepo
,
error
)
{
return
newRepo
(
URL
,
credentialName
,
ERepoFormat
(
repoFormat
),
ERepoType
(
repoType
))
return
newRepo
(
URL
,
credentialName
,
repoName
,
ERepoFormat
(
repoFormat
),
ERepoType
(
repoType
))
}
}
func
newRepo
(
URL
,
credentialName
string
,
repoFormat
ERepoFormat
,
repoType
ERepoType
)
(
*
Repo
,
error
)
{
func
newRepo
(
URL
,
credentialName
,
repoName
string
,
repoFormat
ERepoFormat
,
repoType
ERepoType
)
(
*
Repo
,
error
)
{
_
,
err
:=
url
.
Parse
(
URL
)
_
,
err
:=
url
.
Parse
(
URL
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"invalid URL (%s): %s"
,
URL
,
err
)
return
nil
,
fmt
.
Errorf
(
"invalid URL (%s): %s"
,
URL
,
err
)
...
@@ -41,6 +41,7 @@ func newRepo(URL, credentialName string, repoFormat ERepoFormat, repoType ERepoT
...
@@ -41,6 +41,7 @@ func newRepo(URL, credentialName string, repoFormat ERepoFormat, repoType ERepoT
}
}
r
:=
&
Repo
{
r
:=
&
Repo
{
Name
:
repoName
,
URL
:
URL
,
URL
:
URL
,
CredentialName
:
credentialName
,
CredentialName
:
credentialName
,
Type
:
repoType
,
Type
:
repoType
,
...
@@ -65,6 +66,11 @@ func (r *Repo) GetType() ERepoType {
...
@@ -65,6 +66,11 @@ func (r *Repo) GetType() ERepoType {
return
r
.
Type
return
r
.
Type
}
}
// GetName returns the name of this repository.
func
(
r
*
Repo
)
GetName
()
string
{
return
r
.
Name
}
// GetURL returns the URL to the root of this repository.
// GetURL returns the URL to the root of this repository.
func
(
r
*
Repo
)
GetURL
()
string
{
func
(
r
*
Repo
)
GetURL
()
string
{
return
r
.
URL
return
r
.
URL
...
...
pkg/repo/repo_test.go
View file @
f7e66da9
...
@@ -29,7 +29,7 @@ var (
...
@@ -29,7 +29,7 @@ var (
)
)
func
TestValidRepoURL
(
t
*
testing
.
T
)
{
func
TestValidRepoURL
(
t
*
testing
.
T
)
{
tr
,
err
:=
NewRepo
(
TestRepoURL
,
TestRepoCredentialName
,
string
(
TestRepoFormat
),
string
(
TestRepoType
))
tr
,
err
:=
NewRepo
(
TestRepoURL
,
TestRepoCredentialName
,
TestRepoBucket
,
string
(
TestRepoFormat
),
string
(
TestRepoType
))
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
@@ -40,14 +40,14 @@ func TestValidRepoURL(t *testing.T) {
...
@@ -40,14 +40,14 @@ func TestValidRepoURL(t *testing.T) {
}
}
func
TestInvalidRepoURL
(
t
*
testing
.
T
)
{
func
TestInvalidRepoURL
(
t
*
testing
.
T
)
{
_
,
err
:=
newRepo
(
"%:invalid&url:%"
,
TestRepoCredentialName
,
TestRepoFormat
,
TestRepoType
)
_
,
err
:=
newRepo
(
"%:invalid&url:%"
,
TestRepoCredentialName
,
TestRepo
Bucket
,
TestRepo
Format
,
TestRepoType
)
if
err
==
nil
{
if
err
==
nil
{
t
.
Fatalf
(
"expected error did not occur for invalid URL"
)
t
.
Fatalf
(
"expected error did not occur for invalid URL"
)
}
}
}
}
func
TestDefaultCredentialName
(
t
*
testing
.
T
)
{
func
TestDefaultCredentialName
(
t
*
testing
.
T
)
{
tr
,
err
:=
newRepo
(
TestRepoURL
,
""
,
TestRepoFormat
,
TestRepoType
)
tr
,
err
:=
newRepo
(
TestRepoURL
,
""
,
TestRepo
Bucket
,
TestRepo
Format
,
TestRepoType
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"cannot create repo using default credential name"
)
t
.
Fatalf
(
"cannot create repo using default credential name"
)
}
}
...
@@ -60,7 +60,7 @@ func TestDefaultCredentialName(t *testing.T) {
...
@@ -60,7 +60,7 @@ func TestDefaultCredentialName(t *testing.T) {
}
}
func
TestInvalidRepoFormat
(
t
*
testing
.
T
)
{
func
TestInvalidRepoFormat
(
t
*
testing
.
T
)
{
_
,
err
:=
newRepo
(
TestRepoURL
,
TestRepoCredentialName
,
""
,
TestRepoType
)
_
,
err
:=
newRepo
(
TestRepoURL
,
TestRepoCredentialName
,
TestRepoBucket
,
""
,
TestRepoType
)
if
err
==
nil
{
if
err
==
nil
{
t
.
Fatalf
(
"expected error did not occur for invalid format"
)
t
.
Fatalf
(
"expected error did not occur for invalid format"
)
}
}
...
...
pkg/repo/repoprovider.go
View file @
f7e66da9
...
@@ -225,7 +225,7 @@ func (gcsrp gcsRepoProvider) GetGCSRepo(r IRepo) (IStorageRepo, error) {
...
@@ -225,7 +225,7 @@ func (gcsrp gcsRepoProvider) GetGCSRepo(r IRepo) (IStorageRepo, error) {
return
nil
,
err
return
nil
,
err
}
}
return
NewGCSRepo
(
r
.
GetURL
(),
r
.
GetCredentialName
(),
client
)
return
NewGCSRepo
(
r
.
GetURL
(),
r
.
GetCredentialName
(),
r
.
GetName
(),
client
)
}
}
func
(
gcsrp
gcsRepoProvider
)
createGCSClient
(
credentialName
string
)
(
*
http
.
Client
,
error
)
{
func
(
gcsrp
gcsRepoProvider
)
createGCSClient
(
credentialName
string
)
(
*
http
.
Client
,
error
)
{
...
...
pkg/repo/repoprovider_test.go
View file @
f7e66da9
...
@@ -116,7 +116,7 @@ func TestGetChartByReferenceWithValidReferences(t *testing.T) {
...
@@ -116,7 +116,7 @@ func TestGetChartByReferenceWithValidReferences(t *testing.T) {
func
getTestRepoProvider
(
t
*
testing
.
T
)
IRepoProvider
{
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
(
TestRepoURL
,
TestRepoCredentialName
,
TestRepoFormat
,
TestRepoType
)
tr
,
err
:=
newRepo
(
TestRepoURL
,
TestRepoCredentialName
,
Test
Name
,
Test
RepoFormat
,
TestRepoType
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"cannot create test repository: %s"
,
err
)
t
.
Fatalf
(
"cannot create test repository: %s"
,
err
)
}
}
...
...
pkg/repo/types.go
View file @
f7e66da9
...
@@ -70,6 +70,7 @@ const (
...
@@ -70,6 +70,7 @@ const (
// Repo describes a repository
// Repo describes a repository
type
Repo
struct
{
type
Repo
struct
{
Name
string
`json:"name"`
// Name of 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,omitempty"`
// Credential name used to access this repository
CredentialName
string
`json:"credentialname,omitempty"`
// Credential name used to access this repository
Format
ERepoFormat
`json:"format,omitempty"`
// Format of this repository
Format
ERepoFormat
`json:"format,omitempty"`
// Format of this repository
...
@@ -78,6 +79,8 @@ type Repo struct {
...
@@ -78,6 +79,8 @@ type Repo struct {
// IRepo abstracts a repository.
// IRepo abstracts a repository.
type
IRepo
interface
{
type
IRepo
interface
{
// GetName returns the name of the repository
GetName
()
string
// GetURL returns the URL to the root of this repository.
// GetURL returns the URL to the root of this repository.
GetURL
()
string
GetURL
()
string
// GetCredentialName returns the credential name used to access this repository.
// GetCredentialName returns the credential name used to access this repository.
...
@@ -115,11 +118,13 @@ type IStorageRepo interface {
...
@@ -115,11 +118,13 @@ type IStorageRepo interface {
// repository based operations, such as search and chart reference resolution.
// repository based operations, such as search and chart reference resolution.
type
IRepoService
interface
{
type
IRepoService
interface
{
// ListRepos returns the list of all known chart repositories
// ListRepos returns the list of all known chart repositories
ListRepos
()
(
[
]
string
,
error
)
ListRepos
()
(
map
[
string
]
string
,
error
)
// CreateRepo adds a known repository to the list
// CreateRepo adds a known repository to the list
CreateRepo
(
repository
IRepo
)
error
CreateRepo
(
repository
IRepo
)
error
// GetRepoByURL returns the repository with the given name
// GetRepoByURL returns the repository with the given name
GetRepoByURL
(
name
string
)
(
IRepo
,
error
)
GetRepoByURL
(
name
string
)
(
IRepo
,
error
)
// GetRepoURLByName return url for a repository with the given name
GetRepoURLByName
(
name
string
)
(
string
,
error
)
// GetRepoByChartURL returns the repository that backs the given URL
// GetRepoByChartURL returns the repository that backs the given URL
GetRepoByChartURL
(
URL
string
)
(
IRepo
,
error
)
GetRepoByChartURL
(
URL
string
)
(
IRepo
,
error
)
// DeleteRepo removes a known repository from the list
// DeleteRepo removes a known repository from the list
...
...
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