1
0
mirror of https://github.com/rancher/steve.git synced 2025-10-23 08:18:37 +00:00
Files
steve/pkg/server/resources/common/formatter.go

36 lines
796 B
Go
Raw Normal View History

2019-08-13 16:36:03 -07:00
package common
import (
2020-01-30 22:37:59 -07:00
"github.com/rancher/steve/pkg/schema"
"github.com/rancher/steve/pkg/schemaserver/types"
"github.com/rancher/steve/pkg/server/store/proxy"
"k8s.io/apimachinery/pkg/api/meta"
)
2020-01-30 22:37:59 -07:00
func DefaultTemplate(clientGetter proxy.ClientGetter) schema.Template {
return schema.Template{
2019-08-13 16:36:03 -07:00
Store: proxy.NewProxyStore(clientGetter),
Formatter: Formatter,
2019-08-14 11:08:34 -07:00
Mapper: &DefaultColumns{},
2020-01-30 22:37:59 -07:00
}
2019-08-13 16:36:03 -07:00
}
func Formatter(request *types.APIRequest, resource *types.RawResource) {
2020-01-30 22:37:59 -07:00
meta, err := meta.Accessor(resource.APIObject.Object)
if err != nil {
return
}
selfLink := meta.GetSelfLink()
if selfLink == "" {
return
}
u := request.URLBuilder.RelativeToRoot(selfLink)
resource.Links["view"] = u
2020-01-30 22:01:21 -07:00
if _, ok := resource.Links["update"]; !ok {
resource.Links["update"] = u
}
}