Skip to content

Commit

Permalink
chore: upgrade SDK naming to v1
Browse files Browse the repository at this point in the history
  • Loading branch information
hperl committed Nov 22, 2022
1 parent ef73f05 commit dfb9b45
Show file tree
Hide file tree
Showing 48 changed files with 2,407 additions and 2,152 deletions.
2 changes: 1 addition & 1 deletion cmd/check/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/ory/keto/cmd/client"
)

type checkOutput check.RESTResponse
type checkOutput check.CheckPermissionResponse

func (o *checkOutput) String() string {
if o.Allowed {
Expand Down
8 changes: 4 additions & 4 deletions cmd/relationtuple/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (

func NewCreateCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "create <relation-tuple.json> [<relation-tuple-dir>]",
Short: "Create relation tuples from JSON files",
Long: "Create relation tuples from JSON files.\n" +
"A directory will be traversed and all relation tuples will be created.\n" +
Use: "create <relationships.json> [<relationships-dir>]",
Short: "Create relationships from JSON files",
Long: "Create relationships from JSON files.\n" +
"A directory will be traversed and all relationships will be created.\n" +
"Pass the special filename `-` to read from STD_IN.",
Args: cobra.MinimumNArgs(1),
RunE: transactRelationTuples(rts.RelationTupleDelta_ACTION_INSERT),
Expand Down
6 changes: 3 additions & 3 deletions cmd/relationtuple/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
func NewDeleteCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "delete <relation-tuple.json> [<relation-tuple-dir>]",
Short: "Delete relation tuples defined in JSON files",
Long: "Delete relation tuples defined in the given JSON files.\n" +
"A directory will be traversed and all relation tuples will be deleted.\n" +
Short: "Delete relationships defined in JSON files",
Long: "Delete relationships defined in the given JSON files.\n" +
"A directory will be traversed and all relationships will be deleted.\n" +
"Pass the special filename `-` to read from STD_IN.",
Args: cobra.MinimumNArgs(1),
RunE: transactRelationTuples(rts.RelationTupleDelta_ACTION_DELETE),
Expand Down
6 changes: 3 additions & 3 deletions cmd/relationtuple/delete_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ const (
func NewDeleteAllCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "delete-all",
Short: "Delete ALL relation tuples matching the relation query.",
Long: "Delete all relation tuples matching the relation query.\n" +
Short: "Delete ALL relationships matching the relation query.",
Long: "Delete all relationships matching the relation query.\n" +
"It is recommended to first run the command without the `--force` flag to verify that the operation is safe.",
Args: cobra.ExactArgs(0),
RunE: deleteRelationTuplesFromQuery,
}
registerPackageFlags(cmd.Flags())
registerRelationTupleFlags(cmd.Flags())
cmd.Flags().Bool(FlagForce, false, "Force the deletion of relation tuples")
cmd.Flags().Bool(FlagForce, false, "Force the deletion of relationships")

return cmd
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/relationtuple/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func NewGetCmd() *cobra.Command {

cmd := &cobra.Command{
Use: "get",
Short: "Get relation tuples",
Long: "Get relation tuples matching the given partial tuple.\n" +
Short: "Get relationships",
Long: "Get relationships matching the given partial tuple.\n" +
"Returns paginated results.",
Args: cobra.ExactArgs(0),
RunE: getTuples(&pageSize, &pageToken),
Expand Down
4 changes: 2 additions & 2 deletions cmd/relationtuple/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
func NewParseCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "parse",
Short: "Parse human readable relation tuples",
Long: "Parse human readable relation tuples as used in the documentation.\n" +
Short: "Parse human readable relationships",
Long: "Parse human readable relationships as used in the documentation.\n" +
"Supports various output formats. Especially useful for piping into other commands by using `--format json`.\n" +
"Ignores comments (lines starting with `//`) and blank lines.",
Args: cobra.MinimumNArgs(1),
Expand Down
2 changes: 1 addition & 1 deletion cmd/relationtuple/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
func newRelationCmd() *cobra.Command {
return &cobra.Command{
Use: "relation-tuple",
Short: "Read and manipulate relation tuples",
Short: "Read and manipulate relationships",
}
}

Expand Down
2 changes: 1 addition & 1 deletion contrib/cat-videos-example/up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ keto relation-tuple create contrib/cat-videos-example/relation-tuples

echo "
Created all relation tuples. Now you can use the Keto CLI client to play around:
Created all relationships. Now you can use the Keto CLI client to play around:
export KETO_READ_REMOTE=\"127.0.0.1:4466\"
keto relation-tuple get videos
Expand Down
60 changes: 30 additions & 30 deletions internal/check/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type (

var (
_ rts.CheckServiceServer = (*Handler)(nil)
_ *getCheckRequest = nil
_ *checkPermission = nil
)

func NewHandler(d handlerDependencies) *Handler {
Expand All @@ -61,29 +61,29 @@ func (h *Handler) RegisterReadGRPC(s *grpc.Server) {
rts.RegisterCheckServiceServer(s, h)
}

// RESTResponse represents the response for a check request.
// CheckPermissionResponse represents the response for a check request.
//
// The content of the allowed field is mirrored in the HTTP status code.
//
// swagger:model getCheckResponse
type RESTResponse struct {
// swagger:model checkPermissionResponse
type CheckPermissionResponse struct {
// whether the relation tuple is allowed
//
// required: true
Allowed bool `json:"allowed"`
}

// swagger:parameters getCheck postCheck
type getCheckRequest struct {
// swagger:parameters checkPermission checkPermissionOrError postCheckPermission postCheckPermissionOrError
type checkPermission struct {
// in:query
MaxDepth int `json:"max-depth"`
}

// swagger:route GET /relation-tuples/check/openapi read getCheck
// swagger:route GET /relation-tuples/check/openapi permission checkPermission
//
// # Check a relation tuple
// # Check a permission
//
// To learn how relation tuples and the check works, head over to [the documentation](https://www.ory.sh/docs/keto/concepts/api-overview).
// To learn how relationship tuples and the check works, head over to [the documentation](https://www.ory.sh/docs/keto/concepts/api-overview).
//
// Consumes:
// - application/x-www-form-urlencoded
Expand All @@ -94,7 +94,7 @@ type getCheckRequest struct {
// Schemes: http, https
//
// Responses:
// 200: getCheckResponse
// 200: checkPermissionResponse
// 400: genericError
// 500: genericError
func (h *Handler) getCheckNoStatus(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
Expand All @@ -103,14 +103,14 @@ func (h *Handler) getCheckNoStatus(w http.ResponseWriter, r *http.Request, _ htt
h.d.Writer().WriteError(w, r, err)
return
}
h.d.Writer().Write(w, r, &RESTResponse{Allowed: allowed})
h.d.Writer().Write(w, r, &CheckPermissionResponse{Allowed: allowed})
}

// swagger:route GET /relation-tuples/check read getCheckMirrorStatus
// swagger:route GET /relation-tuples/check permission checkPermissionOrError
//
// # Check a relation tuple
// # Check a permission
//
// To learn how relation tuples and the check works, head over to [the documentation](https://www.ory.sh/docs/keto/concepts/api-overview).
// To learn how relationship tuples and the check works, head over to [the documentation](https://www.ory.sh/docs/keto/concepts/api-overview).
//
// Consumes:
// - application/x-www-form-urlencoded
Expand All @@ -121,9 +121,9 @@ func (h *Handler) getCheckNoStatus(w http.ResponseWriter, r *http.Request, _ htt
// Schemes: http, https
//
// Responses:
// 200: getCheckResponse
// 200: checkPermissionResponse
// 400: genericError
// 403: getCheckResponse
// 403: checkPermissionResponse
// 500: genericError
func (h *Handler) getCheckMirrorStatus(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
allowed, err := h.getCheck(r.Context(), r.URL.Query())
Expand All @@ -133,11 +133,11 @@ func (h *Handler) getCheckMirrorStatus(w http.ResponseWriter, r *http.Request, _
}

if allowed {
h.d.Writer().Write(w, r, &RESTResponse{Allowed: allowed})
h.d.Writer().Write(w, r, &CheckPermissionResponse{Allowed: allowed})
return
}

h.d.Writer().WriteCode(w, r, http.StatusForbidden, &RESTResponse{Allowed: allowed})
h.d.Writer().WriteCode(w, r, http.StatusForbidden, &CheckPermissionResponse{Allowed: allowed})
}

func (h *Handler) getCheck(ctx context.Context, q url.Values) (bool, error) {
Expand All @@ -162,11 +162,11 @@ func (h *Handler) getCheck(ctx context.Context, q url.Values) (bool, error) {
return h.d.PermissionEngine().CheckIsMember(ctx, it[0], maxDepth)
}

// swagger:route POST /relation-tuples/check/openapi read postCheck
// swagger:route POST /relation-tuples/check/openapi permission postCheckPermission
//
// # Check a relation tuple
// # Check a permission
//
// To learn how relation tuples and the check works, head over to [the documentation](https://www.ory.sh/docs/keto/concepts/api-overview).
// To learn how relationship tuples and the check works, head over to [the documentation](https://www.ory.sh/docs/keto/concepts/api-overview).
//
// Consumes:
// - application/json
Expand All @@ -177,7 +177,7 @@ func (h *Handler) getCheck(ctx context.Context, q url.Values) (bool, error) {
// Schemes: http, https
//
// Responses:
// 200: getCheckResponse
// 200: checkPermissionResponse
// 400: genericError
// 500: genericError
func (h *Handler) postCheckNoStatus(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
Expand All @@ -186,14 +186,14 @@ func (h *Handler) postCheckNoStatus(w http.ResponseWriter, r *http.Request, _ ht
h.d.Writer().WriteError(w, r, err)
return
}
h.d.Writer().Write(w, r, &RESTResponse{Allowed: allowed})
h.d.Writer().Write(w, r, &CheckPermissionResponse{Allowed: allowed})
}

// swagger:route POST /relation-tuples/check read postCheckMirrorStatus
// swagger:route POST /relation-tuples/check permission postCheckPermissionOrError
//
// # Check a relation tuple
// # Check a permission
//
// To learn how relation tuples and the check works, head over to [the documentation](https://www.ory.sh/docs/keto/concepts/api-overview).
// To learn how relationship tuples and the check works, head over to [the documentation](https://www.ory.sh/docs/keto/concepts/api-overview).
//
// Consumes:
// - application/json
Expand All @@ -204,9 +204,9 @@ func (h *Handler) postCheckNoStatus(w http.ResponseWriter, r *http.Request, _ ht
// Schemes: http, https
//
// Responses:
// 200: getCheckResponse
// 200: checkPermissionResponse
// 400: genericError
// 403: getCheckResponse
// 403: checkPermissionResponse
// 500: genericError
func (h *Handler) postCheckMirrorStatus(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
allowed, err := h.postCheck(r.Context(), r.Body, r.URL.Query())
Expand All @@ -216,11 +216,11 @@ func (h *Handler) postCheckMirrorStatus(w http.ResponseWriter, r *http.Request,
}

if allowed {
h.d.Writer().Write(w, r, &RESTResponse{Allowed: allowed})
h.d.Writer().Write(w, r, &CheckPermissionResponse{Allowed: allowed})
return
}

h.d.Writer().WriteCode(w, r, http.StatusForbidden, &RESTResponse{Allowed: allowed})
h.d.Writer().WriteCode(w, r, http.StatusForbidden, &CheckPermissionResponse{Allowed: allowed})
}

func (h *Handler) postCheck(ctx context.Context, body io.Reader, query url.Values) (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/e2e/cli_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (g *cliClient) check(t require.TestingT, r *ketoapi.RelationTuple) bool {
sub = r.SubjectSet.String()
}
out := g.c.ExecNoErr(t, "check", sub, r.Relation, r.Namespace, r.Object)
var res check.RESTResponse
var res check.CheckPermissionResponse
require.NoError(t, json.Unmarshal([]byte(out), &res))
return res.Allowed
}
Expand Down
4 changes: 2 additions & 2 deletions internal/e2e/rest_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ func (rc *restClient) check(t require.TestingT, r *ketoapi.RelationTuple) bool {
q := r.ToURLQuery()
bodyGet, codeGet := rc.makeRequest(t, http.MethodGet, fmt.Sprintf("%s?%s", check.RouteBase, q.Encode()), "", rc.readURL)

var respGet check.RESTResponse
var respGet check.CheckPermissionResponse
require.NoError(t, json.Unmarshal([]byte(bodyGet), &respGet))

j, err := json.Marshal(r)
require.NoError(t, err)
bodyPost, codePost := rc.makeRequest(t, http.MethodPost, check.RouteBase, string(j), rc.readURL)

var respPost check.RESTResponse
var respPost check.CheckPermissionResponse
require.NoError(t, json.Unmarshal([]byte(bodyPost), &respPost))

if codeGet == http.StatusOK && codePost == http.StatusOK {
Expand Down
24 changes: 12 additions & 12 deletions internal/e2e/sdk_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (c *sdkClient) requestCtx() context.Context {

func (c *sdkClient) oplCheckSyntax(t require.TestingT, content []byte) (parseErrors []*ketoapi.ParseError) {
res, _, err := c.getOPLSyntaxClient().
SyntaxApi.
RelationshipApi.
CheckOplSyntax(c.requestCtx()).
Body(string(content)).
Execute()
Expand Down Expand Up @@ -96,8 +96,8 @@ func (c *sdkClient) createTuple(t require.TestingT, r *ketoapi.RelationTuple) {
}
}

_, _, err := c.getWriteClient().WriteApi.
CreateRelationTuple(c.requestCtx()).
_, _, err := c.getWriteClient().RelationshipApi.
CreateRelationships(c.requestCtx()).
RelationQuery(payload).
Execute()
require.NoError(t, err)
Expand All @@ -122,8 +122,8 @@ func withSubject[P interface {
}

func (c *sdkClient) deleteTuple(t require.TestingT, r *ketoapi.RelationTuple) {
request := c.getWriteClient().WriteApi.
DeleteRelationTuples(c.requestCtx()).
request := c.getWriteClient().RelationshipApi.
DeleteRelationships(c.requestCtx()).
Namespace(r.Namespace).
Object(r.Object).
Relation(r.Relation)
Expand All @@ -134,7 +134,7 @@ func (c *sdkClient) deleteTuple(t require.TestingT, r *ketoapi.RelationTuple) {
}

func (c *sdkClient) deleteAllTuples(t require.TestingT, q *ketoapi.RelationQuery) {
request := c.getWriteClient().WriteApi.DeleteRelationTuples(c.requestCtx())
request := c.getWriteClient().RelationshipApi.DeleteRelationships(c.requestCtx())
if q.Namespace != nil {
request = request.Namespace(*q.Namespace)
}
Expand All @@ -149,7 +149,7 @@ func (c *sdkClient) deleteAllTuples(t require.TestingT, q *ketoapi.RelationQuery
require.NoError(t, err)
}

func compileParams(req httpclient.ReadApiApiGetRelationTuplesRequest, q *ketoapi.RelationQuery, opts []x.PaginationOptionSetter) httpclient.ReadApiApiGetRelationTuplesRequest {
func compileParams(req httpclient.RelationshipApiApiGetRelationshipsRequest, q *ketoapi.RelationQuery, opts []x.PaginationOptionSetter) httpclient.RelationshipApiApiGetRelationshipsRequest {
if q.Namespace != nil {
req = req.Namespace(*q.Namespace)
}
Expand Down Expand Up @@ -181,7 +181,7 @@ func compileParams(req httpclient.ReadApiApiGetRelationTuplesRequest, q *ketoapi
}

func (c *sdkClient) queryTuple(t require.TestingT, q *ketoapi.RelationQuery, opts ...x.PaginationOptionSetter) *ketoapi.GetResponse {
request := c.getReadClient().ReadApi.GetRelationTuples(c.requestCtx())
request := c.getReadClient().RelationshipApi.GetRelationships(c.requestCtx())
request = compileParams(request, q, opts)

resp, _, err := request.Execute()
Expand Down Expand Up @@ -213,7 +213,7 @@ func (c *sdkClient) queryTuple(t require.TestingT, q *ketoapi.RelationQuery, opt
}

func (c *sdkClient) queryTupleErr(t require.TestingT, expected herodot.DefaultError, q *ketoapi.RelationQuery, opts ...x.PaginationOptionSetter) {
request := c.getReadClient().ReadApi.GetRelationTuples(c.requestCtx())
request := c.getReadClient().RelationshipApi.GetRelationships(c.requestCtx())
request = compileParams(request, q, opts)
_, _, err := request.Execute()

Expand All @@ -228,7 +228,7 @@ func (c *sdkClient) queryTupleErr(t require.TestingT, expected herodot.DefaultEr
}

func (c *sdkClient) check(t require.TestingT, r *ketoapi.RelationTuple) bool {
request := c.getReadClient().ReadApi.GetCheck(c.requestCtx()).
request := c.getReadClient().PermissionApi.CheckPermission(c.requestCtx()).
Namespace(r.Namespace).
Object(r.Object).
Relation(r.Relation)
Expand Down Expand Up @@ -269,7 +269,7 @@ func buildTree(t require.TestingT, mt *httpclient.ExpandTree) *ketoapi.Tree[*ket
}

func (c *sdkClient) expand(t require.TestingT, r *ketoapi.SubjectSet, depth int) *ketoapi.Tree[*ketoapi.RelationTuple] {
request := c.getReadClient().ReadApi.GetExpand(c.requestCtx()).
request := c.getReadClient().PermissionApi.ExpandPermissions(c.requestCtx()).
Namespace(r.Namespace).
Object(r.Object).
Relation(r.Relation).
Expand All @@ -290,7 +290,7 @@ func (c *sdkClient) waitUntilLive(t require.TestingT) {
}

func (c *sdkClient) queryNamespaces(t require.TestingT) (response ketoapi.GetNamespacesResponse) {
res, _, err := c.getReadClient().NamespacesApi.GetNamespaces(c.requestCtx()).Execute()
res, _, err := c.getReadClient().RelationshipApi.GetRelationshipNamespaces(c.requestCtx()).Execute()
require.NoError(t, err)
require.NoError(t, convert(res, &response))

Expand Down
Loading

0 comments on commit dfb9b45

Please sign in to comment.