-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(python-sdk): address misc issues, add example (#265)
- Loading branch information
Showing
15 changed files
with
488 additions
and
7 deletions.
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
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
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
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
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,11 @@ | ||
all: run | ||
|
||
project_name=example1 | ||
openfga_version=latest | ||
|
||
run: | ||
python example1/example1.py | ||
|
||
run-openfga: | ||
docker pull docker.io/openfga/openfga:${openfga_version} && \ | ||
docker run -p 8080:8080 docker.io/openfga/openfga:${openfga_version} run |
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,32 @@ | ||
## Examples of using the OpenFGA Python SDK | ||
|
||
A set of examples on how to call the OpenFGA Python SDK | ||
|
||
### Examples | ||
Example 1: | ||
A bare-bones example. It creates a store, and runs a set of calls against it including creating a model, writing tuples and checking for access. | ||
|
||
### Running the Examples | ||
|
||
Prerequisites: | ||
- `docker` | ||
- `make` | ||
- `python` 3.11+ | ||
|
||
#### Run using a published SDK | ||
|
||
Steps: | ||
1. Clone/Copy the example folder | ||
2. If you have an OpenFGA server running, you can use it, otherwise run `make run-openfga` to spin up an instance (you'll need to switch to a different terminal after - don't forget to close it when done) | ||
3. Run `make run` to run the example | ||
|
||
#### Run using a local unpublished SDK build | ||
|
||
Steps: | ||
1. Build the SDK | ||
2. Change to the example directory | ||
3. Install the local SDK `pip install -e $LOCAL_DIR` | ||
- For example, if your local SDK is located at `$HOME/projects/python-sdk`, run `pip install -e $HOME/projects/python-sdk` | ||
- For advanced users: The above just updates `requirements.txt` and the source of openfga-sdk. If you know how to manually edit this, feel free to do that as well. | ||
4. If you have an OpenFGA server running, you can use it, otherwise run `make run-openfga` to spin up an instance (you'll need to switch to a different terminal after - don't forget to close it when done) | ||
5. Run `make run` to run the example |
73 changes: 73 additions & 0 deletions
73
config/clients/python/template/example/example1/auth-model.json
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,73 @@ | ||
{ | ||
"schema_version": "1.1", | ||
"type_definitions": [ | ||
{ | ||
"type": "user" | ||
}, | ||
{ | ||
"type": "document", | ||
"relations": { | ||
"reader": { | ||
"this": {} | ||
}, | ||
"writer": { | ||
"this": {} | ||
}, | ||
"owner": { | ||
"this": {} | ||
} | ||
}, | ||
"metadata": { | ||
"relations": { | ||
"reader": { | ||
"directly_related_user_types": [ | ||
{ | ||
"type": "user" | ||
} | ||
] | ||
}, | ||
"writer": { | ||
"directly_related_user_types": [ | ||
{ | ||
"type": "user" | ||
} | ||
] | ||
}, | ||
"owner": { | ||
"directly_related_user_types": [ | ||
{ | ||
"type": "user" | ||
} | ||
] | ||
}, | ||
"conditional_reader": { | ||
"directly_related_user_types": [ | ||
{ | ||
"condition": "name_starts_with_a", | ||
"type": "user" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"conditions": { | ||
"ViewCountLessThan200": { | ||
"name": "ViewCountLessThan200", | ||
"expression": "ViewCount < 200", | ||
"parameters": { | ||
"ViewCount": { | ||
"type_name": "TYPE_NAME_INT" | ||
}, | ||
"Type": { | ||
"type_name": "TYPE_NAME_STRING" | ||
}, | ||
"Name": { | ||
"type_name": "TYPE_NAME_STRING" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.