From a51755970847e9e53dff7e5b8c98095bff97c112 Mon Sep 17 00:00:00 2001 From: EgeAytin Date: Thu, 31 Oct 2024 15:01:35 +0300 Subject: [PATCH] push end to end example --- docs/getting-started/end-to-end-example.mdx | 188 +++++++++++++++++--- docs/mint.json | 2 +- 2 files changed, 169 insertions(+), 21 deletions(-) diff --git a/docs/getting-started/end-to-end-example.mdx b/docs/getting-started/end-to-end-example.mdx index ebb5cf7a5..470f41d95 100644 --- a/docs/getting-started/end-to-end-example.mdx +++ b/docs/getting-started/end-to-end-example.mdx @@ -1,7 +1,7 @@ --- sidebar_position: 5 icon: 'cube' -title: 'Permify Cloud: End to End Example' +title: 'End to End Example' mode: wide --- @@ -55,15 +55,95 @@ Permify Cloud currently gives you an Endpoint and an API Key to connect via gRPC By using these configuration you can set up clients via our SDKs. + + +```java +import org.permify.ApiClient; +import org.permify.api.TenancyApi; +import org.permify.model.TenantListRequest; + +ApiClient apiClient = new ApiClient(); +apiClient.setBasePath(""); +apiClient.addDefaultHeader("Authorization", "Bearer "); +``` + + + + +```python +# Rest SDK for Python +import permify + +configuration = permify.Configuration( + host = ":3476" +) + +api_client = permify.ApiClient(configuration, + header_name="Authorization", + header_value="Bearer ") +``` + + + + +```javascript +// Rest SDK for Javascript +const permify = require('permify-javascript'); +const apiClient = new permify.ApiClient(":3476"); +apiClient.defaultHeaders = {'Authorization': "Bearer "}; +``` + + + + +```typescript +// Rest SDK for Typescript +import * as permify from 'permify-typescript'; +const apiClient = new permify.ApiClient(""); +apiClient.defaultHeaders = {'Authorization': "Bearer "}; +``` + + + +```javascript +// gRPC SDK for Node +const permify = require("@permify/permify-node"); + +const interceptor = permify.grpc.newAccessTokenInterceptor(""); +const client = permify.grpc.newClient({ + endpoint: "", + cert: undefined, + pk: undefined, + certChain: undefined, + insecure: false +}, interceptor); +``` + + + +Let's try validating our connection by sending a **List Tenants API** request. + ```java // Rest SDK for Java import org.permify.ApiClient; +import org.permify.api.TenancyApi; +import org.permify.model.TenantListRequest; ApiClient apiClient = new ApiClient(); -apiClient.setBasePath(""); +apiClient.setBasePath(""); apiClient.addDefaultHeader("Authorization", "Bearer "); + +TenancyApi tenancyApi = new TenancyApi(apiClient); // previously created apiClient +try { + TenantListRequest req = new TenantListRequest(); + req.setPageSize((long) 20); + tenancyApi.tenantsList(req); + +} catch (Exception e) { + System.out.println("Error occurred: " + e.getMessage()); +} ``` @@ -72,11 +152,22 @@ apiClient.addDefaultHeader("Authorization", "Bearer "); ```python # Rest SDK for Python import permify + configuration = permify.Configuration( - host = "", - api_key= "" + host = ":3476" ) -api_client = permify.ApiClient(configuration) + +api_client = permify.ApiClient(configuration, + header_name="Authorization", + header_value="Bearer ") + +api_instance = permify.TenancyApi(api_client) +body = permify.TenantListRequest(page_size=20) +try: + response = api_instance.tenants_list(body) + pprint(response.continuous_token) +except ApiException as e: + print("Exception when listing tenants: %s\n" % e) ``` @@ -85,8 +176,23 @@ api_client = permify.ApiClient(configuration) ```javascript // Rest SDK for Javascript const permify = require('permify-javascript'); -const apiClient = new permify.ApiClient(""); +const apiClient = new permify.ApiClient(":3476"); apiClient.defaultHeaders = {'Authorization': "Bearer "}; +const api = permify.TenancyApi(apiClient) +const body = { + pageSize: 20 +}; +try { + api.tenantsList(body, (error, data, response) => { + if (error) { + // handle the error + } + // handle the response + }); +} catch (error) { + // This block will only handle synchronous errors, + // so you generally wouldn't catch REST errors here. +} ``` @@ -95,8 +201,29 @@ apiClient.defaultHeaders = {'Authorization': "Bearer "}; ```typescript // Rest SDK for Typescript import * as permify from 'permify-typescript'; -const apiClient = new permify.ApiClient(""); +const apiClient = new permify.ApiClient(""); apiClient.defaultHeaders = {'Authorization': "Bearer "}; +apiClient.tenancy.list({ + pageSize: 20 +}).then((response) => { + console.log(response); + // handle response +}) +const api = permify.TenancyApi(apiClient) +const body = { + pageSize: 20 +}; +try { + api.tenantsList(body, (error, data, response) => { + if (error) { + // handle the error + } + // handle the response + }); +} catch (error) { + // This block will only handle synchronous errors, + // so you generally wouldn't catch REST errors here. +} ``` @@ -107,16 +234,27 @@ const permify = require("@permify/permify-node"); const interceptor = permify.grpc.newAccessTokenInterceptor(""); const client = permify.grpc.newClient({ - endpoint: "", + endpoint: "", cert: undefined, pk: undefined, certChain: undefined, insecure: false }, interceptor); + +client.tenancy.list({ + pageSize: 20 +}).then((response) => { + console.log(response); + // handle response +}); ``` +Here is an example Python List Tenant request that shows a successful List Tenants response. + +![tenant-list-response](https://github.com/user-attachments/assets/f63d271b-9582-45fd-94dd-20130efdef26) + Lets move forward with defining our authorization model into Permify Cloud! ## Model Authorization Policy @@ -310,6 +448,10 @@ try { +Here you can observe your configured and deployed schema history in the **Schema Section**. + +![schema-section](https://github.com/user-attachments/assets/4fa825fe-0f61-4345-8ee8-5ee984ce0e2a) + We defined our model to Permify Cloud, lets add some permissions and send example API check request in our application. ## Add Permissions & Store Authorization Data @@ -499,6 +641,9 @@ try { +On **Data Section**, you will see the data you have inserted to Permify: + +![data-section](https://github.com/user-attachments/assets/2d6a00bf-826f-4121-bdd7-7e25aeb6017c) ## Perform Access Check @@ -524,8 +669,8 @@ public static void main(String[] args) { // Create the entity for the organization Entity entity = new Entity(); - entity.setId("organization1"); - entity.setType("organization"); + entity.setId("repository1"); + entity.setType("repository"); // Create the subject for the user Subject subject = new Subject(); @@ -551,11 +696,11 @@ public static void main(String[] args) { ```python # Rest SDK for Python api_instance = permify.PermissionApi(api_client) -metadata = permify.PermissionCheckRequestMetadata() -body = permify.CheckBody(metadata=metadata, entity=permify.Entity("organization", "organization1"), permission="edit", subject=permify.Subject("user", "user1")) +metadata = permify.PermissionCheckRequestMetadata(depth=20) +body = permify.CheckBody(metadata=metadata, entity=permify.Entity(id="repository1", type="repository"), permission="edit", subject=permify.Subject(id="user1", type="user")) try: response = api_instance.permissions_check("t1", body) - pprint(response.can) + pprint(response.to_dict()) except ApiException as e: print("Exception when checking permission: %s\n" % e) ``` @@ -574,8 +719,8 @@ const body = { depth: 20 }, entity: { - type: "organization", - id: "organization1" + type: "repository", + id: "repository1" }, permission: "edit", subject: { @@ -606,8 +751,8 @@ const body = { depth: 20 }, entity: { - type: "organization", - id: "organization1" + type: "repository", + id: "repository1" }, permission: "edit", subject: { @@ -626,7 +771,6 @@ try { - ```javascript // gRPC SDK for Node const body = { @@ -637,8 +781,8 @@ const body = { depth: 20 }, entity: { - type: "organization", - id: "organization1" + type: "repository", + id: "repository1" }, permission: "edit", subject: { @@ -662,3 +806,7 @@ try { ``` + +Below is an example of an implemented Python access check request and response + +![python-check](https://github.com/user-attachments/assets/494b13a6-8f6c-4b3a-a0cb-01e5c045e5b7) \ No newline at end of file diff --git a/docs/mint.json b/docs/mint.json index 534aab36b..383027bd1 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -242,7 +242,7 @@ { "group": "Getting Started", "pages": [ - "getting-started/quickstart", + "getting-started/end-to-end-example", "getting-started/modeling", "getting-started/sync-data", "getting-started/enforcement",