1
0
mirror of https://github.com/rancher/steve.git synced 2025-06-21 20:47:33 +00:00
steve/pkg/schema/defaultmapper.go

38 lines
654 B
Go
Raw Normal View History

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