mirror of
https://github.com/rancher/steve.git
synced 2025-09-18 00:08:17 +00:00
Vendor
This commit is contained in:
37
pkg/schema/defaultmapper.go
Normal file
37
pkg/schema/defaultmapper.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/rancher/norman/v2/pkg/data"
|
||||
"github.com/rancher/norman/v2/pkg/types"
|
||||
)
|
||||
|
||||
func newDefaultMapper() types.Mapper {
|
||||
return &defaultMapper{}
|
||||
}
|
||||
|
||||
type defaultMapper struct {
|
||||
types.EmptyMapper
|
||||
}
|
||||
|
||||
func (d *defaultMapper) FromInternal(data data.Object) {
|
||||
if data["kind"] != "" && data["apiVersion"] != "" {
|
||||
if t, ok := data["type"]; ok && data != nil {
|
||||
data["_type"] = t
|
||||
}
|
||||
}
|
||||
|
||||
if _, ok := data["id"]; ok || data == nil {
|
||||
return
|
||||
}
|
||||
|
||||
name := types.Name(data)
|
||||
namespace := types.Namespace(data)
|
||||
|
||||
if namespace == "" {
|
||||
data["id"] = name
|
||||
} else {
|
||||
data["id"] = fmt.Sprintf("%s/%s", namespace, name)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user