Skip to content

Commit

Permalink
Merge pull request #1741 from Permify/docs
Browse files Browse the repository at this point in the history
docs: push end to end example
  • Loading branch information
EgeAytin authored Oct 31, 2024
2 parents fbdde47 + a517559 commit f8d3d67
Show file tree
Hide file tree
Showing 2 changed files with 169 additions and 21 deletions.
188 changes: 168 additions & 20 deletions docs/getting-started/end-to-end-example.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
sidebar_position: 5
icon: 'cube'
title: 'Permify Cloud: End to End Example'
title: 'End to End Example'
mode: wide
---

Expand Down Expand Up @@ -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.

<Tabs>
<Tab title="Java">
```java
import org.permify.ApiClient;
import org.permify.api.TenancyApi;
import org.permify.model.TenantListRequest;

ApiClient apiClient = new ApiClient();
apiClient.setBasePath("<your-permify-endpoint:3476>");
apiClient.addDefaultHeader("Authorization", "Bearer <your-permify-api-key>");
```
</Tab>

<Tab title="Python">

```python
# Rest SDK for Python
import permify

configuration = permify.Configuration(
host = "<your-permify-endpoint>:3476"
)

api_client = permify.ApiClient(configuration,
header_name="Authorization",
header_value="Bearer <your-permify-api-key>")
```
</Tab>

<Tab title="Javascript">

```javascript
// Rest SDK for Javascript
const permify = require('permify-javascript');
const apiClient = new permify.ApiClient("<your-permify-endpoint>:3476");
apiClient.defaultHeaders = {'Authorization': "Bearer <your-permify-api-key>"};
```
</Tab>

<Tab title="Typescript">

```typescript
// Rest SDK for Typescript
import * as permify from 'permify-typescript';
const apiClient = new permify.ApiClient("<your-permify-endpoint:3476>");
apiClient.defaultHeaders = {'Authorization': "Bearer <your-permify-api-key>"};
```
</Tab>

<Tab title="Node">
```javascript
// gRPC SDK for Node
const permify = require("@permify/permify-node");

const interceptor = permify.grpc.newAccessTokenInterceptor("<your-permify-api-key>");
const client = permify.grpc.newClient({
endpoint: "<your-permify-endpoint:3478>",
cert: undefined,
pk: undefined,
certChain: undefined,
insecure: false
}, interceptor);
```
</Tab>
</Tabs>

Let's try validating our connection by sending a **List Tenants API** request.

<Tabs>
<Tab title="Java">
```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("<your-permify-host>");
apiClient.setBasePath("<your-permify-endpoint:3476>");
apiClient.addDefaultHeader("Authorization", "Bearer <your-permify-api-key>");

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());
}
```
</Tab>

Expand All @@ -72,11 +152,22 @@ apiClient.addDefaultHeader("Authorization", "Bearer <your-permify-api-key>");
```python
# Rest SDK for Python
import permify

configuration = permify.Configuration(
host = "<your-permify-host>",
api_key= "<your-permify-api-key>"
host = "<your-permify-endpoint>:3476"
)
api_client = permify.ApiClient(configuration)

api_client = permify.ApiClient(configuration,
header_name="Authorization",
header_value="Bearer <your-permify-api-key>")

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)
```
</Tab>

Expand All @@ -85,8 +176,23 @@ api_client = permify.ApiClient(configuration)
```javascript
// Rest SDK for Javascript
const permify = require('permify-javascript');
const apiClient = new permify.ApiClient("<your-permify-host>");
const apiClient = new permify.ApiClient("<your-permify-endpoint>:3476");
apiClient.defaultHeaders = {'Authorization': "Bearer <your-permify-api-key>"};
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.
}
```
</Tab>

Expand All @@ -95,8 +201,29 @@ apiClient.defaultHeaders = {'Authorization': "Bearer <your-permify-api-key>"};
```typescript
// Rest SDK for Typescript
import * as permify from 'permify-typescript';
const apiClient = new permify.ApiClient("<your-permify-host>");
const apiClient = new permify.ApiClient("<your-permify-endpoint:3476>");
apiClient.defaultHeaders = {'Authorization': "Bearer <your-permify-api-key>"};
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.
}
```
</Tab>

Expand All @@ -107,16 +234,27 @@ const permify = require("@permify/permify-node");

const interceptor = permify.grpc.newAccessTokenInterceptor("<your-permify-api-key>");
const client = permify.grpc.newClient({
endpoint: "<your-permify-host>",
endpoint: "<your-permify-endpoint:3478>",
cert: undefined,
pk: undefined,
certChain: undefined,
insecure: false
}, interceptor);

client.tenancy.list({
pageSize: 20
}).then((response) => {
console.log(response);
// handle response
});
```
</Tab>
</Tabs>

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
Expand Down Expand Up @@ -310,6 +448,10 @@ try {
</Tab>
</Tabs>

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
Expand Down Expand Up @@ -499,6 +641,9 @@ try {
</Tab>
</Tabs>

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

Expand All @@ -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();
Expand All @@ -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)
```
Expand All @@ -574,8 +719,8 @@ const body = {
depth: 20
},
entity: {
type: "organization",
id: "organization1"
type: "repository",
id: "repository1"
},
permission: "edit",
subject: {
Expand Down Expand Up @@ -606,8 +751,8 @@ const body = {
depth: 20
},
entity: {
type: "organization",
id: "organization1"
type: "repository",
id: "repository1"
},
permission: "edit",
subject: {
Expand All @@ -626,7 +771,6 @@ try {
</Tab>
<Tab title="Node">
```javascript
// gRPC SDK for Node
const body = {
Expand All @@ -637,8 +781,8 @@ const body = {
depth: 20
},
entity: {
type: "organization",
id: "organization1"
type: "repository",
id: "repository1"
},
permission: "edit",
subject: {
Expand All @@ -662,3 +806,7 @@ try {
```
</Tab>
</Tabs>
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)
2 changes: 1 addition & 1 deletion docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit f8d3d67

Please sign in to comment.