Skip to content

Commit

Permalink
enhancement: Promote batch API to top level (#190)
Browse files Browse the repository at this point in the history
Moves the batch API REST endpoint from `/api/x/check_resource_batch` to
`/api/check_resource_batch`
  • Loading branch information
charithe committed Jul 6, 2021
1 parent 6e327f3 commit 833538d
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 103 deletions.
94 changes: 94 additions & 0 deletions docs/modules/api/pages/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Alternatively, you can explore the API using the following methods as well:

== Request and response formats

=== `CheckResourceSet` (`/api/check`)

.Request
[source,json,linenums]
----
Expand Down Expand Up @@ -99,7 +101,99 @@ Alternatively, you can explore the API using the following methods as well:
<5> The policy that matched to make the decision for the given action.
<6> Derived roles that were activated.

=== `CheckResourceBatch` (`/api/check_resource_batch`)

Unlike `CheckResourceSet` -- which checks access to resource instances of the _same_ kind, `CheckResourceBatch` allows checking access to multiple heterogeneous resource instances.

.Request
[source,json,linenums]
----
{
"requestId": "test",
"principal": {
"id": "donald_duck",
"policyVersion": "20210210",
"roles": [
"employee"
],
"attr": {
"department": "marketing",
"geography": "GB",
"team": "design"
}
},
"resources": [
{
"actions": [
"view:public",
"approve",
"create"
],
"resource": {
"kind": "leave_request",
"policyVersion": "20210210",
"id": "XX125",
"attr": {
"department": "marketing",
"geography": "GB",
"id": "XX125",
"owner": "john",
"team": "design"
}
}
},
{
"actions": [
"view:public",
"approve",
"create"
],
"resource": {
"kind": "leave_request",
"policyVersion": "20210210",
"id": "XX150",
"attr": {
"department": "marketing",
"geography": "GB",
"id": "XX125",
"owner": "mary",
"team": "design"
}
}
}
]
}
----


.Response
[source,json,linenums]
----
{
"requestId": "test",
"results": [
{
"resourceId": "XX125",
"actions": {
"approve": "EFFECT_DENY",
"create": "EFFECT_DENY",
"view:public": "EFFECT_ALLOW"
}
},
{
"resourceId": "XX150",
"actions": {
"approve": "EFFECT_DENY",
"create": "EFFECT_DENY",
"view:public": "EFFECT_ALLOW"
}
}
]
}
----


== Accessing the API

=== Using curl to access the REST API

Expand Down
4 changes: 2 additions & 2 deletions hack/dev/dev.mk
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ check-http:
$(wildcard $(DEV_DIR)/requests/check_resource_batch/*.json),\
echo "";\
echo $(REQ_FILE); \
curl -k https://localhost:$(HTTP_PORT)/api/x/check_resource_batch?pretty -d @$(REQ_FILE);\
curl -k https://localhost:$(HTTP_PORT)/api/check_resource_batch?pretty -d @$(REQ_FILE);\
echo "";)

@ $(foreach REQ_FILE,\
Expand Down Expand Up @@ -126,7 +126,7 @@ check-http-insecure:
$(wildcard $(DEV_DIR)/requests/check_resource_batch/*.json),\
echo "";\
echo $(REQ_FILE); \
curl http://localhost:$(HTTP_PORT)/api/x/check_resource_batch?pretty -d @$(REQ_FILE);\
curl http://localhost:$(HTTP_PORT)/api/check_resource_batch?pretty -d @$(REQ_FILE);\
echo "";)

@ $(foreach REQ_FILE,\
Expand Down
143 changes: 70 additions & 73 deletions internal/genpb/svc/v1/svc.pb.go

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

2 changes: 1 addition & 1 deletion internal/genpb/svc/v1/svc.pb.gw.go

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

2 changes: 1 addition & 1 deletion internal/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func executeHTTPTestCase(c *http.Client, hostAddr string, creds *authCreds, tc *
want = call.CheckResourceSet.WantResponse
have = &responsev1.CheckResourceSetResponse{}
case *cerbosdevv1.ServerTestCase_CheckResourceBatch:
addr = fmt.Sprintf("%s/api/x/check_resource_batch", hostAddr)
addr = fmt.Sprintf("%s/api/check_resource_batch", hostAddr)
input = call.CheckResourceBatch.Input
want = call.CheckResourceBatch.WantResponse
have = &responsev1.CheckResourceBatchResponse{}
Expand Down

0 comments on commit 833538d

Please sign in to comment.