github.com/rancher/types@v0.0.0-20220328215343-4370ff10ecd5/mapper/namespace.go (about)

     1  package mapper
     2  
     3  import (
     4  	"github.com/rancher/norman/types"
     5  	"github.com/rancher/norman/types/mapper"
     6  )
     7  
     8  type NamespaceIDMapper struct {
     9  	Move *mapper.Move
    10  }
    11  
    12  func (n *NamespaceIDMapper) FromInternal(data map[string]interface{}) {
    13  	if n.Move != nil {
    14  		n.Move.FromInternal(data)
    15  	}
    16  }
    17  
    18  func (n *NamespaceIDMapper) ToInternal(data map[string]interface{}) error {
    19  	if n.Move != nil {
    20  		return n.Move.ToInternal(data)
    21  	}
    22  	return nil
    23  }
    24  
    25  func (n *NamespaceIDMapper) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
    26  	field, ok := schema.ResourceFields["namespace"]
    27  	if !ok {
    28  		return nil
    29  	}
    30  
    31  	field.Type = "reference[/v3/clusters/schemas/namespace]"
    32  	field.Required = true
    33  	field.Update = false
    34  	schema.ResourceFields["namespace"] = field
    35  
    36  	n.Move = &mapper.Move{
    37  		From: "namespace",
    38  		To:   "namespaceId",
    39  	}
    40  
    41  	return n.Move.ModifySchema(schema, schemas)
    42  }