1
0
mirror of https://github.com/rancher/steve.git synced 2025-09-04 17:01:16 +00:00
Files
steve/pkg/resources/schema/defaultmapper.go

38 lines
648 B
Go
Raw Normal View History

2019-08-13 16:36:03 -07:00
package schema
2019-08-04 10:41:32 -07:00
import (
"fmt"
2019-08-14 11:08:34 -07:00
"github.com/rancher/norman/pkg/data"
2019-08-04 10:41:32 -07:00
"github.com/rancher/norman/pkg/types"
)
func newDefaultMapper() types.Mapper {
return &defaultMapper{}
}
type defaultMapper struct {
types.EmptyMapper
}
2019-08-14 11:08:34 -07:00
func (d *defaultMapper) FromInternal(data data.Object) {
2019-08-13 16:36:03 -07:00
if data["kind"] != "" && data["apiVersion"] != "" {
if t, ok := data["type"]; ok && data != nil {
data["_type"] = t
}
2019-08-08 16:39:37 -07:00
}
2019-08-04 10:41:32 -07:00
if _, ok := data["id"]; ok || data == nil {
return
}
2019-08-14 11:08:34 -07:00
name := types.Name(data)
namespace := types.Namespace(data)
2019-08-04 10:41:32 -07:00
if namespace == "" {
data["id"] = name
} else {
data["id"] = fmt.Sprintf("%s/%s", namespace, name)
}
}