mirror of
https://github.com/niusmallnan/steve.git
synced 2025-07-18 16:41:13 +00:00
Add view/update links for resource that go to k8s proxy
This commit is contained in:
parent
25fbba9803
commit
f4898c6187
21
pkg/resources/formatter.go
Normal file
21
pkg/resources/formatter.go
Normal 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
|
||||||
|
}
|
||||||
|
}
|
@ -3,9 +3,8 @@ package schemas
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/rancher/naok/pkg/attributes"
|
|
||||||
|
|
||||||
"github.com/rancher/naok/pkg/accesscontrol"
|
"github.com/rancher/naok/pkg/accesscontrol"
|
||||||
|
"github.com/rancher/naok/pkg/attributes"
|
||||||
"github.com/rancher/norman/pkg/api/builtin"
|
"github.com/rancher/norman/pkg/api/builtin"
|
||||||
"github.com/rancher/norman/pkg/types"
|
"github.com/rancher/norman/pkg/types"
|
||||||
)
|
)
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
openapi_v2 "github.com/googleapis/gnostic/OpenAPIv2"
|
openapi_v2 "github.com/googleapis/gnostic/OpenAPIv2"
|
||||||
"github.com/rancher/naok/pkg/accesscontrol"
|
"github.com/rancher/naok/pkg/accesscontrol"
|
||||||
"github.com/rancher/naok/pkg/attributes"
|
"github.com/rancher/naok/pkg/attributes"
|
||||||
|
"github.com/rancher/naok/pkg/resources"
|
||||||
"github.com/rancher/norman/pkg/store/proxy"
|
"github.com/rancher/norman/pkg/store/proxy"
|
||||||
"github.com/rancher/norman/pkg/types"
|
"github.com/rancher/norman/pkg/types"
|
||||||
"github.com/rancher/norman/pkg/types/convert"
|
"github.com/rancher/norman/pkg/types/convert"
|
||||||
@ -32,6 +33,7 @@ type SchemaFactory interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type handler struct {
|
type handler struct {
|
||||||
|
formatter types.Formatter
|
||||||
schemas *schemas
|
schemas *schemas
|
||||||
schemaStore types.Store
|
schemaStore types.Store
|
||||||
client discovery.DiscoveryInterface
|
client discovery.DiscoveryInterface
|
||||||
@ -69,6 +71,7 @@ func Register(ctx context.Context, clientGetter proxy.ClientGetter, discovery di
|
|||||||
apiService v1.APIServiceController) SchemaFactory {
|
apiService v1.APIServiceController) SchemaFactory {
|
||||||
|
|
||||||
h := &handler{
|
h := &handler{
|
||||||
|
formatter: resources.Formatter,
|
||||||
client: discovery,
|
client: discovery,
|
||||||
schemas: &schemas{},
|
schemas: &schemas{},
|
||||||
schemaStore: proxy.NewProxyStore(clientGetter),
|
schemaStore: proxy.NewProxyStore(clientGetter),
|
||||||
@ -182,6 +185,7 @@ func (h *handler) refresh(gv schema.GroupVersion, resources *metav1.APIResourceL
|
|||||||
schema.PluralName = resource.Name
|
schema.PluralName = resource.Name
|
||||||
attributes.SetAPIResource(schema, resource)
|
attributes.SetAPIResource(schema, resource)
|
||||||
schema.Store = h.schemaStore
|
schema.Store = h.schemaStore
|
||||||
|
schema.Formatter = h.formatter
|
||||||
|
|
||||||
h.schemas.schemas[schema.ID] = schema
|
h.schemas.schemas[schema.ID] = schema
|
||||||
h.schemas.gvkToName[gvk] = schema.ID
|
h.schemas.gvkToName[gvk] = schema.ID
|
||||||
|
Loading…
Reference in New Issue
Block a user