1
0
mirror of https://github.com/rancher/types.git synced 2025-04-29 19:03:21 +00:00
types/mapper/namespace.go

43 lines
870 B
Go
Raw Permalink Normal View History

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)
}