From c8b312ebdae0fff5d08009ccd1f1299cf54e9a66 Mon Sep 17 00:00:00 2001 From: Magnus Jensen Date: Thu, 25 Apr 2024 13:32:01 +0200 Subject: [PATCH] fix: order and content of curl rebac api calls --- docs/api/rebac/rebac-api-calls.mdx | 139 +++++++++++++++-------------- 1 file changed, 73 insertions(+), 66 deletions(-) diff --git a/docs/api/rebac/rebac-api-calls.mdx b/docs/api/rebac/rebac-api-calls.mdx index 8e1207d1..0e2e5c24 100644 --- a/docs/api/rebac/rebac-api-calls.mdx +++ b/docs/api/rebac/rebac-api-calls.mdx @@ -25,25 +25,14 @@ https://api.permit.io/v2/schema/{proj_id}/{env_id}/resources/{resource_id}/roles ```bash -curl https://api.permit.io/v2/schema/$permit_project/$permit_env/resources/folder/roles/editor \ - -X PATCH \ +curl https://api.permit.io/v2/schema/$permit_project/$permit_env/resources/repo/roles \ + -X POST \ -H "Authorization: Bearer $permit_sdk_api_key" \ -H "Content-Type: application/json" \ -d '{ - "granted_to": { - "users_with_role": [ - { - "linked_by_relation": "account", - "on_resource": "account", - "role": "admin" - }, - { - "linked_by_relation": "parent", - "on_resource": "folder", - "role": "editor" - } - ] - } + "key": "maintainer", + "name": "Maintainer", + "permissions": ["read", "write"] }' ``` @@ -51,21 +40,10 @@ curl https://api.permit.io/v2/schema/$permit_project/$permit_env/resources/folde ```javascript -await permit.api.resourceRoles.update("folder", "editor", { - granted_to: { - users_with_role: [ - { - linked_by_relation: "account", - on_resource: "account", - role: "admin", - }, - { - linked_by_relation: "parent", - on_resource: "folder", - role: "editor", - }, - ], - }, +await permit.api.resourceRoles.create("repo", { + key: "maintainer", + name: "Maintainer", + permissions: ["read", "write"], }); ``` @@ -83,6 +61,21 @@ https://api.permit.io/v2/schema/{proj_id}/{env_id}/resources/{resource_id}/relat ### Example + + +```bash +curl https://api.permit.io/v2/schema/$permit_project/$permit_env/resources/file/relations \ + -X POST \ + -H "Authorization: Bearer $permit_sdk_api_key" \ + -H "Content-Type: application/json" \ + -d '{ + "key": "parent", + "name": "Parent", + "subject_resource": "folder" + }' +``` + + ```python @@ -101,9 +94,9 @@ await permit.api.resource_relations.create( ```javascript await permit.api.resourceRelations.create("file", { - key: "parent", - name: "Parent", - subject_resource: "folder", + key: "parent", + name: "Parent", + subject_resource: "folder", }); ``` @@ -121,14 +114,28 @@ https://api.permit.io/v2/facts/{proj_id}/{env_id}/resource_instances ### Example - + + +```bash +curl https://api.permit.io/v2/facts/$permit_project/$permit_env/resource_instances \ +-X POST \ +-H "Authorization: Bearer $permit_sdk_api_key" \ +-H "Content-Type: application/json" \ +-d '{ + "resource": "file", + "key": "2023_report", + "tenant": "default" +}' +``` + + ```javascript await permit.api.resourceInstances.create({ - resource: "file", - key: "2023_report", - tenant: "default", + resource: "file", + key: "2023_report", + tenant: "default", }); ``` @@ -145,14 +152,14 @@ await permit.api.resourceInstances.create({ ```bash -curl https://api.permit.io/v2/facts/$permit_project/$permit_env/resource_instances \ +curl https://api.permit.io/v2/facts/$permit_project/$permit_env/role_assignments \ -X POST \ -H "Authorization: Bearer $permit_sdk_api_key" \ -H "Content-Type: application/json" \ -d '{ - "resource": "file", - "key": "2023_report", - "tenant": "default" + "user": "john@acme.com", + "role": "viewer", + "resource_instance": "file:2023_report" }' ``` @@ -161,9 +168,9 @@ curl https://api.permit.io/v2/facts/$permit_project/$permit_env/resource_instanc ```javascript await permit.api.roleAssignments.assign({ - user: "john@acme.com", - role: "viewer", - resource_instance: "file:2023_report", + user: "john@acme.com", + role: "viewer", + resource_instance: "file:2023_report", }); ``` @@ -184,15 +191,15 @@ https://api.permit.io/v2/facts/{proj_id}/{env_id}/relationship_tuples ```bash -curl https://api.permit.io/v2/facts/$permit_project/$permit_env/role_assignments \ - -X POST \ - -H "Authorization: Bearer $permit_sdk_api_key" \ - -H "Content-Type: application/json" \ - -d '{ - "user": "john@acme.com", - "role": "viewer", - "resource_instance": "file:2023_report" - }' +curl https://api.permit.io/v2/facts/$permit_project/$permit_env/relationship_tuples \ +-X POST \ +-H "Authorization: Bearer $permit_sdk_api_key" \ +-H "Content-Type: application/json" \ +-d '{ + "subject": "folder:finance", + "relation": "parent", + "object": "file:2023_report" +}' ``` @@ -200,9 +207,9 @@ curl https://api.permit.io/v2/facts/$permit_project/$permit_env/role_assignments ```javascript await permit.api.relationshipTuples.create({ - subject: "folder:finance", - relation: "parent", - object: "file:2023_report", + subject: "folder:finance", + relation: "parent", + object: "file:2023_report", }); ``` @@ -245,15 +252,15 @@ curl https://api.permit.io/v2/schema/$permit_project/$permit_env/resources/file/ ```javascript await permit.api.resourceRoles.update("file", "editor", { - granted_to: { - users_with_role: [ - { - linked_by_relation: "parent", - on_resource: "folder", - role: "editor", - }, - ], - }, + granted_to: { + users_with_role: [ + { + linked_by_relation: "parent", + on_resource: "folder", + role: "editor", + }, + ], + }, }); ```