Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: API paths #862

Merged
merged 3 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ for your colleagues, and much more!

### :mega: Community gets Ory Cloud for Free! :mega:

Ory community members get the Ory Cloud Start Up plan **free for six months**, with
all quality-of-life features available, such as custom domains and giving your
team members access.
Ory community members get the Ory Cloud Start Up plan **free for six months**,
with all quality-of-life features available, such as custom domains and giving
your team members access.
[Sign up with your GitHub account](https://console.ory.sh/registration?preferred_plan=start-up&utm_source=github&utm_medium=banner&utm_campaign=keto-readme-first900)
and use the coupon code **`FIRST900`** on the _"Start-Up Plan"_ checkout page to
claim your free project now! Make sure to be signed up to the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ files:/photos/mountains.jpg#access@(directories:/photos#access)' | \
jq "[ .[] | { relation_tuple: . , action: \"insert\" } ]" -c | \
curl -X PATCH --silent --fail \
--data @- \
http://127.0.0.1:4467/relation-tuples
http://127.0.0.1:4467/admin/relation-tuples

echo "Successfully created tuples"
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ curl -G --silent \
--data-urlencode "relation=access" \
--data-urlencode "object=/photos/beach.jpg" \
--data-urlencode "max-depth=3" \
http://127.0.0.1:4466/expand | \
http://127.0.0.1:4466/acl/expand | \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACL for Access Control List? Is that the nomenclautur you want to go here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also not sure about that, but basically yes. The gRPC API is also package ory.keto.acl.v1alpha1, so it would be consistent.
In some way you could say that relation tuples are an ACL?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Later on we can have /rbac/check and others.

jq
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ curl -G --silent \
jq "[ .relation_tuples[] | { relation_tuple: . , action: \"delete\" } ]" -c | \
curl -X PATCH --silent --fail \
--data @- \
http://127.0.0.1:4467/relation-tuples
http://127.0.0.1:4467/admin/relation-tuples

curl -G --silent \
--data-urlencode "namespace=directories" \
http://127.0.0.1:4466/relation-tuples | \
jq "[ .relation_tuples[] | { relation_tuple: . , action: \"delete\" } ]" -c | \
curl -X PATCH --silent --fail \
--data @- \
http://127.0.0.1:4467/relation-tuples
http://127.0.0.1:4467/admin/relation-tuples
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ chats:coffee-break#member@Patrik' | \
jq "[ .[] | { relation_tuple: . , action: \"insert\" } ]" -c | \
curl -X PATCH --silent --fail \
--data @- \
http://127.0.0.1:4467/relation-tuples
http://127.0.0.1:4467/admin/relation-tuples

echo "Successfully created tuples"
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ curl -G --silent \
jq "[ .relation_tuples[] | { relation_tuple: . , action: \"delete\" } ]" -c | \
curl -X PATCH --silent --fail \
--data @- \
http://127.0.0.1:4467/relation-tuples
http://127.0.0.1:4467/admin/relation-tuples
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ relationtuple='

curl --fail --silent -X PUT \
--data "$relationtuple" \
http://127.0.0.1:4467/relation-tuples > /dev/null \
http://127.0.0.1:4467/admin/relation-tuples > /dev/null \
&& echo "Successfully created tuple" \
|| echo "Encountered error"
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ curl -G --silent \
--data-urlencode "relation=decypher" \
--data-urlencode "namespace=messages" \
--data-urlencode "object=02y_15_4w350m3" \
http://127.0.0.1:4466/check \
http://127.0.0.1:4466/acl/check \
| jq -r 'if .allowed == true then "Allowed" else "Denied" end'
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ curl -X DELETE -G --silent \
--data-urlencode "relation=decypher" \
--data-urlencode "namespace=messages" \
--data-urlencode "object=02y_15_4w350m3" \
http://127.0.0.1:4467/relation-tuples
http://127.0.0.1:4467/admin/relation-tuples
6 changes: 3 additions & 3 deletions internal/check/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewHandler(d handlerDependencies) *Handler {
return &Handler{d: d}
}

const RouteBase = "/check"
const RouteBase = "/acl/check"

func (h *Handler) RegisterReadRoutes(r *x.ReadRouter) {
r.GET(RouteBase, h.getCheck)
Expand Down Expand Up @@ -70,7 +70,7 @@ type getCheckRequest struct {
MaxDepth int `json:"max-depth"`
}

// swagger:route GET /check read getCheck
// swagger:route GET /acl/check read getCheck
//
// Check a relation tuple
//
Expand Down Expand Up @@ -119,7 +119,7 @@ func (h *Handler) getCheck(w http.ResponseWriter, r *http.Request, _ httprouter.
h.d.Writer().WriteCode(w, r, http.StatusForbidden, &RESTResponse{Allowed: false})
}

// swagger:route POST /check read postCheck
// swagger:route POST /acl/check read postCheck
//
// Check a relation tuple
//
Expand Down
2 changes: 1 addition & 1 deletion internal/driver/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (r *RegistryDefault) enableSqa(cmd *cobra.Command) {
healthx.ReadyCheckPath,
healthx.VersionPath,

relationtuple.RouteBase,
relationtuple.ReadRouteBase,
check.RouteBase,
expand.RouteBase,
},
Expand Down
2 changes: 1 addition & 1 deletion internal/e2e/full_suit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func TestServeConfig(t *testing.T) {
time.Sleep(10 * time.Millisecond)
}

req, err := http.NewRequest(http.MethodOptions, "http://"+reg.Config(ctx).ReadAPIListenOn()+relationtuple.RouteBase, nil)
req, err := http.NewRequest(http.MethodOptions, "http://"+reg.Config(ctx).ReadAPIListenOn()+relationtuple.ReadRouteBase, nil)
require.NoError(t, err)
req.Header.Set("Origin", "https://ory.sh")
resp, err := http.DefaultClient.Do(req)
Expand Down
10 changes: 5 additions & 5 deletions internal/e2e/rest_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,19 @@ func (rc *restClient) createTuple(t require.TestingT, r *relationtuple.InternalR
tEnc, err := json.Marshal(r)
require.NoError(t, err)

body, code := rc.makeRequest(t, http.MethodPut, relationtuple.RouteBase, string(tEnc), true)
body, code := rc.makeRequest(t, http.MethodPut, relationtuple.WriteRouteBase, string(tEnc), true)
assert.Equal(t, http.StatusCreated, code, body)
}

func (rc *restClient) deleteTuple(t require.TestingT, r *relationtuple.InternalRelationTuple) {
q, err := r.ToURLQuery()
require.NoError(t, err)
body, code := rc.makeRequest(t, http.MethodDelete, relationtuple.RouteBase+"?"+q.Encode(), "", true)
body, code := rc.makeRequest(t, http.MethodDelete, relationtuple.WriteRouteBase+"?"+q.Encode(), "", true)
require.Equal(t, http.StatusNoContent, code, body)
}

func (rc restClient) deleteAllTuples(t require.TestingT, q *relationtuple.RelationQuery) {
body, code := rc.makeRequest(t, http.MethodDelete, relationtuple.RouteBase+"?"+q.ToURLQuery().Encode(), "", true)
body, code := rc.makeRequest(t, http.MethodDelete, relationtuple.WriteRouteBase+"?"+q.ToURLQuery().Encode(), "", true)
require.Equal(t, http.StatusNoContent, code, body)
}

Expand All @@ -85,7 +85,7 @@ func (rc *restClient) queryTuple(t require.TestingT, q *relationtuple.RelationQu
urlQuery.Set("page_token", pagination.Token)
}

body, code := rc.makeRequest(t, http.MethodGet, fmt.Sprintf("%s?%s", relationtuple.RouteBase, urlQuery.Encode()), "", false)
body, code := rc.makeRequest(t, http.MethodGet, fmt.Sprintf("%s?%s", relationtuple.ReadRouteBase, urlQuery.Encode()), "", false)
require.Equal(t, http.StatusOK, code, body)

var dec relationtuple.GetResponse
Expand All @@ -105,7 +105,7 @@ func (rc *restClient) queryTupleErr(t require.TestingT, expected herodot.Default
urlQuery.Set("page_token", pagination.Token)
}

body, code := rc.makeRequest(t, http.MethodGet, fmt.Sprintf("%s?%s", relationtuple.RouteBase, urlQuery.Encode()), "", false)
body, code := rc.makeRequest(t, http.MethodGet, fmt.Sprintf("%s?%s", relationtuple.ReadRouteBase, urlQuery.Encode()), "", false)

assert.Equal(t, expected.CodeField, code)
assert.Equal(t, int64(expected.StatusCode()), gjson.Get(body, "error.code").Int())
Expand Down
4 changes: 2 additions & 2 deletions internal/expand/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type (

var _ acl.ExpandServiceServer = (*handler)(nil)

const RouteBase = "/expand"
const RouteBase = "/acl/expand"

func NewHandler(d handlerDependencies) *handler {
return &handler{d: d}
Expand All @@ -55,7 +55,7 @@ type getExpandRequest struct {
MaxDepth int `json:"max-depth"`
}

// swagger:route GET /expand read getExpand
// swagger:route GET /acl/expand read getExpand
//
// Expand a Relation Tuple
//
Expand Down
12 changes: 6 additions & 6 deletions internal/httpclient-next/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading