2017-11-28 21:32:17 +00:00
|
|
|
package mapper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/rancher/norman/types"
|
|
|
|
"github.com/rancher/norman/types/mapper"
|
|
|
|
)
|
|
|
|
|
|
|
|
type NamespaceIDMapper struct {
|
|
|
|
Move *mapper.Move
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *NamespaceIDMapper) FromInternal(data map[string]interface{}) {
|
|
|
|
if n.Move != nil {
|
|
|
|
n.Move.FromInternal(data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-05 04:44:54 +00:00
|
|
|
func (n *NamespaceIDMapper) ToInternal(data map[string]interface{}) error {
|
2017-11-28 21:32:17 +00:00
|
|
|
if n.Move != nil {
|
2018-06-05 04:44:54 +00:00
|
|
|
return n.Move.ToInternal(data)
|
2017-11-28 21:32:17 +00:00
|
|
|
}
|
2018-06-05 04:44:54 +00:00
|
|
|
return nil
|
2017-11-28 21:32:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (n *NamespaceIDMapper) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
|
|
|
|
field, ok := schema.ResourceFields["namespace"]
|
|
|
|
if !ok {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-02-13 23:46:50 +00:00
|
|
|
field.Type = "reference[/v3/clusters/schemas/namespace]"
|
2017-12-28 16:48:10 +00:00
|
|
|
field.Required = true
|
2017-12-28 18:31:33 +00:00
|
|
|
field.Update = false
|
2017-11-28 21:32:17 +00:00
|
|
|
schema.ResourceFields["namespace"] = field
|
|
|
|
|
|
|
|
n.Move = &mapper.Move{
|
|
|
|
From: "namespace",
|
|
|
|
To: "namespaceId",
|
|
|
|
}
|
|
|
|
|
|
|
|
return n.Move.ModifySchema(schema, schemas)
|
|
|
|
}
|