1
0
mirror of https://github.com/rancher/types.git synced 2025-07-19 07:46:25 +00:00

credential type

This commit is contained in:
kinarashah 2018-12-07 11:43:28 -08:00 committed by Alena Prokharchyk
parent 129266c375
commit b5f3a23193
3 changed files with 105 additions and 5 deletions

View File

@ -40,10 +40,11 @@ type NodeTemplateCondition struct {
}
type NodeTemplateSpec struct {
DisplayName string `json:"displayName"`
Description string `json:"description"`
Driver string `json:"driver" norman:"nocreate,noupdate"`
NodeCommonParams `json:",inline"`
DisplayName string `json:"displayName"`
Description string `json:"description"`
Driver string `json:"driver" norman:"nocreate,noupdate"`
CloudCredentialName string `json:"cloudCredentialName" norman:"type=reference[cloudCredential]"`
NodeCommonParams `json:",inline"`
}
type Node struct {
@ -292,3 +293,11 @@ type NodeDrainInput struct {
// Time to wait (in seconds) before giving up for one try
Timeout int `json:"timeout" norman:"min=1,max=10800,default=60"`
}
type CloudCredential struct {
types.Namespaced
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
}

View File

@ -40,7 +40,9 @@ var (
Init(globalDNSTypes).
Init(kontainerTypes).
Init(etcdBackupTypes).
Init(monitorTypes)
Init(monitorTypes).
Init(credTypes).
Init(mgmtSecretTypes)
TokenSchemas = factory.Schemas(&Version).
Init(tokens)
@ -55,6 +57,24 @@ func schemaTypes(schemas *types.Schemas) *types.Schemas {
MustImport(&Version, v3.DynamicSchema{})
}
func credTypes(schemas *types.Schemas) *types.Schemas {
return schemas.
AddMapperForType(&Version, v3.CloudCredential{},
&mapper.CredentialMapper{},
&m.Move{From: "name", To: "id"},
&m.Drop{Field: "namespaceId"}).
MustImport(&Version, v3.CloudCredential{})
}
func mgmtSecretTypes(schemas *types.Schemas) *types.Schemas {
return schemas.MustImportAndCustomize(&Version, v1.Secret{}, func(schema *types.Schema) {
schema.ID = "managementSecret"
schema.PluralName = "managementSecrets"
schema.CodeName = "ManagementSecret"
schema.CodeNamePlural = "ManagementSecrets"
})
}
func catalogTypes(schemas *types.Schemas) *types.Schemas {
return schemas.
AddMapperForType(&Version, v3.Catalog{},

View File

@ -0,0 +1,71 @@
package mapper
import (
"fmt"
"strings"
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
"github.com/rancher/norman/types/values"
)
type CredentialMapper struct {
}
func (s CredentialMapper) FromInternal(data map[string]interface{}) {
formatData(data)
delete(data, "data")
}
func (s CredentialMapper) ToInternal(data map[string]interface{}) error {
updateData(data)
return nil
}
func (s CredentialMapper) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
return nil
}
func updateData(data map[string]interface{}) {
stringData := map[string]string{}
for key, val := range data {
if val == nil {
continue
}
if strings.HasSuffix(key, "Config") {
for key2, val2 := range convert.ToMapInterface(val) {
stringData[fmt.Sprintf("%s-%s", key, key2)] = convert.ToString(val2)
}
values.PutValue(data, stringData, "stringData")
delete(data, key)
return
}
}
}
func formatData(data map[string]interface{}) {
secretData := convert.ToMapInterface(data["data"])
getKey := func(data map[string]interface{}) string {
for key := range data {
splitKeys := strings.Split(key, "-")
if len(splitKeys) != 2 {
continue
}
if strings.HasSuffix(splitKeys[0], "Config") {
return splitKeys[0]
}
}
return ""
}
config := getKey(secretData)
if config == "" {
return
}
for key, val := range secretData {
splitKeys := strings.Split(key, "-")
if len(splitKeys) != 2 {
continue
}
values.PutValue(data, convert.ToString(val), config, splitKeys[1])
}
}