mirror of
https://github.com/rancher/types.git
synced 2025-08-15 03:02:59 +00:00
DockerCredential support auth and email
This commit is contained in:
parent
a3256ec667
commit
5f653d2d37
@ -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
|
||||
}
|
||||
|
@ -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{
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user