clean up the code for fetching registries

pull/172/head
vaikas-google 9 years ago
parent 1ee72edf31
commit 3db24d8531

@ -44,7 +44,7 @@ var (
deployment_name = flag.String("name", "", "Name of deployment, used for deploy and update commands (defaults to template name)") deployment_name = flag.String("name", "", "Name of deployment, used for deploy and update commands (defaults to template name)")
stdin = flag.Bool("stdin", false, "Reads a configuration from the standard input") stdin = flag.Bool("stdin", false, "Reads a configuration from the standard input")
properties = flag.String("properties", "", "Properties to use when deploying a template (e.g., --properties k1=v1,k2=v2)") properties = flag.String("properties", "", "Properties to use when deploying a template (e.g., --properties k1=v1,k2=v2)")
template_registry = flag.String("registry", "kubernetes/application-dm-templates", "Github based template registry (owner/repo[/path])") template_registry = flag.String("registry", "github.com/kubernetes/application-dm-templates", "Registry (github.com/owner/repo)")
service = flag.String("service", "http://localhost:8001/api/v1/proxy/namespaces/dm/services/manager-service:manager", "URL for deployment manager") service = flag.String("service", "http://localhost:8001/api/v1/proxy/namespaces/dm/services/manager-service:manager", "URL for deployment manager")
binary = flag.String("binary", "../expandybird/expansion/expansion.py", "Path to template expansion binary") binary = flag.String("binary", "../expandybird/expansion/expansion.py", "Path to template expansion binary")
timeout = flag.Int("timeout", 10, "Time in seconds to wait for response") timeout = flag.Int("timeout", 10, "Time in seconds to wait for response")
@ -82,12 +82,7 @@ var usage = func() {
} }
func getGitRegistry() (registry.Registry, error) { func getGitRegistry() (registry.Registry, error) {
rs := registry.NewDefaultRegistryProvider() return registry.NewDefaultRegistryProvider().GetRegistry(*template_registry)
s := strings.Split(*template_registry, "/")
if len(s) < 2 {
panic(fmt.Errorf("invalid template registry: %s", *template_registry))
}
return rs.GetRegistry("github.com/" + s[0] + "/" + s[1])
} }
func main() { func main() {

@ -66,20 +66,11 @@ func (rs *inmemRepositoryService) Get(name string) (*common.Registry, error) {
func (rs *inmemRepositoryService) Delete(name string) error { func (rs *inmemRepositoryService) Delete(name string) error {
return nil return nil
} }
func (rs *inmemRepositoryService) GetByURL(URL string) (*common.Registry, error) {
if !strings.HasPrefix(URL, "github.com/") {
return nil, fmt.Errorf("Failed to parse short github url: %s", URL)
}
s := strings.Split(URL, "/")
if len(s) < 3 {
panic(fmt.Errorf("invalid template registry: %s", URL))
}
toFind := "github.com/" + s[1] + "/" + s[2] // GetByURL returns a registry that handles the types for a given URL.
fmt.Printf("toFind: %s", toFind) func (rs *inmemRepositoryService) GetByURL(URL string) (*common.Registry, error) {
for _, r := range rs.repositories { for _, r := range rs.repositories {
fmt.Printf("Checking: %s", r.URL) if strings.HasPrefix(r.URL, URL) {
if r.URL == toFind {
return r, nil return r, nil
} }
} }

Loading…
Cancel
Save