mirror of
https://github.com/rancher/steve.git
synced 2025-09-04 17:01:16 +00:00
This reverts commit 542c471584
.
This commit is contained in:
committed by
GitHub
parent
542c471584
commit
8cd7bd0a8f
@@ -121,22 +121,15 @@ func formatter(summarycache common.SummaryCache, asl accesscontrol.AccessSetLook
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hasGet := accessSet.Grants("get", gvr.GroupResource(), resource.APIObject.Namespace(), resource.APIObject.Name())
|
|
||||||
hasUpdate := accessSet.Grants("update", gvr.GroupResource(), resource.APIObject.Namespace(), resource.APIObject.Name())
|
hasUpdate := accessSet.Grants("update", gvr.GroupResource(), resource.APIObject.Namespace(), resource.APIObject.Name())
|
||||||
hasDelete := accessSet.Grants("delete", gvr.GroupResource(), resource.APIObject.Namespace(), resource.APIObject.Name())
|
hasDelete := accessSet.Grants("delete", gvr.GroupResource(), resource.APIObject.Namespace(), resource.APIObject.Name())
|
||||||
hasPatch := accessSet.Grants("patch", gvr.GroupResource(), resource.APIObject.Namespace(), resource.APIObject.Name())
|
hasPatch := accessSet.Grants("patch", gvr.GroupResource(), resource.APIObject.Namespace(), resource.APIObject.Name())
|
||||||
|
|
||||||
selfLink := selfLink(gvr, meta)
|
selfLink := selfLink(gvr, meta)
|
||||||
|
|
||||||
u := request.URLBuilder.RelativeToRoot(selfLink)
|
u := request.URLBuilder.RelativeToRoot(selfLink)
|
||||||
resource.Links["view"] = u
|
resource.Links["view"] = u
|
||||||
|
|
||||||
if hasGet {
|
|
||||||
if attributes.DisallowMethods(resource.Schema)[http.MethodGet] {
|
|
||||||
resource.Links["view"] = "blocked"
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
delete(resource.Links, "view")
|
|
||||||
}
|
|
||||||
if hasUpdate {
|
if hasUpdate {
|
||||||
if attributes.DisallowMethods(resource.Schema)[http.MethodPut] {
|
if attributes.DisallowMethods(resource.Schema)[http.MethodPut] {
|
||||||
resource.Links["update"] = "blocked"
|
resource.Links["update"] = "blocked"
|
||||||
|
@@ -648,75 +648,6 @@ func Test_formatterLinks(t *testing.T) {
|
|||||||
currentLinks map[string]string
|
currentLinks map[string]string
|
||||||
wantLinks map[string]string
|
wantLinks map[string]string
|
||||||
}{
|
}{
|
||||||
{
|
|
||||||
name: "get permission granted",
|
|
||||||
hasUser: true,
|
|
||||||
permissions: &permissions{
|
|
||||||
hasGet: true,
|
|
||||||
},
|
|
||||||
schema: &types.APISchema{
|
|
||||||
Schema: &schemas.Schema{
|
|
||||||
ID: "example",
|
|
||||||
Attributes: map[string]interface{}{
|
|
||||||
"group": "",
|
|
||||||
"version": "v1",
|
|
||||||
"resource": "pods",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
apiObject: types.APIObject{
|
|
||||||
ID: "example",
|
|
||||||
Object: &v1.Pod{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Name: "example-pod",
|
|
||||||
Namespace: "example-ns",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
currentLinks: map[string]string{
|
|
||||||
"default": "defaultVal",
|
|
||||||
},
|
|
||||||
wantLinks: map[string]string{
|
|
||||||
"default": "defaultVal",
|
|
||||||
"view": "/api/v1/namespaces/example-ns/pods/example-pod",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "get permission granted, but disallowed in schema",
|
|
||||||
hasUser: true,
|
|
||||||
permissions: &permissions{
|
|
||||||
hasGet: true,
|
|
||||||
},
|
|
||||||
schema: &types.APISchema{
|
|
||||||
Schema: &schemas.Schema{
|
|
||||||
ID: "example",
|
|
||||||
Attributes: map[string]interface{}{
|
|
||||||
"group": "",
|
|
||||||
"version": "v1",
|
|
||||||
"resource": "pods",
|
|
||||||
"disallowMethods": map[string]bool{
|
|
||||||
http.MethodGet: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
apiObject: types.APIObject{
|
|
||||||
ID: "example",
|
|
||||||
Object: &v1.Pod{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Name: "example-pod",
|
|
||||||
Namespace: "example-ns",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
currentLinks: map[string]string{
|
|
||||||
"default": "defaultVal",
|
|
||||||
},
|
|
||||||
wantLinks: map[string]string{
|
|
||||||
"default": "defaultVal",
|
|
||||||
"view": "blocked",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "no schema",
|
name: "no schema",
|
||||||
currentLinks: map[string]string{
|
currentLinks: map[string]string{
|
||||||
@@ -853,6 +784,7 @@ func Test_formatterLinks(t *testing.T) {
|
|||||||
},
|
},
|
||||||
wantLinks: map[string]string{
|
wantLinks: map[string]string{
|
||||||
"default": "defaultVal",
|
"default": "defaultVal",
|
||||||
|
"view": "/api/v1/namespaces/example-ns/pods/example-pod",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -888,6 +820,7 @@ func Test_formatterLinks(t *testing.T) {
|
|||||||
wantLinks: map[string]string{
|
wantLinks: map[string]string{
|
||||||
"default": "defaultVal",
|
"default": "defaultVal",
|
||||||
"update": "../v1/namespaces/example-ns/pods/example-pod",
|
"update": "../v1/namespaces/example-ns/pods/example-pod",
|
||||||
|
"view": "/api/v1/namespaces/example-ns/pods/example-pod",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -923,6 +856,7 @@ func Test_formatterLinks(t *testing.T) {
|
|||||||
wantLinks: map[string]string{
|
wantLinks: map[string]string{
|
||||||
"default": "defaultVal",
|
"default": "defaultVal",
|
||||||
"remove": "../v1/namespaces/example-ns/pods/example-pod",
|
"remove": "../v1/namespaces/example-ns/pods/example-pod",
|
||||||
|
"view": "/api/v1/namespaces/example-ns/pods/example-pod",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -960,6 +894,7 @@ func Test_formatterLinks(t *testing.T) {
|
|||||||
"default": "defaultVal",
|
"default": "defaultVal",
|
||||||
"update": "../v1/namespaces/example-ns/pods/example-pod",
|
"update": "../v1/namespaces/example-ns/pods/example-pod",
|
||||||
"remove": "../v1/namespaces/example-ns/pods/example-pod",
|
"remove": "../v1/namespaces/example-ns/pods/example-pod",
|
||||||
|
"view": "/api/v1/namespaces/example-ns/pods/example-pod",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -1001,6 +936,7 @@ func Test_formatterLinks(t *testing.T) {
|
|||||||
"default": "defaultVal",
|
"default": "defaultVal",
|
||||||
"update": "blocked",
|
"update": "blocked",
|
||||||
"remove": "blocked",
|
"remove": "blocked",
|
||||||
|
"view": "/api/v1/namespaces/example-ns/pods/example-pod",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -1036,6 +972,7 @@ func Test_formatterLinks(t *testing.T) {
|
|||||||
wantLinks: map[string]string{
|
wantLinks: map[string]string{
|
||||||
"default": "defaultVal",
|
"default": "defaultVal",
|
||||||
"patch": "/v1/apps.deployments/example-ns/example-deployment",
|
"patch": "/v1/apps.deployments/example-ns/example-deployment",
|
||||||
|
"view": "/apis/apps/v1/namespaces/example-ns/deployments/example-deployment",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -1074,6 +1011,7 @@ func Test_formatterLinks(t *testing.T) {
|
|||||||
wantLinks: map[string]string{
|
wantLinks: map[string]string{
|
||||||
"default": "defaultVal",
|
"default": "defaultVal",
|
||||||
"patch": "blocked",
|
"patch": "blocked",
|
||||||
|
"view": "/apis/apps/v1/namespaces/example-ns/deployments/example-deployment",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -1093,12 +1031,6 @@ func Test_formatterLinks(t *testing.T) {
|
|||||||
meta, err := meta.Accessor(test.apiObject.Object)
|
meta, err := meta.Accessor(test.apiObject.Object)
|
||||||
accessSet := accesscontrol.AccessSet{}
|
accessSet := accesscontrol.AccessSet{}
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
if test.permissions.hasGet {
|
|
||||||
accessSet.Add("get", gvr.GroupResource(), accesscontrol.Access{
|
|
||||||
Namespace: meta.GetNamespace(),
|
|
||||||
ResourceName: meta.GetName(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if test.permissions.hasUpdate {
|
if test.permissions.hasUpdate {
|
||||||
accessSet.Add("update", gvr.GroupResource(), accesscontrol.Access{
|
accessSet.Add("update", gvr.GroupResource(), accesscontrol.Access{
|
||||||
Namespace: meta.GetNamespace(),
|
Namespace: meta.GetNamespace(),
|
||||||
|
Reference in New Issue
Block a user