From 6a10d67933fa033e511ed4a15cbe67c2b7eaaacf Mon Sep 17 00:00:00 2001 From: Jan Moxter Date: Thu, 7 Oct 2021 10:57:47 -0500 Subject: [PATCH 1/2] fix: read relation tuples must require namspace query parameter only --- .../read/get_relation_tuples_parameters.go | 50 ++++++++++++------- internal/relationtuple/read_server.go | 42 +++++++++++++++- spec/api.json | 28 +++++------ 3 files changed, 85 insertions(+), 35 deletions(-) diff --git a/internal/httpclient/client/read/get_relation_tuples_parameters.go b/internal/httpclient/client/read/get_relation_tuples_parameters.go index e719e1ad9..011f8fc62 100644 --- a/internal/httpclient/client/read/get_relation_tuples_parameters.go +++ b/internal/httpclient/client/read/get_relation_tuples_parameters.go @@ -70,7 +70,7 @@ type GetRelationTuplesParams struct { Object of the Relation Tuple */ - Object string + Object *string // PageSize. // @@ -84,7 +84,7 @@ type GetRelationTuplesParams struct { Relation of the Relation Tuple */ - Relation string + Relation *string /* SubjectID. @@ -175,13 +175,13 @@ func (o *GetRelationTuplesParams) SetNamespace(namespace string) { } // WithObject adds the object to the get relation tuples params -func (o *GetRelationTuplesParams) WithObject(object string) *GetRelationTuplesParams { +func (o *GetRelationTuplesParams) WithObject(object *string) *GetRelationTuplesParams { o.SetObject(object) return o } // SetObject adds the object to the get relation tuples params -func (o *GetRelationTuplesParams) SetObject(object string) { +func (o *GetRelationTuplesParams) SetObject(object *string) { o.Object = object } @@ -208,13 +208,13 @@ func (o *GetRelationTuplesParams) SetPageToken(pageToken *string) { } // WithRelation adds the relation to the get relation tuples params -func (o *GetRelationTuplesParams) WithRelation(relation string) *GetRelationTuplesParams { +func (o *GetRelationTuplesParams) WithRelation(relation *string) *GetRelationTuplesParams { o.SetRelation(relation) return o } // SetRelation adds the relation to the get relation tuples params -func (o *GetRelationTuplesParams) SetRelation(relation string) { +func (o *GetRelationTuplesParams) SetRelation(relation *string) { o.Relation = relation } @@ -280,13 +280,20 @@ func (o *GetRelationTuplesParams) WriteToRequest(r runtime.ClientRequest, reg st } } - // query param object - qrObject := o.Object - qObject := qrObject - if qObject != "" { + if o.Object != nil { - if err := r.SetQueryParam("object", qObject); err != nil { - return err + // query param object + var qrObject string + + if o.Object != nil { + qrObject = *o.Object + } + qObject := qrObject + if qObject != "" { + + if err := r.SetQueryParam("object", qObject); err != nil { + return err + } } } @@ -324,13 +331,20 @@ func (o *GetRelationTuplesParams) WriteToRequest(r runtime.ClientRequest, reg st } } - // query param relation - qrRelation := o.Relation - qRelation := qrRelation - if qRelation != "" { + if o.Relation != nil { - if err := r.SetQueryParam("relation", qRelation); err != nil { - return err + // query param relation + var qrRelation string + + if o.Relation != nil { + qrRelation = *o.Relation + } + qRelation := qrRelation + if qRelation != "" { + + if err := r.SetQueryParam("relation", qRelation); err != nil { + return err + } } } diff --git a/internal/relationtuple/read_server.go b/internal/relationtuple/read_server.go index cd3e9dbd7..70783fff0 100644 --- a/internal/relationtuple/read_server.go +++ b/internal/relationtuple/read_server.go @@ -50,8 +50,46 @@ func (h *handler) ListRelationTuples(ctx context.Context, req *acl.ListRelationT // swagger:parameters getRelationTuples // nolint:deadcode,unused type getRelationsParams struct { - // swagger:allOf - queryRelationTuple + // Namespace of the Relation Tuple + // + // in: query + // required: true + Namespace string `json:"namespace"` + + // Object of the Relation Tuple + // + // in: query + Object string `json:"object"` + + // Relation of the Relation Tuple + // + // in: query + Relation string `json:"relation"` + + // SubjectID of the Relation Tuple + // + // in: query + // Either subject_set.* or subject_id are required. + SubjectID string `json:"subject_id"` + + // Namespace of the Subject Set + // + // in: query + // Either subject_set.* or subject_id are required. + SNamespace string `json:"subject_set.namespace"` + + // Object of the Subject Set + // + // in: query + // Either subject_set.* or subject_id are required. + SObject string `json:"subject_set.object"` + + // Relation of the Subject Set + // + // in: query + // Either subject_set.* or subject_id are required. + SRelation string `json:"subject_set.relation"` + // swagger:allOf x.PaginationOptions } diff --git a/spec/api.json b/spec/api.json index 73be5924a..a9a008441 100755 --- a/spec/api.json +++ b/spec/api.json @@ -521,6 +521,17 @@ "summary": "Query relation tuples", "operationId": "getRelationTuples", "parameters": [ + { + "type": "string", + "name": "page_token", + "in": "query" + }, + { + "type": "integer", + "format": "int64", + "name": "page_size", + "in": "query" + }, { "type": "string", "description": "Namespace of the Relation Tuple", @@ -532,15 +543,13 @@ "type": "string", "description": "Object of the Relation Tuple", "name": "object", - "in": "query", - "required": true + "in": "query" }, { "type": "string", "description": "Relation of the Relation Tuple", "name": "relation", - "in": "query", - "required": true + "in": "query" }, { "type": "string", @@ -565,17 +574,6 @@ "description": "Relation of the Subject Set", "name": "subject_set.relation", "in": "query" - }, - { - "type": "string", - "name": "page_token", - "in": "query" - }, - { - "type": "integer", - "format": "int64", - "name": "page_size", - "in": "query" } ], "responses": { From cafc02c4bdda382dfecb5b3cd8dc06dd9b2962ec Mon Sep 17 00:00:00 2001 From: Jan Moxter Date: Thu, 7 Oct 2021 12:20:13 -0500 Subject: [PATCH 2/2] Update Test to use pointer --- internal/e2e/sdk_client_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/e2e/sdk_client_test.go b/internal/e2e/sdk_client_test.go index 3d2850ccc..a73758091 100644 --- a/internal/e2e/sdk_client_test.go +++ b/internal/e2e/sdk_client_test.go @@ -97,10 +97,10 @@ func (c *sdkClient) deleteTuple(t require.TestingT, r *relationtuple.InternalRel func compileParams(q *relationtuple.RelationQuery, opts []x.PaginationOptionSetter) *read.GetRelationTuplesParams { params := read.NewGetRelationTuplesParams().WithNamespace(q.Namespace) if q.Relation != "" { - params = params.WithRelation(q.Relation) + params = params.WithRelation(&q.Relation) } if q.Object != "" { - params = params.WithObject(q.Object) + params = params.WithObject(&q.Object) } if q.SubjectID != nil { params = params.WithSubjectID(q.SubjectID)