func getRegistryProvider() registry.RegistryProvider { if registryProvider == nil { rs := registry.NewInmemRegistryService() _, err := rs.GetByURL(*template_registry) if err != nil { r := newRegistry(*template_registry) if err := rs.Create(r); err != nil { panic(fmt.Errorf("cannot configure registry at %s: %s", r.URL, err)) } } cp := registry.NewInmemCredentialProvider() if *apitoken == "" { *apitoken = os.Getenv("DM_GITHUB_API_TOKEN") } if *apitoken != "" { credential := common.RegistryCredential{ APIToken: common.APITokenCredential(*apitoken), } if err := cp.SetCredential("default", &credential); err != nil { panic(fmt.Errorf("cannot set credential at %s: %s", "default", err)) } } registryProvider = registry.NewRegistryProvider(rs, nil, cp) } return registryProvider }
func getGithubCredential() *common.RegistryCredential { *apitoken = strings.TrimSpace(*apitoken) if *apitoken == "" { *apitoken = strings.TrimSpace(os.Getenv("GITHUB_API_TOKEN")) } if *apitoken != "" { return &common.RegistryCredential{ APIToken: common.APITokenCredential(*apitoken), } } *username = strings.TrimSpace(*username) if *username == "" { *username = strings.TrimSpace(os.Getenv("GITHUB_USERNAME")) } if *username != "" { *password = strings.TrimSpace(*password) if *password == "" { *password = strings.TrimSpace(os.Getenv("GITHUB_PASSWORD")) } return &common.RegistryCredential{ BasicAuth: common.BasicAuthCredential{ Username: *username, Password: *password, }, } } return nil }
func getCredential() *common.RegistryCredential { *apitoken = strings.TrimSpace(*apitoken) if *apitoken == "" { *apitoken = strings.TrimSpace(os.Getenv("GITHUB_API_TOKEN")) } if *apitoken != "" { return &common.RegistryCredential{ APIToken: common.APITokenCredential(*apitoken), } } *username = strings.TrimSpace(*username) if *username == "" { *username = strings.TrimSpace(os.Getenv("GITHUB_USERNAME")) } if *username != "" { *password = strings.TrimSpace(*password) if *password == "" { *password = strings.TrimSpace(os.Getenv("GITHUB_PASSWORD")) } return &common.RegistryCredential{ BasicAuth: common.BasicAuthCredential{ Username: *username, Password: *password, }, } } if *serviceaccount != "" { b, err := ioutil.ReadFile(*serviceaccount) if err != nil { log.Fatalf("Unable to read service account file: %v", err) } return &common.RegistryCredential{ ServiceAccount: common.JWTTokenCredential(string(b)), } } return nil }