Skip to content

Commit 4fc7e8c

Browse files
authored
Merge pull request #22 from jzelinskie/v1-init
Generate v1 APIs
2 parents cc4f362 + 050249e commit 4fc7e8c

40 files changed

+4110
-287
lines changed
Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,21 @@
1-
name: Publish Python 🐍 distributions 📦 to PyPI and TestPyPI
2-
on: push
1+
---
2+
name: "Publish to PyPI"
3+
on: "push"
34
jobs:
4-
build-n-publish:
5-
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
6-
runs-on: ubuntu-18.04
5+
publish:
6+
name: "Build & Publish"
7+
runs-on: "ubuntu-latest"
78
steps:
8-
- uses: actions/checkout@master
9-
- name: Set up Python 3.7
10-
uses: actions/setup-python@v1
11-
with:
12-
python-version: 3.7
13-
- name: Install pypa/build
14-
run: >-
15-
python -m
16-
pip install
17-
build
18-
--user
19-
- name: Build a binary wheel and a source tarball
20-
run: >-
21-
python -m
22-
build
23-
--sdist
24-
--wheel
25-
--outdir dist/
26-
.
27-
- name: Publish distribution 📦 to PyPI
28-
if: startsWith(github.ref, 'refs/tags')
29-
uses: pypa/gh-action-pypi-publish@release/v1
30-
with:
31-
password: ${{ secrets.PYPI_API_TOKEN }}
9+
- uses: "actions/checkout@v2"
10+
- uses: "actions/setup-python@v1"
11+
with:
12+
python-version: "3.6"
13+
- name: "Install pypa/build"
14+
run: "python -m pip install build --user"
15+
- name: "Build wheel and source tarball"
16+
run: "python -m build --sdist --wheel --outdir dist/ ."
17+
- name: "Publish"
18+
if: "startsWith(github.ref, 'refs/tags')"
19+
uses: "pypa/gh-action-pypi-publish@release/v1"
20+
with:
21+
password: "${{ secrets.PYPI_API_TOKEN }}"

.github/workflows/test.yaml

