Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6aa5f73
feat: initial checkin of sdk with python generator
adriantam Aug 12, 2022
e989cc8
feat: adding unit test
adriantam Aug 12, 2022
19239e8
chore: add in snyk and github action config file
adriantam Aug 12, 2022
c88982a
feat: add in better handling for 400/404/500 errors
adriantam Aug 22, 2022
14aa75b
feat: update README and add in UT for list objects
adriantam Aug 22, 2022
8589316
fix: ensure subsection matches table of content in README
adriantam Aug 22, 2022
229c684
chore: enable github action for python sdk
adriantam Aug 22, 2022
562d779
fix: no need to JSON dumps before calling rest client
adriantam Aug 22, 2022
9c586ed
fix: update github action + git ignore file
adriantam Aug 23, 2022
ebe65e0
chore: ignore pyc file
adriantam Aug 23, 2022
786022f
chore: update READMEs to reflect python SDK
adriantam Aug 23, 2022
c4fd129
feat: add unit test for converting model
adriantam Aug 24, 2022
9ec0f4a
fix: apply patch for create_store API
adriantam Aug 24, 2022
286a81c
fix: manually add README examples
adriantam Aug 25, 2022
c7e72fa
fix: update based on code review feedback
adriantam Aug 29, 2022
81ef89e
fix: correct info on init config
adriantam Aug 30, 2022
1ddcca2
fix: update changelog date
adriantam Aug 30, 2022
f518886
fix: simply api example shown
adriantam Aug 31, 2022
75326b3
fix: update partial header to be similar to other SDK
adriantam Sep 8, 2022
2b8fac2
Merge branch 'main' into feat/python_new
adriantam Sep 14, 2022
9ea50f3
Merge branch 'main' into feat/python_new
adriantam Sep 16, 2022
2ad8545
Merge branch 'main' into feat/python_new
adriantam Sep 20, 2022
2461380
feat: incorporate async python (#29)
adriantam Sep 21, 2022
f23a544
feat: python SDK to add in retry upon 429 (#35)
adriantam Sep 23, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,81 @@ jobs:
GITHUB_ORG_ID: ${{ secrets.DOTNET_SDK_GITHUB_ORG_ID }}
GITHUB_REPO_ID: ${{ secrets.DOTNET_SDK_GITHUB_REPO_ID }}
SSH_KEY: ${{ secrets.DOTNET_SDK_SSH_KEY }}

build-and-test-python-sdk:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Specify python version
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Setup git
run: ./scripts/setup_git.sh
env:
GIT_USER_NAME: ${{ secrets.GIT_USER_NAME }}
GIT_USER_EMAIL: ${{ secrets.GIT_USER_EMAIL }}

- name: Clone the existing SDK
run: ./scripts/clone_sdk.sh
env:
GITHUB_ORG_ID: ${{ secrets.PYTHON_SDK_GITHUB_ORG_ID }}
GITHUB_REPO_ID: ${{ secrets.PYTHON_SDK_GITHUB_REPO_ID }}
SSH_KEY: ${{ secrets.PYTHON_SDK_SSH_KEY }}
SDK_PATH: clients/fga-python-sdk
KNOWN_HOSTS: ${{secrets.KNOWN_HOSTS}}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Run All Tests
run: |-
make test-client-python

- name: Install SDK to prepare for Snyk
working-directory: clients/fga-python-sdk
run: |-
pip install -r requirements.txt

- name: Install Snyk CLI
run: |-
mkdir -p ~/.local/bin
export PATH=$PATH:$HOME/.local/bin
curl https://static.snyk.io/cli/latest/snyk-linux -o ~/.local/bin/snyk
chmod +x ~/.local/bin/snyk

- name: Run Snyk to check for vulnerabilities
working-directory: clients/fga-python-sdk
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
run: |-
export PATH=$PATH:$HOME/.local/bin
snyk test

- name: Install FOSSA CLI
run: |-
mkdir -p ~/.local/bin
export PATH=$PATH:$HOME/.local/bin
curl -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/fossas/fossa-cli/master/install-latest.sh -b ~/.local/bin | bash

- name: Run FOSSA scan and upload build data
working-directory: clients/fga-python-sdk
env:
FOSSA_API_KEY: ${{ secrets.FOSSA_API_KEY }}
run: |-
export PATH=$PATH:$HOME/.local/bin
fossa analyze
fossa test

- name: Check for SDK changes
run: ./scripts/commit_push_changes.sh
env:
SDK_PATH: clients/fga-python-sdk
DRY_RUN: 1
TAGGING_DISABLE: 1
GITHUB_ORG_ID: ${{ secrets.PYTHON_SDK_GITHUB_ORG_ID }}
GITHUB_REPO_ID: ${{ secrets.PYTHON_SDK_GITHUB_REPO_ID }}
SSH_KEY: ${{ secrets.PYTHON_SDK_SSH_KEY }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
docs/openapi/*.json

.DS_Store
.dccache

clients/**/*
28 changes: 26 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ GO_DOCKER_TAG = 1
DOTNET_DOCKER_TAG = 6.0
GOLINT_DOCKER_TAG = v1.48
BUSYBOX_DOCKER_TAG = 1.34.1
PYTHON_DOCKER_TAG = 3.10
# Other config
CONFIG_DIR = ${PWD}/config
CLIENTS_OUTPUT_DIR = ${PWD}/clients
DOCS_CACHE_DIR = ${PWD}/docs/openapi
TMP_DIR = $(shell mktemp -d "$${TMPDIR:-/tmp}/tmp.XXXXX")
dotnet_package_version = $(shell cat ./clients/fga-dotnet-sdk/VERSION.txt)
CURRENT_UID := $(shell id -u)
CURRENT_GID := $(shell id -g)

dotnet_publish_api_key=

Expand Down Expand Up @@ -39,10 +42,10 @@ test: test-all-clients
build: build-all-clients

.PHONY: test-all-clients
test-all-clients: test-client-js test-client-go test-client-dotnet
test-all-clients: test-client-js test-client-go test-client-dotnet test-client-python

.PHONY: build-all-clients
build-all-clients: build-client-js build-client-go build-client-dotnet
build-all-clients: build-client-js build-client-go build-client-dotnet build-client-python

### JavaScript
.PHONY: tag-client-js
Expand Down Expand Up @@ -100,6 +103,25 @@ build-client-dotnet:
make run-in-docker sdk_language=dotnet image=mcr.microsoft.com/dotnet/sdk:${DOTNET_DOCKER_TAG} command="/bin/sh -c 'dotnet format ./OpenFga.Sdk.sln'" || true
make run-in-docker sdk_language=dotnet image=mcr.microsoft.com/dotnet/sdk:${DOTNET_DOCKER_TAG} command="/bin/sh -c 'dotnet format ./OpenFga.Sdk.sln'"

### Python
.PHONY: tag-client-python
tag-client-python: test-client-python
make utils-tag-client sdk_language=python

.PHONY: build-client-python
build-client-python:
make build-client sdk_language=python tmpdir=${TMP_DIR} library="--library asyncio"
make run-in-docker sdk_language=python image=busybox:${BUSYBOX_DOCKER_TAG} command="/bin/sh -c 'patch -p1 /module/openfga_sdk/api/open_fga_api.py /config/clients/python/patches/open_fga_api.py.patch'"
make run-in-docker sdk_language=python image=busybox:${BUSYBOX_DOCKER_TAG} command="/bin/sh -c 'patch -p1 /module/docs/OpenFgaApi.md /config/clients/python/patches/OpenFgaApi.md.patch'"
make run-in-docker sdk_language=python image=python:${PYTHON_DOCKER_TAG} command="/bin/sh -c 'python -m pip install autopep8; autopep8 --in-place --ignore E402 --recursive openfga_sdk; autopep8 --in-place --recursive test'"

.PHONY: test-client-python
test-client-python: build-client-python
make run-in-docker sdk_language=python image=python:${PYTHON_DOCKER_TAG} command="/bin/sh -c 'python -m pip install -r test-requirements.txt; python -m unittest test/*'"
make run-in-docker sdk_language=python image=python:${PYTHON_DOCKER_TAG} command="/bin/sh -c 'python -m pip install -r test-requirements.txt; python -m flake8 --ignore F401,E402,E501,W504 openfga_sdk'"
# Need to ignore E402 (import order) to avoid circular dependency
make run-in-docker sdk_language=python image=python:${PYTHON_DOCKER_TAG} command="/bin/sh -c 'python -m pip install -r test-requirements.txt; python -m flake8 --ignore E501 test'"

.PHONY: run-in-docker
run-in-docker:
docker run --rm \
Expand Down Expand Up @@ -136,13 +158,15 @@ build-client: build-openapi

# Generate the SDK
docker run --rm \
-u ${CURRENT_UID}:${CURRENT_GID} \
-v ${PWD}/docs:/docs \
-v ${CLIENTS_OUTPUT_DIR}:/clients \
-v ${tmpdir}:/config \
--name openapi-generator \
openapitools/openapi-generator-cli:${OPENAPI_GENERATOR_CLI_DOCKER_TAG} generate \
-i /docs/openapi/openfga.openapiv2.json \
--http-user-agent='openfga-sdk (${sdk_language}) {packageVersion}' \
${library} \
-o /clients/fga-${sdk_language}-sdk \
-c /config/config.json \
-g `cat ./config/clients/${sdk_language}/generator.txt`
Expand Down
35 changes: 23 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@ This is the main generator responsible for generating the OpenFGA SDKs from the

## Table of Contents

- [About OpenFGA](#about)
- [Resources](#resources)
- [Currently Supported SDKs](#currently-supported-sdks)
- [Getting Started](#getting-started)
- [Requirements](#requirements)
- [Usage](#usage)
- [Adding a New SDK](#adding-a-new-sdk)
- [Uploading the SDK](#uploading-the-sdk)
- [Publishing the SDK](#publishingopen-sourcing-the-sdk)
- [Contributing](#contributing)
- [License](#license)
- [OpenFGA Client SDK Generator](#openfga-client-sdk-generator)
- [Table of Contents](#table-of-contents)
- [About](#about)
- [Resources](#resources)
- [Currently Supported SDKs](#currently-supported-sdks)
- [Getting Started](#getting-started)
- [Requirements](#requirements)
- [Usage](#usage)
- [Adding a new SDK](#adding-a-new-sdk)
- [Using the setup script](#using-the-setup-script)
- [Manually](#manually)
- [Uploading the SDK](#uploading-the-sdk)
- [Publishing/Open Sourcing the SDK](#publishingopen-sourcing-the-sdk)
- [GitHub Action Secrets](#github-action-secrets)
- [Contributing](#contributing)
- [Author](#author)
- [License](#license)

## About

Expand All @@ -42,6 +48,7 @@ OpenFGA is designed to make it easy for application builders to model their perm
| Javascript | [openfga/js-sdk](https://github.com/openfga/js-sdk) | [@openfga/sdk](https://www.npmjs.com/package/@auth0/fga) on npm |
| Go | [openfga/go-sdk](https://github.com/openfga/go-sdk) | - |
| .NET | [openfga/dotnet-sdk](https://github.com/openfga/dotnet-sdk) | [OpenFga.Sdk](https://www.nuget.org/packages/OpenFga.Sdk) on nuget |
| PYTHON | [openfga/python](https://github.com/openfga/python-sdk) | [openfga-sdk](https://pypi.org/project/openfga-sdk) on PyPI |

## Getting Started

Expand All @@ -67,6 +74,7 @@ git clone git@github.com:openfga/sdk-generator.git
git clone git@github.com:openfga/go-sdk.git clients/fga-go-sdk
git clone git@github.com:openfga/js-sdk.git clients/fga-js-sdk
git clone git@github.com:openfga/dotnet-sdk.git clients/fga-dotnet-sdk
git clone git@github.com:openfga/python-sdk.git clients/fga-python-sdk
```

3. Build and test the client sdks
Expand Down Expand Up @@ -163,6 +171,9 @@ Note: Semgrep will be automatically enabled - there is nothing you need to do fo
| `DOTNET_SDK_GITHUB_ORG_ID` | The GitHub org for the SDK |
| `DOTNET_SDK_GITHUB_REPO_ID` | The GitHub repo id for the SDK |
| `DOTNET_SDK_SSH_KEY` | The SSH private deploy key for the SDK |
| `PYTHON_SDK_GITHUB_ORG_ID` | The GitHub org for the SDK |
| `PYTHON_SDK_GITHUB_REPO_ID` | The GitHub repo id for the SDK |
| `PYTHON_SDK_SSH_KEY` | The SSH private deploy key for the SDK |

The following keys are also available but should be considered deprecated. Automated release is disabled due to the complexity of generating relevant commit messages when using a generator.

Expand All @@ -186,7 +197,7 @@ In addition, we ask that the SDKs:

* be generated from the [openapiv2 swagger document](https://github.com/openfga/api/blob/main/docs/openapiv2/apidocs.swagger.json) using the sdk-generator.

* have roughly the same consistent interface for configuration, such as [JS](https://github.com/openfga/js-sdk), [GoLang](https://github.com/openfga/go-sdk) and [.NET](https://github.com/openfga/dotnet-sdk) SDKs.
* have roughly the same consistent interface for configuration, such as [JS](https://github.com/openfga/js-sdk), [GoLang](https://github.com/openfga/go-sdk), [.NET](https://github.com/openfga/dotnet-sdk) and [Python](https://github.com/openfga/python-sdk) SDKs.

* support the same features with other existing SDKs.

Expand Down
8 changes: 8 additions & 0 deletions config/clients/python/.openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
git_push.sh
test/*
!test/__init__.py
!test/test_open_fga_api.py
!test/test_credentials.py
.gitlab-ci.yml
.travis.yml
tox.ini
13 changes: 13 additions & 0 deletions config/clients/python/CHANGELOG.md.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Changelog

## v0.0.1

### [0.0.1](https://{{gitHost}}/{{gitUserId}}/{{gitRepoId}}/releases/tag/v0.0.1) (2022-08-31)

Initial OpenFGA Python SDK release
- Support for [OpenFGA](https://github.com/openfga/openfga) API
- CRUD stores
- Create, read & list authorization models
- Writing and Reading Tuples
- Checking authorization
- Using Expand to understand why access was granted
23 changes: 23 additions & 0 deletions config/clients/python/config.overrides.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"gitRepoId": "python-sdk",
"packageName": "openfga_sdk",
"packageVersion": "0.0.1",
"packageDescription": "Python SDK for OpenFGA",
"packageDetailedDescription": "This is an autogenerated python SDK for OpenFGA. It provides a wrapper around the [OpenFGA API definition](https://openfga.dev/api).",
"infoName": "OpenFGA",
"infoEmail": "community@openfga.dev",
"files": {
".github/workflows/main.yaml": {
},
".snyk": {
},
"credentials.mustache": {
"destinationFilename": "openfga_sdk/credentials.py",
"templateType": "SupportingFiles"
},
"credentials_test.mustache": {
"destinationFilename": "test/test_credentials.py",
"templateType": "SupportingFiles"
}
}
}
1 change: 1 addition & 0 deletions config/clients/python/generator.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-legacy
48 changes: 48 additions & 0 deletions config/clients/python/patches/OpenFgaApi.md.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
--- clients/fga-python-sdk/docs/OpenFgaApi.md 2022-09-13 15:41:02.000000000 -0400
+++ OpenFgaApi.md 2022-09-13 15:39:58.000000000 -0400
@@ -103,7 +103,7 @@
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

# **create_store**
-> CreateStoreResponse create_store()
+> CreateStoreResponse create_store(body)

Create a store

@@ -125,7 +125,6 @@
configuration = openfga_sdk.Configuration(
scheme = "https",
api_host = "api.fga.example",
- store_id = 'YOUR_STORE_ID',
)


@@ -134,7 +133,6 @@
configuration = openfga_sdk.Configuration(
scheme = "https",
api_host = "api.fga.example",
- store_id = 'YOUR_STORE_ID',
credentials = credentials
)

@@ -142,10 +140,11 @@
async with openfga_sdk.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = openfga_sdk.OpenFgaApi(api_client)
+ body = openfga_sdk.CreateStoreRequest() # CreateStoreRequest |

try:
# Create a store
- api_response = await api_instance.api_instance.create_store()
+ api_response = await api_instance.api_instance.create_store(body)
pprint(api_response)
except ApiException as e:
print("Exception when calling OpenFgaApi->create_store: %s\n" % e)
@@ -157,6 +156,7 @@

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
+ **body** | [**CreateStoreRequest**](CreateStoreRequest.md)| |

### Return type

68 changes: 68 additions & 0 deletions config/clients/python/patches/open_fga_api.py.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
--- clients/fga-python-sdk/openfga_sdk/api/open_fga_api.py 2022-09-13 14:15:46.000000000 -0400
+++ open_fga_api.py 2022-09-13 14:14:01.000000000 -0400
@@ -193,13 +193,15 @@
collection_formats=collection_formats,
_request_auth=local_var_params.get('_request_auth')))

- async def create_store(self, **kwargs): # noqa: E501
+ async def create_store(self, body, **kwargs): # noqa: E501
"""Create a store # noqa: E501

Create a unique OpenFGA store which will be used to store authorization models and relationship tuples. # noqa: E501

- >>> thread = await api.create_store()
+ >>> thread = await api.create_store(body)

+ :param body: (required)
+ :type body: CreateStoreRequest
:param async_req: Whether to execute the request asynchronously.
:type async_req: bool, optional
:param _preload_content: if False, the urllib3.HTTPResponse object will
@@ -216,15 +218,17 @@
:rtype: CreateStoreResponse
"""
kwargs['_return_http_data_only'] = True
- return await(self.create_store_with_http_info(**kwargs)) # noqa: E501
+ return await(self.create_store_with_http_info(body, **kwargs)) # noqa: E501

- async def create_store_with_http_info(self, **kwargs): # noqa: E501
+ async def create_store_with_http_info(self, body, **kwargs): # noqa: E501
"""Create a store # noqa: E501

Create a unique OpenFGA store which will be used to store authorization models and relationship tuples. # noqa: E501

- >>> thread = api.create_store_with_http_info()
+ >>> thread = api.create_store_with_http_info(body)

+ :param body: (required)
+ :type body: CreateStoreRequest
:param async_req: Whether to execute the request asynchronously.
:type async_req: bool, optional
:param _return_http_data_only: response data without head status code
@@ -253,6 +257,8 @@

all_params = [

+ 'body'
+
]
all_params.extend(
[
@@ -312,7 +318,7 @@
}

return await(self.api_client.call_api(
- '/stores'.replace('{store_id}', store_id), 'POST',
+ '/stores', 'POST',
path_params,
query_params,
header_params,
@@ -998,7 +1004,7 @@
}

return await(self.api_client.call_api(
- '/stores'.replace('{store_id}', store_id), 'GET',
+ '/stores', 'GET',
path_params,
query_params,
header_params,
Loading