Add view/update links for resource that go to k8s proxy

This commit is contained in:
Darren Shepherd 2019-08-07 22:43:10 -07:00
parent 25fbba9803
commit f4898c6187
3 changed files with 26 additions and 2 deletions

View File

@ -0,0 +1,21 @@
package resources
import (
"github.com/rancher/norman/pkg/types"
"github.com/rancher/norman/pkg/types/convert"
"github.com/rancher/norman/pkg/types/values"
)
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
}
}

View File

@ -3,9 +3,8 @@ package schemas
import (
"net/http"
"github.com/rancher/naok/pkg/attributes"
"github.com/rancher/naok/pkg/accesscontrol"
"github.com/rancher/naok/pkg/attributes"
"github.com/rancher/norman/pkg/api/builtin"
"github.com/rancher/norman/pkg/types"
)

View File

@ -11,6 +11,7 @@ import (
openapi_v2 "github.com/googleapis/gnostic/OpenAPIv2"
"github.com/rancher/naok/pkg/accesscontrol"
"github.com/rancher/naok/pkg/attributes"
"github.com/rancher/naok/pkg/resources"
"github.com/rancher/norman/pkg/store/proxy"
"github.com/rancher/norman/pkg/types"
"github.com/rancher/norman/pkg/types/convert"
@ -32,6 +33,7 @@ type SchemaFactory interface {
}
type handler struct {
formatter types.Formatter
schemas *schemas
schemaStore types.Store
client discovery.DiscoveryInterface
@ -69,6 +71,7 @@ func Register(ctx context.Context, clientGetter proxy.ClientGetter, discovery di
apiService v1.APIServiceController) SchemaFactory {
h := &handler{
formatter: resources.Formatter,
client: discovery,
schemas: &schemas{},
schemaStore: proxy.NewProxyStore(clientGetter),
@ -182,6 +185,7 @@ func (h *handler) refresh(gv schema.GroupVersion, resources *metav1.APIResourceL
schema.PluralName = resource.Name
attributes.SetAPIResource(schema, resource)
schema.Store = h.schemaStore
schema.Formatter = h.formatter
h.schemas.schemas[schema.ID] = schema
h.schemas.gvkToName[gvk] = schema.ID