1
0
mirror of https://github.com/rancher/steve.git synced 2025-07-11 05:43:24 +00:00
steve/pkg/server/mapper.go

33 lines
672 B
Go
Raw Normal View History

2019-08-04 17:41:32 +00:00
package server
import (
"fmt"
"github.com/rancher/norman/pkg/types"
2019-08-07 21:59:00 +00:00
"github.com/rancher/norman/pkg/types/convert"
2019-08-04 17:41:32 +00:00
"github.com/rancher/norman/pkg/types/values"
)
func newDefaultMapper() types.Mapper {
return &defaultMapper{}
}
type defaultMapper struct {
types.EmptyMapper
}
func (d *defaultMapper) FromInternal(data map[string]interface{}) {
if _, ok := data["id"]; ok || data == nil {
return
}
2019-08-07 21:59:00 +00:00
name := convert.ToString(values.GetValueN(data, "metadata", "name"))
namespace := convert.ToString(values.GetValueN(data, "metadata", "namespace"))
2019-08-04 17:41:32 +00:00
if namespace == "" {
data["id"] = name
} else {
data["id"] = fmt.Sprintf("%s/%s", namespace, name)
}
}