-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1426 from Permify/ufuk/sdk-samples
feat: sdk samples are added for java, js, ts, go and python
- Loading branch information
Showing
28 changed files
with
1,048 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,7 @@ | |
vendor/dist/ | ||
/dist | ||
/config | ||
/tmp | ||
/tmp | ||
|
||
# macOS | ||
*.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
## Sample Usages for SDKs | ||
|
||
We have added sample usages for various SDKs in different languages. | ||
|
||
### Python | ||
- **[Python gRPC](https://github.com/Permify/permify/tree/master/sdk/python/grpc)** | ||
- **[Python REST](https://github.com/Permify/permify/tree/master/sdk/python/rest)** | ||
|
||
### TypeScript | ||
- **[TypeScript gRPC](https://github.com/Permify/permify/tree/master/sdk/typescript/grpc)** | ||
- **[TypeScript REST](https://github.com/Permify/permify/tree/master/sdk/typescript/rest)** | ||
|
||
### JavaScript | ||
- **[JavaScript gRPC](https://github.com/Permify/permify/tree/master/sdk/javascript/grpc)** | ||
- **[JavaScript REST](https://github.com/Permify/permify/tree/master/sdk/javascript/rest)** | ||
|
||
### Java | ||
- **[Java gRPC](https://github.com/Permify/permify/tree/master/sdk/java/grpc)** | ||
- **[Java REST](https://github.com/Permify/permify/tree/master/sdk/java/rest)** | ||
|
||
|
||
For any feedback or questions, please use our [Discord channels](https://discord.gg/n6KfzYxhPp). We value your input and are here to help you get the most out of Permify. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Permify Go SDK | ||
|
||
This repository contains a sample usage for the Go gRPC SDK for Permify. | ||
|
||
## Getting Started | ||
|
||
### Prerequisites | ||
|
||
Ensure you have the following installed: | ||
- go | ||
|
||
### Cloning the Repository | ||
|
||
To get started, clone the repository using the following command: | ||
|
||
```sh | ||
git clone https://github.com/ucatbas/permify-sdk-samples.git | ||
cd permify-sdk-samples/go/grpc | ||
``` | ||
|
||
### Running the Application | ||
|
||
After successfully building the project, you can run the application using the following command: | ||
|
||
```sh | ||
go run create_tenant.go | ||
``` | ||
|
||
## For your own Projects | ||
|
||
To use the Permify SDK in your project, add the following dependency to your pom.xml file: | ||
|
||
```sh | ||
go get github.com/Permify/permify-go/v1 | ||
``` | ||
|
||
Here is a simple permify client: | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
v1 "github.com/Permify/permify-go/generated/base/v1" | ||
permify "github.com/Permify/permify-go/v1" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials/insecure" | ||
) | ||
|
||
func main() { | ||
client, err := permify.NewClient( | ||
permify.Config{ | ||
Endpoint: `localhost:3478`, | ||
}, | ||
grpc.WithTransportCredentials(insecure.NewCredentials()), | ||
) | ||
if err != nil { | ||
log.Fatalf("failed to create Permify client: %v", err) | ||
} | ||
} | ||
|
||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
v1 "github.com/Permify/permify-go/generated/base/v1" | ||
permify "github.com/Permify/permify-go/v1" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials/insecure" | ||
) | ||
|
||
func main() { | ||
client, err := permify.NewClient( | ||
permify.Config{ | ||
Endpoint: `localhost:3478`, | ||
}, | ||
grpc.WithTransportCredentials(insecure.NewCredentials()), | ||
) | ||
if err != nil { | ||
log.Fatalf("failed to create Permify client: %v", err) | ||
} | ||
|
||
ct, err := client.Tenancy.Create(context.Background(), &v1.TenantCreateRequest{ | ||
Id: "t1", | ||
Name: "tenant 1", | ||
}) | ||
if err != nil { | ||
log.Fatalf("failed to create tenant: %v", err) | ||
} | ||
|
||
log.Printf("Tenant created: %v", ct) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module main | ||
|
||
go 1.22.5 | ||
|
||
require ( | ||
github.com/Permify/permify-go v0.4.7 // indirect | ||
github.com/envoyproxy/protoc-gen-validate v1.0.2 // indirect | ||
github.com/golang/protobuf v1.5.3 // indirect | ||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 // indirect | ||
golang.org/x/net v0.17.0 // indirect | ||
golang.org/x/sys v0.13.0 // indirect | ||
golang.org/x/text v0.13.0 // indirect | ||
google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 // indirect | ||
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect | ||
google.golang.org/grpc v1.58.2 // indirect | ||
google.golang.org/protobuf v1.31.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
github.com/Permify/permify-go v0.4.7 h1:VLHBNzv6tQyBV+V+gKi4T+53Wyh8D68+E3gspLxfMJQ= | ||
github.com/Permify/permify-go v0.4.7/go.mod h1:CJQZdI3Zo7adXbh2BHtEgfboOsdxcIe1Ou9INbQ9s+E= | ||
github.com/envoyproxy/protoc-gen-validate v1.0.2 h1:QkIBuU5k+x7/QXPvPPnWXWlCdaBFApVqftFV6k087DA= | ||
github.com/envoyproxy/protoc-gen-validate v1.0.2/go.mod h1:GpiZQP3dDbg4JouG/NNS7QWXpgx6x8QiMKdmN72jogE= | ||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= | ||
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= | ||
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= | ||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | ||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 h1:RtRsiaGvWxcwd8y3BiRZxsylPT8hLWZ5SPcfI+3IDNk= | ||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0/go.mod h1:TzP6duP4Py2pHLVPPQp42aoYI92+PCrVotyR5e8Vqlk= | ||
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= | ||
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= | ||
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= | ||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= | ||
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= | ||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||
google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 h1:L6iMMGrtzgHsWofoFcihmDEMYeDR9KN/ThbPWGrh++g= | ||
google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5/go.mod h1:oH/ZOT02u4kWEp7oYBGYFFkCdKS/uYR9Z7+0/xuuFp8= | ||
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d h1:DoPTO70H+bcDXcd39vOqb2viZxgqeBeSGtZ55yZU4/Q= | ||
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d/go.mod h1:KjSP20unUpOx5kyQUFa7k4OJg0qeJ7DEZflGDu2p6Bk= | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d h1:uvYuEyMHKNt+lT4K3bN6fGswmK8qSvcreM3BwjDh+y4= | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M= | ||
google.golang.org/grpc v1.58.2 h1:SXUpjxeVF3FKrTYQI4f4KvbGD5u2xccdYdurwowix5I= | ||
google.golang.org/grpc v1.58.2/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= | ||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= | ||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= | ||
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= | ||
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Permify Java SDK | ||
|
||
This repository contains a sample usage for the Java gRPC SDK for Permify. | ||
|
||
## Getting Started | ||
|
||
### Prerequisites | ||
|
||
Ensure you have the following installed: | ||
- Java | ||
- Maven | ||
|
||
### Cloning the Repository | ||
|
||
To get started, clone the repository using the following command: | ||
|
||
```sh | ||
git clone https://github.com/ucatbas/permify-sdk-samples.git | ||
cd permify-sdk-samples/java/grpc | ||
``` | ||
|
||
### Building the Project | ||
|
||
Navigate to the root directory of the project and run the following commands to build and install the SDK: | ||
|
||
```sh | ||
mvn clean install | ||
``` | ||
|
||
### Running the Application | ||
|
||
After successfully building the project, you can run the application using the following command: | ||
|
||
```sh | ||
java -jar target/your-artifact-name-0.0.1.jar | ||
``` | ||
|
||
Replace your-artifact-name-0.0.1.jar with the actual name of the jar file generated after the build. | ||
|
||
## For your own Projects | ||
|
||
To use the Permify SDK in your project, add the following dependency to your pom.xml file: | ||
|
||
```xml | ||
<dependency> | ||
<groupId>build.buf.gen</groupId> | ||
<artifactId>permifyco_permify_grpc_java</artifactId> | ||
<version>1.65.1.1.20240628085453.215bbf832f82</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>build.buf.gen</groupId> | ||
<artifactId>permifyco_permify_protocolbuffers_java</artifactId> | ||
<version>27.2.0.1.20240628085453.215bbf832f82</version> | ||
</dependency> | ||
``` | ||
|
||
Here is a simple permify client: | ||
|
||
```java | ||
|
||
// Create the channel | ||
ManagedChannel channel = ManagedChannelBuilder.forAddress("127.0.0.1", 3478).usePlaintext().build(); | ||
|
||
try { | ||
// Create the blocking stub | ||
TenancyGrpc.TenancyBlockingStub blockingStub = TenancyGrpc.newBlockingStub(channel); | ||
|
||
String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date()); | ||
TenantCreateRequest req = TenantCreateRequest.newBuilder() | ||
.setId("tenant_" + timeStamp) | ||
.setName("tenant id name") | ||
.build(); | ||
|
||
TenantCreateResponse response = blockingStub.create(req); | ||
System.out.println(response); | ||
|
||
} finally { | ||
// Gracefully shutdown the channel | ||
try { | ||
channel.shutdown().awaitTermination(5, TimeUnit.SECONDS); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
channel.shutdownNow(); | ||
} | ||
} | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http:https://maven.apache.org/POM/4.0.0" xmlns:xsi="http:https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http:https://maven.apache.org/POM/4.0.0 http:https://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>gs-maven</artifactId> | ||
<version>0.1.0</version> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>3.2.4</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<transformers> | ||
<transformer> | ||
<mainClass>grpc.TenantCreator</mainClass> | ||
</transformer> | ||
</transformers> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<repositories> | ||
<repository> | ||
<releases /> | ||
<snapshots> | ||
<enabled>false</enabled> | ||
</snapshots> | ||
<id>buf</id> | ||
<name>Buf Maven Repository</name> | ||
<url>https://buf.build/gen/maven</url> | ||
</repository> | ||
</repositories> | ||
<properties> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
</properties> | ||
</project> |
Oops, something went wrong.