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
a6e1067a
Commit
a6e1067a
authored
Jan 12, 2016
by
jackgr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make github registry provider and repository service mockable.
parent
4ffe3422
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
47 deletions
+77
-47
github_package_registry.go
registry/github_package_registry.go
+5
-6
github_registry.go
registry/github_registry.go
+22
-5
github_template_registry.go
registry/github_template_registry.go
+4
-5
registryprovider.go
registry/registryprovider.go
+46
-31
No files found.
registry/github_package_registry.go
View file @
a6e1067a
...
@@ -17,7 +17,6 @@ limitations under the License.
...
@@ -17,7 +17,6 @@ limitations under the License.
package
registry
package
registry
import
(
import
(
"github.com/google/go-github/github"
"github.com/kubernetes/deployment-manager/common"
"github.com/kubernetes/deployment-manager/common"
"fmt"
"fmt"
...
@@ -41,9 +40,9 @@ type GithubPackageRegistry struct {
...
@@ -41,9 +40,9 @@ type GithubPackageRegistry struct {
}
}
// NewGithubPackageRegistry creates a GithubPackageRegistry.
// NewGithubPackageRegistry creates a GithubPackageRegistry.
func
NewGithubPackageRegistry
(
name
,
shortURL
string
,
client
*
github
.
Client
)
(
GithubPackageRegistry
,
error
)
{
func
NewGithubPackageRegistry
(
name
,
shortURL
string
,
service
RepositoryService
)
(
GithubPackageRegistry
,
error
)
{
format
:=
fmt
.
Sprintf
(
"%s;%s"
,
common
.
UnversionedRegistry
,
common
.
OneLevelRegistry
)
format
:=
fmt
.
Sprintf
(
"%s;%s"
,
common
.
UnversionedRegistry
,
common
.
OneLevelRegistry
)
gr
,
err
:=
newGithubRegistry
(
name
,
shortURL
,
common
.
RegistryFormat
(
format
),
client
)
gr
,
err
:=
newGithubRegistry
(
name
,
shortURL
,
common
.
RegistryFormat
(
format
),
service
)
if
err
!=
nil
{
if
err
!=
nil
{
return
GithubPackageRegistry
{},
err
return
GithubPackageRegistry
{},
err
}
}
...
@@ -64,7 +63,7 @@ func (g GithubPackageRegistry) ListTypes(regex *regexp.Regexp) ([]Type, error) {
...
@@ -64,7 +63,7 @@ func (g GithubPackageRegistry) ListTypes(regex *regexp.Regexp) ([]Type, error) {
var
retTypes
[]
Type
var
retTypes
[]
Type
for
_
,
t
:=
range
types
{
for
_
,
t
:=
range
types
{
// Check to see if there's a Chart.yaml file in the directory
// Check to see if there's a Chart.yaml file in the directory
_
,
dc
,
_
,
err
:=
g
.
client
.
Repositories
.
GetContents
(
g
.
owner
,
g
.
repository
,
t
,
nil
)
_
,
dc
,
_
,
err
:=
g
.
service
.
GetContents
(
g
.
owner
,
g
.
repository
,
t
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Printf
(
"Failed to list package files at path: %s: %v"
,
t
,
err
)
log
.
Printf
(
"Failed to list package files at path: %s: %v"
,
t
,
err
)
return
nil
,
err
return
nil
,
err
...
@@ -87,7 +86,7 @@ func (g GithubPackageRegistry) GetDownloadURLs(t Type) ([]*url.URL, error) {
...
@@ -87,7 +86,7 @@ func (g GithubPackageRegistry) GetDownloadURLs(t Type) ([]*url.URL, error) {
return
nil
,
err
return
nil
,
err
}
}
_
,
dc
,
_
,
err
:=
g
.
client
.
Repositories
.
GetContents
(
g
.
owner
,
g
.
repository
,
path
,
nil
)
_
,
dc
,
_
,
err
:=
g
.
service
.
GetContents
(
g
.
owner
,
g
.
repository
,
path
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Printf
(
"Failed to list package files at path: %s: %v"
,
path
,
err
)
log
.
Printf
(
"Failed to list package files at path: %s: %v"
,
path
,
err
)
return
nil
,
err
return
nil
,
err
...
@@ -111,7 +110,7 @@ func (g GithubPackageRegistry) GetDownloadURLs(t Type) ([]*url.URL, error) {
...
@@ -111,7 +110,7 @@ func (g GithubPackageRegistry) GetDownloadURLs(t Type) ([]*url.URL, error) {
}
}
func
(
g
GithubPackageRegistry
)
getDirs
(
dir
string
)
([]
string
,
error
)
{
func
(
g
GithubPackageRegistry
)
getDirs
(
dir
string
)
([]
string
,
error
)
{
_
,
dc
,
_
,
err
:=
g
.
client
.
Repositories
.
GetContents
(
g
.
owner
,
g
.
repository
,
dir
,
nil
)
_
,
dc
,
_
,
err
:=
g
.
service
.
GetContents
(
g
.
owner
,
g
.
repository
,
dir
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Printf
(
"Failed to get contents at path: %s: %v"
,
dir
,
err
)
log
.
Printf
(
"Failed to get contents at path: %s: %v"
,
dir
,
err
)
return
nil
,
err
return
nil
,
err
...
...
registry/github_registry.go
View file @
a6e1067a
...
@@ -38,17 +38,34 @@ type githubRegistry struct {
...
@@ -38,17 +38,34 @@ type githubRegistry struct {
repository
string
repository
string
path
string
path
string
format
common
.
RegistryFormat
format
common
.
RegistryFormat
client
*
github
.
Client
service
RepositoryService
}
type
RepositoryService
interface
{
GetContents
(
owner
,
repo
,
path
string
,
opt
*
github
.
RepositoryContentGetOptions
,
)
(
fileContent
*
github
.
RepositoryContent
,
directoryContent
[]
*
github
.
RepositoryContent
,
resp
*
github
.
Response
,
err
error
,
)
}
}
// newGithubRegistry creates a githubRegistry.
// newGithubRegistry creates a githubRegistry.
func
newGithubRegistry
(
name
,
shortURL
string
,
format
common
.
RegistryFormat
,
client
*
github
.
Client
)
(
githubRegistry
,
error
)
{
func
newGithubRegistry
(
name
,
shortURL
string
,
format
common
.
RegistryFormat
,
service
RepositoryService
)
(
githubRegistry
,
error
)
{
trimmed
:=
util
.
TrimURLScheme
(
shortURL
)
trimmed
:=
util
.
TrimURLScheme
(
shortURL
)
owner
,
repository
,
path
,
err
:=
parseGithubShortURL
(
trimmed
)
owner
,
repository
,
path
,
err
:=
parseGithubShortURL
(
trimmed
)
if
err
!=
nil
{
if
err
!=
nil
{
return
githubRegistry
{},
fmt
.
Errorf
(
"cannot create Github template registry %s: %s"
,
name
,
err
)
return
githubRegistry
{},
fmt
.
Errorf
(
"cannot create Github template registry %s: %s"
,
name
,
err
)
}
}
if
service
==
nil
{
client
:=
github
.
NewClient
(
nil
)
service
=
client
.
Repositories
}
return
githubRegistry
{
return
githubRegistry
{
name
:
name
,
name
:
name
,
shortURL
:
trimmed
,
shortURL
:
trimmed
,
...
@@ -56,7 +73,7 @@ func newGithubRegistry(name, shortURL string, format common.RegistryFormat, clie
...
@@ -56,7 +73,7 @@ func newGithubRegistry(name, shortURL string, format common.RegistryFormat, clie
repository
:
repository
,
repository
:
repository
,
path
:
path
,
path
:
path
,
format
:
format
,
format
:
format
,
client
:
client
,
service
:
service
,
},
nil
},
nil
}
}
...
@@ -165,7 +182,7 @@ func (g githubRegistry) GetDownloadURLs(t Type) ([]*url.URL, error) {
...
@@ -165,7 +182,7 @@ func (g githubRegistry) GetDownloadURLs(t Type) ([]*url.URL, error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
_
,
dc
,
_
,
err
:=
g
.
client
.
Repositories
.
GetContents
(
g
.
owner
,
g
.
repository
,
path
,
nil
)
_
,
dc
,
_
,
err
:=
g
.
service
.
GetContents
(
g
.
owner
,
g
.
repository
,
path
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"cannot list versions at path %s: %v"
,
path
,
err
)
return
nil
,
fmt
.
Errorf
(
"cannot list versions at path %s: %v"
,
path
,
err
)
}
}
...
@@ -205,7 +222,7 @@ func (g githubRegistry) getDirs(dir string) ([]string, error) {
...
@@ -205,7 +222,7 @@ func (g githubRegistry) getDirs(dir string) ([]string, error) {
path
=
g
.
path
+
"/"
+
dir
path
=
g
.
path
+
"/"
+
dir
}
}
_
,
dc
,
_
,
err
:=
g
.
client
.
Repositories
.
GetContents
(
g
.
owner
,
g
.
repository
,
path
,
nil
)
_
,
dc
,
_
,
err
:=
g
.
service
.
GetContents
(
g
.
owner
,
g
.
repository
,
path
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Printf
(
"Failed to get contents at path: %s: %v"
,
path
,
err
)
log
.
Printf
(
"Failed to get contents at path: %s: %v"
,
path
,
err
)
return
nil
,
err
return
nil
,
err
...
...
registry/github_template_registry.go
View file @
a6e1067a
...
@@ -17,7 +17,6 @@ limitations under the License.
...
@@ -17,7 +17,6 @@ limitations under the License.
package
registry
package
registry
import
(
import
(
"github.com/google/go-github/github"
"github.com/kubernetes/deployment-manager/common"
"github.com/kubernetes/deployment-manager/common"
"fmt"
"fmt"
...
@@ -54,9 +53,9 @@ type GithubTemplateRegistry struct {
...
@@ -54,9 +53,9 @@ type GithubTemplateRegistry struct {
}
}
// NewGithubTemplateRegistry creates a GithubTemplateRegistry.
// NewGithubTemplateRegistry creates a GithubTemplateRegistry.
func
NewGithubTemplateRegistry
(
name
,
shortURL
string
,
client
*
github
.
Client
)
(
GithubTemplateRegistry
,
error
)
{
func
NewGithubTemplateRegistry
(
name
,
shortURL
string
,
service
RepositoryService
)
(
GithubTemplateRegistry
,
error
)
{
format
:=
fmt
.
Sprintf
(
"%s;%s"
,
common
.
VersionedRegistry
,
common
.
CollectionRegistry
)
format
:=
fmt
.
Sprintf
(
"%s;%s"
,
common
.
VersionedRegistry
,
common
.
CollectionRegistry
)
gr
,
err
:=
newGithubRegistry
(
name
,
shortURL
,
common
.
RegistryFormat
(
format
),
client
)
gr
,
err
:=
newGithubRegistry
(
name
,
shortURL
,
common
.
RegistryFormat
(
format
),
service
)
if
err
!=
nil
{
if
err
!=
nil
{
return
GithubTemplateRegistry
{},
err
return
GithubTemplateRegistry
{},
err
}
}
...
@@ -113,7 +112,7 @@ func (g GithubTemplateRegistry) GetDownloadURLs(t Type) ([]*url.URL, error) {
...
@@ -113,7 +112,7 @@ func (g GithubTemplateRegistry) GetDownloadURLs(t Type) ([]*url.URL, error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
_
,
dc
,
_
,
err
:=
g
.
client
.
Repositories
.
GetContents
(
g
.
owner
,
g
.
repository
,
path
,
nil
)
_
,
dc
,
_
,
err
:=
g
.
service
.
GetContents
(
g
.
owner
,
g
.
repository
,
path
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"cannot list versions at path %s: %v"
,
path
,
err
)
return
nil
,
fmt
.
Errorf
(
"cannot list versions at path %s: %v"
,
path
,
err
)
}
}
...
@@ -153,7 +152,7 @@ func (g GithubTemplateRegistry) getDirs(dir string) ([]string, error) {
...
@@ -153,7 +152,7 @@ func (g GithubTemplateRegistry) getDirs(dir string) ([]string, error) {
path
=
g
.
path
+
"/"
+
dir
path
=
g
.
path
+
"/"
+
dir
}
}
_
,
dc
,
_
,
err
:=
g
.
client
.
Repositories
.
GetContents
(
g
.
owner
,
g
.
repository
,
path
,
nil
)
_
,
dc
,
_
,
err
:=
g
.
service
.
GetContents
(
g
.
owner
,
g
.
repository
,
path
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Printf
(
"Failed to get contents at path: %s: %v"
,
path
,
err
)
log
.
Printf
(
"Failed to get contents at path: %s: %v"
,
path
,
err
)
return
nil
,
err
return
nil
,
err
...
...
registry/registryprovider.go
View file @
a6e1067a
...
@@ -17,7 +17,6 @@ limitations under the License.
...
@@ -17,7 +17,6 @@ limitations under the License.
package
registry
package
registry
import
(
import
(
"github.com/google/go-github/github"
"github.com/kubernetes/deployment-manager/common"
"github.com/kubernetes/deployment-manager/common"
"github.com/kubernetes/deployment-manager/util"
"github.com/kubernetes/deployment-manager/util"
...
@@ -28,55 +27,71 @@ import (
...
@@ -28,55 +27,71 @@ import (
"sync"
"sync"
)
)
// RegistryProvider
returns factories for creating registry client
s.
// RegistryProvider
is a factory for Registry instance
s.
type
RegistryProvider
interface
{
type
RegistryProvider
interface
{
GetRegistryByShortURL
(
URL
string
)
(
Registry
,
error
)
GetRegistryByShortURL
(
URL
string
)
(
Registry
,
error
)
GetRegistryByName
(
registryName
string
)
(
Registry
,
error
)
GetRegistryByName
(
registryName
string
)
(
Registry
,
error
)
}
// GithubRegistryProvider is a factory for GithubRegistry instances.
type
GithubRegistryProvider
interface
{
GetGithubRegistry
(
cr
common
.
Registry
)
(
GithubRegistry
,
error
)
GetGithubRegistry
(
cr
common
.
Registry
)
(
GithubRegistry
,
error
)
}
}
func
NewDefaultRegistryProvider
()
RegistryProvider
{
func
NewDefaultRegistryProvider
()
RegistryProvider
{
return
NewRegistryProvider
(
nil
,
nil
)
}
func
NewRegistryProvider
(
rs
common
.
RegistryService
,
grp
GithubRegistryProvider
)
RegistryProvider
{
if
rs
==
nil
{
rs
=
NewInmemRegistryService
()
}
registries
:=
make
(
map
[
string
]
Registry
)
registries
:=
make
(
map
[
string
]
Registry
)
rs
:=
NewInmemRegistryService
()
rp
:=
registryProvider
{
rs
:
rs
,
registries
:
registries
}
return
&
DefaultRegistryProvider
{
registries
:
registries
,
rs
:
rs
}
if
grp
==
nil
{
grp
=
rp
}
rp
.
grp
=
grp
return
rp
}
}
type
DefaultR
egistryProvider
struct
{
type
r
egistryProvider
struct
{
sync
.
RWMutex
sync
.
RWMutex
registries
map
[
string
]
Registry
rs
common
.
RegistryService
rs
common
.
RegistryService
grp
GithubRegistryProvider
registries
map
[
string
]
Registry
}
}
// Deprecated: Use GetRegistryByShortURL instead.
func
(
rp
registryProvider
)
GetRegistryByShortURL
(
URL
string
)
(
Registry
,
error
)
{
func
(
drp
DefaultRegistryProvider
)
GetRegistryByURL
(
URL
string
)
(
Registry
,
error
)
{
rp
.
RLock
()
return
drp
.
GetRegistryByShortURL
(
URL
)
defer
rp
.
RUnlock
()
}
func
(
drp
DefaultRegistryProvider
)
GetRegistryByShortURL
(
URL
string
)
(
Registry
,
error
)
{
drp
.
RLock
()
defer
drp
.
RUnlock
()
r
:=
d
rp
.
findRegistryByShortURL
(
URL
)
r
:=
rp
.
findRegistryByShortURL
(
URL
)
if
r
==
nil
{
if
r
==
nil
{
cr
,
err
:=
d
rp
.
rs
.
GetByURL
(
URL
)
cr
,
err
:=
rp
.
rs
.
GetByURL
(
URL
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
r
,
err
:=
d
rp
.
GetGithubRegistry
(
*
cr
)
r
,
err
:=
rp
.
GetGithubRegistry
(
*
cr
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
d
rp
.
registries
[
r
.
GetRegistryName
()]
=
r
rp
.
registries
[
r
.
GetRegistryName
()]
=
r
}
}
return
r
,
nil
return
r
,
nil
}
}
func
(
drp
DefaultRegistryProvider
)
findRegistryByShortURL
(
URL
string
)
Registry
{
// findRegistryByShortURL trims the scheme from both the supplied URL
for
_
,
r
:=
range
drp
.
registries
{
// and the short URL returned by GetRegistryShortURL.
if
strings
.
HasPrefix
(
URL
,
r
.
GetRegistryShortURL
())
{
func
(
rp
registryProvider
)
findRegistryByShortURL
(
URL
string
)
Registry
{
trimmed
:=
util
.
TrimURLScheme
(
URL
)
for
_
,
r
:=
range
rp
.
registries
{
if
strings
.
HasPrefix
(
trimmed
,
util
.
TrimURLScheme
(
r
.
GetRegistryShortURL
()))
{
return
r
return
r
}
}
}
}
...
@@ -84,23 +99,23 @@ func (drp DefaultRegistryProvider) findRegistryByShortURL(URL string) Registry {
...
@@ -84,23 +99,23 @@ func (drp DefaultRegistryProvider) findRegistryByShortURL(URL string) Registry {
return
nil
return
nil
}
}
func
(
drp
DefaultR
egistryProvider
)
GetRegistryByName
(
registryName
string
)
(
Registry
,
error
)
{
func
(
rp
r
egistryProvider
)
GetRegistryByName
(
registryName
string
)
(
Registry
,
error
)
{
d
rp
.
RLock
()
rp
.
RLock
()
defer
d
rp
.
RUnlock
()
defer
rp
.
RUnlock
()
r
,
ok
:=
d
rp
.
registries
[
registryName
]
r
,
ok
:=
rp
.
registries
[
registryName
]
if
!
ok
{
if
!
ok
{
cr
,
err
:=
d
rp
.
rs
.
Get
(
registryName
)
cr
,
err
:=
rp
.
rs
.
Get
(
registryName
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
r
,
err
:=
d
rp
.
GetGithubRegistry
(
*
cr
)
r
,
err
:=
rp
.
GetGithubRegistry
(
*
cr
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
d
rp
.
registries
[
r
.
GetRegistryName
()]
=
r
rp
.
registries
[
r
.
GetRegistryName
()]
=
r
}
}
return
r
,
nil
return
r
,
nil
...
@@ -116,15 +131,15 @@ func ParseRegistryFormat(rf common.RegistryFormat) map[common.RegistryFormat]boo
...
@@ -116,15 +131,15 @@ func ParseRegistryFormat(rf common.RegistryFormat) map[common.RegistryFormat]boo
return
result
return
result
}
}
func
(
drp
DefaultR
egistryProvider
)
GetGithubRegistry
(
cr
common
.
Registry
)
(
GithubRegistry
,
error
)
{
func
(
rp
r
egistryProvider
)
GetGithubRegistry
(
cr
common
.
Registry
)
(
GithubRegistry
,
error
)
{
if
cr
.
Type
==
common
.
GithubRegistryType
{
if
cr
.
Type
==
common
.
GithubRegistryType
{
fMap
:=
ParseRegistryFormat
(
cr
.
Format
)
fMap
:=
ParseRegistryFormat
(
cr
.
Format
)
if
fMap
[
common
.
UnversionedRegistry
]
&&
fMap
[
common
.
OneLevelRegistry
]
{
if
fMap
[
common
.
UnversionedRegistry
]
&&
fMap
[
common
.
OneLevelRegistry
]
{
return
NewGithubPackageRegistry
(
cr
.
Name
,
cr
.
URL
,
github
.
NewClient
(
nil
)
)
return
NewGithubPackageRegistry
(
cr
.
Name
,
cr
.
URL
,
nil
)
}
}
if
fMap
[
common
.
VersionedRegistry
]
&&
fMap
[
common
.
CollectionRegistry
]
{
if
fMap
[
common
.
VersionedRegistry
]
&&
fMap
[
common
.
CollectionRegistry
]
{
return
NewGithubTemplateRegistry
(
cr
.
Name
,
cr
.
URL
,
github
.
NewClient
(
nil
)
)
return
NewGithubTemplateRegistry
(
cr
.
Name
,
cr
.
URL
,
nil
)
}
}
return
nil
,
fmt
.
Errorf
(
"unknown registry format: %s"
,
cr
.
Format
)
return
nil
,
fmt
.
Errorf
(
"unknown registry format: %s"
,
cr
.
Format
)
...
...
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