Lines changed: 85 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,103 @@
1-
name: Test
1+
---
2+
name: "Test"
23
on:
34
push:
45
branches:
5-
- "master"
6+
- "!dependabot/*"
7+
- "*"
68
pull_request:
79
branches:
8-
- "*"
10+
- "*"
911
jobs:
1012
lint:
11-
name: Format & Lint
12-
runs-on: ubuntu-latest
13+
name: "Format & Lint"
14+
runs-on: "ubuntu-latest"
1315
strategy:
1416
fail-fast: false
1517
steps:
16-
17-
- uses: actions/checkout@v2
18-
- name: Set up Python 3.8
19-
uses: actions/setup-python@v1
20-
with:
21-
python-version: 3.8
22-
- name: Setup Python Environment
23-
run: pip install -U pip virtualenv
24-
25-
- name: Install Dependencies
26-
run: |
27-
virtualenv ~/.cache/virtualenv/authzedpy
28-
source ~/.cache/virtualenv/authzedpy/bin/activate
29-
pip install poetry
30-
poetry env info
31-
poetry install
32-
- name: Check for Lint
33-
run: |
34-
source ~/.cache/virtualenv/authzedpy/bin/activate
35-
find . -name "*.py" | grep -v "_pb2" | xargs pyflakes
36-
- name: Check Formatting
37-
run: |
38-
source ~/.cache/virtualenv/authzedpy/bin/activate
39-
black --check --diff .
40-
- name: Checking Imports Ordering
41-
run: |
42-
source ~/.cache/virtualenv/authzedpy/bin/activate
43-
find . -name "*.py" | grep -v "_pb2" | xargs isort --check --diff
18+
- uses: "actions/checkout@v2"
19+
- uses: "bewuethr/yamllint-action@v1.1.1"
20+
with:
21+
config-file: ".yamllint"
22+
- uses: "actions/setup-python@v1"
23+
with:
24+
python-version: "3.8"
25+
- name: "Setup Python Environment"
26+
run: "pip install -U pip virtualenv"
27+
- name: "Install Dependencies"
28+
run: |
29+
virtualenv ~/.cache/virtualenv/authzedpy
30+
source ~/.cache/virtualenv/authzedpy/bin/activate
31+
pip install poetry
32+
poetry env info
33+
poetry install
34+
- name: "Pyflakes"
35+
run: |
36+
source ~/.cache/virtualenv/authzedpy/bin/activate
37+
find . -name "*.py" | grep -v "_pb2" | xargs pyflakes
38+
- name: "Blacken"
39+
run: |
40+
source ~/.cache/virtualenv/authzedpy/bin/activate
41+
black --check --diff .
42+
- name: "Isort"
43+
run: |
44+
source ~/.cache/virtualenv/authzedpy/bin/activate
45+
find . -name "*.py" | grep -v "_pb2" | xargs isort --check --diff
4446
4547
pytest:
46-
name: Unit Tests
47-
runs-on: ubuntu-latest
48+
name: "Unit Tests"
49+
runs-on: "ubuntu-latest"
4850
strategy:
4951
matrix:
50-
python-version: [3.6, 3.7, 3.8, 3.9]
52+
python-version:
53+
- "3.6"
54+
- "3.7"
55+
- "3.8"
56+
- "3.9"
5157
steps:
52-
- uses: actions/checkout@v2
53-
- name: Set up Python ${{ matrix.python-version }}
54-
uses: actions/setup-python@v2
55-
with:
56-
python-version: ${{ matrix.python-version }}
57-
- name: Setup Python Environment
58-
run: pip install -U pip virtualenv
59-
60-
- name: Install Dependencies
61-
run: |
62-
virtualenv ~/.cache/virtualenv/authzedpy
63-
source ~/.cache/virtualenv/authzedpy/bin/activate
64-
pip install poetry
65-
poetry env info
66-
poetry install
67-
- name: Pytest
68-
run: |
69-
source ~/.cache/virtualenv/authzedpy/bin/activate
70-
pytest -vv .
58+
- uses: "actions/checkout@v2"
59+
- uses: "actions/setup-python@v2"
60+
with:
61+
python-version: "${{ matrix.python-version }}"
62+
- name: "Setup Python Environment"
63+
run: "pip install -U pip virtualenv"
64+
- name: "Install Dependencies"
65+
run: |
66+
virtualenv ~/.cache/virtualenv/authzedpy
67+
source ~/.cache/virtualenv/authzedpy/bin/activate
68+
pip install poetry
69+
poetry env info
70+
poetry install
71+
- name: "Pytest"
72+
run: |
73+
source ~/.cache/virtualenv/authzedpy/bin/activate
74+
pytest -vv .
7175
7276
protobuf:
73-
name: Generate & Diff
74-
runs-on: ubuntu-latest
77+
name: "Generate & Diff"
78+
runs-on: "ubuntu-latest"
7579
steps:
76-
- uses: actions/checkout@v2
77-
- name: Set up Python 3.6
78-
uses: actions/setup-python@v1
79-
with:
80-
python-version: 3.6
81-
- name: Setup Python Environment
82-
run: pip install -U pip virtualenv
83-
- name: Install Homebrew & gRPC
84-
run: |
85-
bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
86-
brew install grpc
87-
- uses: bufbuild/buf-setup-action@v0.1.0
88-
with:
89-
version: '0.43.2'
90-
91-
- name: Install Python Dependencies
92-
run: |
93-
virtualenv ~/.cache/virtualenv/authzedpy
94-
source ~/.cache/virtualenv/authzedpy/bin/activate
95-
pip install poetry
96-
poetry env info
97-
poetry install
98-
99-
- name: Generate & Diff Protos
100-
run: |
101-
source ~/.cache/virtualenv/authzedpy/bin/activate
102-
./buf.gen.yaml
103-
bash -c '[ $(git status --porcelain | tee /dev/fd/2 | wc -c) -eq 0 ]'
80+
- uses: "actions/checkout@v2"
81+
- uses: "actions/setup-python@v1"
82+
with:
83+
python-version: "3.6"
84+
- name: "Setup Python Environment"
85+
run: "pip install -U pip virtualenv"
86+
- name: "Install Homebrew & gRPC"
87+
run: |
88+
bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
89+
brew install grpc
90+
- uses: "bufbuild/buf-setup-action@v0.5.0"
91+
with:
92+
version: "0.56.0"
93+
- name: "Install Python Dependencies"
94+
run: |
95+
virtualenv ~/.cache/virtualenv/authzedpy
96+
source ~/.cache/virtualenv/authzedpy/bin/activate
97+
pip install poetry
98+
poetry env info
99+
poetry install
100+
- name: "Generate & Diff Protos"
101+
run: |
102+
source ~/.cache/virtualenv/authzedpy/bin/activate
103+
./buf.gen.yaml && git diff && bash -c '[ $(git status --porcelain | tee /dev/fd/2 | wc -c) -eq 0 ]'

