1
0
mirror of https://github.com/rancher/types.git synced 2025-04-30 03:13:19 +00:00
types/mapper/creator.go

36 lines
775 B
Go
Raw Permalink Normal View History

2017-12-28 16:52:40 +00:00
package mapper
import (
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/mapper"
)
type Creator struct {
m types.Mapper
}
func (c *Creator) FromInternal(data map[string]interface{}) {
if c.m != nil {
c.m.FromInternal(data)
}
}
2018-06-05 04:44:54 +00:00
func (c *Creator) ToInternal(data map[string]interface{}) error {
2017-12-28 16:52:40 +00:00
if c.m != nil {
2018-06-05 04:44:54 +00:00
return c.m.ToInternal(data)
2017-12-28 16:52:40 +00:00
}
2018-06-05 04:44:54 +00:00
return nil
2017-12-28 16:52:40 +00:00
}
func (c *Creator) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
2018-03-31 10:15:08 +00:00
if schema.CanList(nil) == nil && schema.CanCreate(nil) == nil {
2017-12-28 16:52:40 +00:00
schema.ResourceFields["creatorId"] = types.Field{
2018-02-13 23:46:50 +00:00
Type: "reference[/v3/schemas/user]",
2017-12-29 22:20:33 +00:00
CodeName: "CreatorID",
2017-12-28 16:52:40 +00:00
}
c.m = &mapper.AnnotationField{Field: "creatorId"}
return c.m.ModifySchema(schema, schemas)
}
return nil
}