1
0
mirror of https://github.com/rancher/steve.git synced 2025-05-04 22:16:52 +00:00
steve/pkg/schema/defaultmapper.go

40 lines
760 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:37:59 +00:00
"github.com/rancher/steve/pkg/schemaserver/types"
"github.com/rancher/wrangler/pkg/data"
"github.com/rancher/wrangler/pkg/schemas"
"github.com/rancher/wrangler/pkg/schemas/mappers"
2019-08-04 17:41:32 +00:00
)
2020-01-31 05:37:59 +00:00
func newDefaultMapper() schemas.Mapper {
2019-08-04 17:41:32 +00:00
return &defaultMapper{}
}
type defaultMapper struct {
2020-01-31 05:37:59 +00:00
mappers.EmptyMapper
2019-08-04 17:41:32 +00:00
}
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)
}
}