.yamllint

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# vim: ft=yaml
2+
---
3+
yaml-files:
4+
- "*.yaml"
5+
- "*.yml"
6+
- ".yamllint"
7+
extends: "default"
8+
rules:
9+
quoted-strings: "enable"
10+
line-length: "disable"

README.md

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This repository houses the Python client library for Authzed.
1414
Developers create a schema that models their permissions requirements and use a client library, such as this one, to apply the schema to the database, insert data into the database, and query the data to efficiently check permissions in their applications.
1515

1616
Supported client API versions:
17+
- [v1](https://docs.authzed.com/reference/api#authzedapiv1)
1718
- [v1alpha1](https://docs.authzed.com/reference/api#authzedapiv1alpha1)
1819
- [v0](https://docs.authzed.com/reference/api#authzedapiv0)
1920
- "arrakisclient" - a deprecated ORM for v0
@@ -63,9 +64,10 @@ In order to successfully connect, you will have to provide a [Bearer Token] with
6364
[Authzed Dashboard]: https://app.authzed.com
6465

6566
```py
66-
from authzed.api.v0 import Client
67+
from authzed.api.v1 import Client
6768
from grpcutil import bearer_token_credentials
6869

70+
6971
client = Client(
7072
"grpc.authzed.com:443",
7173
bearer_token_credentials("t_your_token_here_1234567deadbeef"),
@@ -75,17 +77,25 @@ client = Client(
7577
### Performing an API call
7678

7779
```py
78-
from authzed.api.v0 import CheckRequest, ObjectAndRelation, User
80+
from authzed.api.v1 import (
81+
CheckPermissionRequest,
82+
CheckPermissionResponse,
83+
ObjectReference,
84+
SubjectReference,
85+
)
7986

8087

81-
emilia = User("blog/user", "emilia")
82-
read_first_post = ObjectAndRelation(
83-
namespace="blog/post",
84-
object_id="1",
85-
relation="read",
86-
)
88+
post_one = ObjectReference(object_type="blog/post", object_id="1")
89+
emilia = SubjectReference(object=ObjectReference(
90+
object_type="blog/user",
91+
object_id="emilia",
92+
))
8793

8894
# Is Emilia in the set of users that can read post #1?
89-
resp = client.Check(CheckRequest(user=emilia, test_userset=read_first_post))
90-
assert resp.is_member
95+
resp = client.CheckPermission(CheckPermissionRequest(
96+
resource=post_one,
97+
permission="reader",
98+
subject=emilia,
99+
))
100+
assert resp.permissionship == CheckPermissionResponse.PERMISSIONSHIP_HAS_PERMISSION
91101
```

0 commit comments

Comments
 (0)