2019-08-13 23:36:03 +00:00
|
|
|
package common
|
2019-08-08 05:43:10 +00:00
|
|
|
|
|
|
|
import (
|
2019-09-11 21:05:00 +00:00
|
|
|
"github.com/rancher/steve/pkg/resources/schema"
|
2019-08-13 23:36:03 +00:00
|
|
|
"github.com/rancher/norman/pkg/store/proxy"
|
2019-08-08 05:43:10 +00:00
|
|
|
"github.com/rancher/norman/pkg/types"
|
|
|
|
"github.com/rancher/norman/pkg/types/convert"
|
|
|
|
"github.com/rancher/norman/pkg/types/values"
|
|
|
|
)
|
|
|
|
|
2019-08-13 23:36:03 +00:00
|
|
|
func Register(collection *schema.Collection, clientGetter proxy.ClientGetter) {
|
|
|
|
collection.AddTemplate(&schema.Template{
|
|
|
|
Store: proxy.NewProxyStore(clientGetter),
|
|
|
|
Formatter: Formatter,
|
2019-08-14 18:08:34 +00:00
|
|
|
Mapper: &DefaultColumns{},
|
2019-08-13 23:36:03 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-08-08 05:43:10 +00:00
|
|
|
func Formatter(request *types.APIRequest, resource *types.RawResource) {
|
|
|
|
selfLink := convert.ToString(values.GetValueN(resource.Values, "metadata", "selfLink"))
|
|
|
|
if selfLink == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
u := request.URLBuilder.RelativeToRoot(selfLink)
|
|
|
|
resource.Links["view"] = u
|
|
|
|
|
|
|
|
if _, ok := resource.Links["update"]; ok {
|
|
|
|
resource.Links["update"] = u
|
|
|
|
}
|
|
|
|
}
|