From 5f653d2d37a9ee9bffa7e6abbf2abf33be4b0ba5 Mon Sep 17 00:00:00 2001 From: Prachi Damle Date: Thu, 5 Sep 2019 11:34:45 -0700 Subject: [PATCH] DockerCredential support auth and email --- .../v3/schema/registry_credential.go | 31 +++++++++++++++---- .../v3/schema/schema_secrets.go | 2 +- apis/project.cattle.io/v3/types.go | 1 + 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/apis/project.cattle.io/v3/schema/registry_credential.go b/apis/project.cattle.io/v3/schema/registry_credential.go index fa683bc7..fa149b9a 100644 --- a/apis/project.cattle.io/v3/schema/registry_credential.go +++ b/apis/project.cattle.io/v3/schema/registry_credential.go @@ -2,6 +2,7 @@ package schema import ( "encoding/base64" + "fmt" "github.com/rancher/norman/types" "github.com/rancher/norman/types/convert" @@ -18,17 +19,35 @@ func (e RegistryCredentialMapper) ToInternal(data map[string]interface{}) error return nil } - auth := convert.ToString(data["auth"]) - username := convert.ToString(data["username"]) - password := convert.ToString(data["password"]) + if data["kind"] != "dockerCredential" { + return nil + } - if auth == "" && username != "" && password != "" { - data["auth"] = base64.StdEncoding.EncodeToString([]byte(username + ":" + password)) + addAuthInfo(data) + + return nil +} + +func addAuthInfo(data map[string]interface{}) error { + + registryMap := convert.ToMapInterface(data["registries"]) + for _, regCred := range registryMap { + regCredMap := convert.ToMapInterface(regCred) + + username := convert.ToString(regCredMap["username"]) + if username == "" { + continue + } + password := convert.ToString(regCredMap["password"]) + if password == "" { + continue + } + auth := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", username, password))) + regCredMap["auth"] = auth } return nil } - func (e RegistryCredentialMapper) ModifySchema(schema *types.Schema, schemas *types.Schemas) error { return nil } diff --git a/apis/project.cattle.io/v3/schema/schema_secrets.go b/apis/project.cattle.io/v3/schema/schema_secrets.go index 12818915..f3f2ea64 100644 --- a/apis/project.cattle.io/v3/schema/schema_secrets.go +++ b/apis/project.cattle.io/v3/schema/schema_secrets.go @@ -206,7 +206,7 @@ func secretTypes(schemas *types.Schemas) *types.Schemas { }, }, ). - AddMapperForType(&Version, v3.RegistryCredential{}, RegistryCredentialMapper{}). + AddMapperForType(&Version, v1.Secret{}, RegistryCredentialMapper{}). MustImportAndCustomize(&Version, v1.Secret{}, func(schema *types.Schema) { schema.MustCustomizeField("kind", func(f types.Field) types.Field { f.Options = []string{ diff --git a/apis/project.cattle.io/v3/types.go b/apis/project.cattle.io/v3/types.go index 93fe8065..ab23cf6e 100644 --- a/apis/project.cattle.io/v3/types.go +++ b/apis/project.cattle.io/v3/types.go @@ -35,6 +35,7 @@ type RegistryCredential struct { Username string `json:"username"` Password string `json:"password" norman:"writeOnly"` Auth string `json:"auth" norman:"writeOnly"` + Email string `json:"email"` } type Certificate struct {