Skip to content

Commit 9f06967

Browse files
author
Ronen Hilewicz
committed
Update dependencies and fix test for topaz 0.32+
1 parent f7d7dec commit 9f06967

12 files changed

Lines changed: 756 additions & 754 deletions

.github/workflows/ci.yaml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ on:
1515

1616
env:
1717
VAULT_ADDR: https://vault.eng.aserto.com/
18-
18+
GO_VERSION: "1.22"
1919

2020
jobs:
2121
test:
2222
name: Run test
2323
runs-on: ubuntu-latest
2424
steps:
2525
- name: Read Configuration
26-
uses: hashicorp/vault-action@v2.7.3
26+
uses: hashicorp/vault-action@v3
2727
id: vault
2828
with:
2929
url: ${{ env.VAULT_ADDR }}
@@ -39,7 +39,7 @@ jobs:
3939
git config --global url."git@github.com:".insteadOf https://github.com/
4040
4141
- name: Checkout Repo
42-
uses: actions/checkout@v2
42+
uses: actions/checkout@v4
4343

4444
- name: Set up Homebrew
4545
uses: Homebrew/actions/setup-homebrew@master
@@ -48,9 +48,9 @@ jobs:
4848
run: brew tap aserto-dev/tap && brew install aserto-dev/tap/topaz && topaz install
4949

5050
- name: Use python 3.9
51-
uses: actions/setup-python@v4
51+
uses: actions/setup-python@v5
5252
with:
53-
python-version: '3.9'
53+
python-version: '3.12'
5454

5555
- name: Install and configure Poetry
5656
uses: snok/install-poetry@v1
@@ -61,7 +61,7 @@ jobs:
6161
run: |
6262
poetry install
6363
poetry run pyright .
64-
64+
6565
- name: Run tests
6666
run: |
6767
poetry run pytest -vv
@@ -73,7 +73,7 @@ jobs:
7373
name: Release to pypi
7474
steps:
7575
- name: Read Configuration
76-
uses: hashicorp/vault-action@v2.4.1
76+
uses: hashicorp/vault-action@v3
7777
id: vault
7878
with:
7979
url: ${{ env.VAULT_ADDR }}
@@ -83,17 +83,17 @@ jobs:
8383
kv/data/pypi "API_TOKEN" | POETRY_HTTP_BASIC_PYPI_PASSWORD;
8484
8585
- name: Checkout
86-
uses: actions/checkout@v3
86+
uses: actions/checkout@v4
8787
with:
8888
fetch-depth: 0
8989

9090
- name: Setup Go
91-
uses: actions/setup-go@v2
91+
uses: actions/setup-go@v5
9292
with:
9393
go-version: ${{ env.GO_VERSION }}
9494

9595
- name: Setup caching
96-
uses: actions/cache@v2
96+
uses: actions/cache@v4
9797
with:
9898
path: |
9999
~/.cache/go-build
@@ -119,9 +119,9 @@ jobs:
119119
go run mage.go deps
120120
121121
- name: Set up Python
122-
uses: actions/setup-python@v4
122+
uses: actions/setup-python@v5
123123
with:
124-
python-version: '3.10'
124+
python-version: '3.12'
125125

126126
- name: Install Poetry
127127
uses: snok/install-poetry@v1

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module github.com/aserto-dev/python-authorizer
22

3-
go 1.19
3+
go 1.22
44

55
require github.com/magefile/mage v1.14.0

poetry.lock

Lines changed: 668 additions & 114 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ packages = [
2929

3030
[tool.poetry.dependencies]
3131
python = "^3.8"
32-
aiohttp = "^3.8.0"
33-
grpcio = "^1.49.0"
34-
protobuf = "^4.21.0"
35-
aserto-authorizer = "^0.20.2"
36-
aserto-directory = "^0.31.3"
32+
aiohttp = "^3.9.5"
33+
grpcio = "^1.64.1"
34+
protobuf = "^5.27.2"
35+
aserto-authorizer = "^0.20.3"
36+
aserto-directory = "^0.31.4"
3737

3838
[tool.poetry.dev-dependencies]
3939
black = "^23.0"
4040
isort= "^5.9.0"
41-
pytest-asyncio = "^0.15.0"
41+
pytest-asyncio = "^0.23"
4242
pyright = "^1.1.0"
4343
requests = "^2.31.0"
4444

src/aserto/client/directory/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
from typing import Literal, Tuple
2+
23
from aserto.client.directory.channels import Channels
34

45
__all__ = ["Channels"]
56

7+
68
class NotFoundError(Exception):
79
pass
810

11+
912
class ConfigError(Exception):
1013
pass
1114

12-
Header = Literal["authorization", "aserto-tenant-id", "if-match", "if-none-match"]
13-
1415

15-
def get_metadata(api_key, tenant_id) -> Tuple[Tuple[Header, str], ...]:
16-
md: Tuple[Tuple[Header, str], ...] = ()
16+
def get_metadata(api_key, tenant_id) -> Tuple[Tuple[str, str], ...]:
17+
md: Tuple[Tuple[str, str], ...] = ()
1718
if api_key:
1819
md += (("authorization", f"basic {api_key}"),)
1920
if tenant_id:

test/conftest.py

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,27 @@ def stop() -> None:
4545
@staticmethod
4646
def import_data(path: str) -> None:
4747
subprocess.run(
48-
f"topaz import -i -d {path}",
48+
f"topaz ds import -i -d {path}",
4949
shell=True,
5050
capture_output=True,
5151
check=True,
5252
)
5353

54-
def set_manifest(self, manifest_path: str) -> None:
55-
with open(manifest_path, "r") as f:
56-
manifest = f.read()
57-
resp = requests.post(
58-
f"https://{self.directory_gw.address}/api/v3/directory/manifest",
59-
data=manifest,
60-
verify=self.directory_gw.ca_cert_path,
54+
@staticmethod
55+
def set_manifest(manifest_path: str) -> None:
56+
subprocess.run(
57+
f"topaz ds delete manifest --force",
58+
shell=True,
59+
capture_output=True,
60+
check=True,
61+
)
62+
63+
subprocess.run(
64+
f"topaz ds set manifest {manifest_path}",
65+
shell=True,
66+
capture_output=True,
67+
check=True,
6168
)
62-
resp.raise_for_status()
6369

6470
def wait_for_ready(self) -> None:
6571
t0 = datetime.now()
@@ -93,27 +99,21 @@ def topaz():
9399

94100
time.sleep(1)
95101

96-
subprocess.run(
97-
"rm ~/.config/topaz/db/directory.db",
98-
shell=True,
99-
capture_output=True,
100-
check=True,
101-
)
102-
103102
if os.path.exists(f"{topaz_db_dir}/directory.bak"):
104103
os.rename(f"{topaz_db_dir}/directory.bak", f"{topaz_db_dir}/directory.db")
105104

106105

107106
def topaz_configure() -> Topaz:
108107
subprocess.run(
109-
"topaz configure -r ghcr.io/aserto-policies/policy-todo:3 -n todo -d -f --enable-v2",
108+
"topaz config new -r ghcr.io/aserto-policies/policy-todo:3 -n todo -d -f",
110109
shell=True,
111110
capture_output=True,
112111
check=True,
113112
)
114113

115-
ca_cert_path_grpc = os.path.expanduser("~/.config/topaz/certs/grpc-ca.crt")
116-
ca_cert_path_gw = os.path.expanduser("~/.config/topaz/certs/gateway-ca.crt")
114+
cert_path = topaz_cert_path()
115+
ca_cert_path_grpc = os.path.join(cert_path, "grpc-ca.crt")
116+
ca_cert_path_gw = os.path.join(cert_path, "gateway-ca.crt")
117117

118118
return Topaz(
119119
authorizer=Service("localhost:8282", ca_cert_path=ca_cert_path_grpc),
@@ -122,6 +122,16 @@ def topaz_configure() -> Topaz:
122122
)
123123

124124

125+
def topaz_cert_path() -> str:
126+
proc = subprocess.run(
127+
"topaz config info | jq .config.topaz_certs_dir -r",
128+
shell=True,
129+
check=True,
130+
capture_output=True,
131+
)
132+
return proc.stdout.decode().strip()
133+
134+
125135
def connect(svc: Service) -> grpc.Channel:
126136
return grpc.secure_channel(
127137
target=svc.address, credentials=grpc.ssl_channel_credentials(read_cert(svc.ca_cert_path))

test/test_authorizer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def make_decision_request(client: AuthorizerClient) -> Dict[str, bool]:
3939

4040

4141
def test_decision_tree_grpc(authorizer) -> None:
42-
print("foobar")
4342
expected = {
4443
"todoApp.DELETE.todos.__id": {"allowed": False},
4544
"todoApp.GET.todos": {"allowed": True},

test/test_authorizer_async.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
1-
import asyncio
21
from typing import Dict
32

43
import pytest
4+
import pytest_asyncio
55

66
from aserto.client import AuthorizerOptions, Identity
77
from aserto.client.authorizer.aio import AuthorizerClient, DecisionTree, IdentityType
88

99

10-
@pytest.fixture(scope="session")
11-
def event_loop():
12-
"""Overrides pytest default function scoped event loop"""
13-
policy = asyncio.get_event_loop_policy()
14-
loop = policy.new_event_loop()
15-
yield loop
16-
loop.close()
17-
18-
19-
@pytest.fixture(scope="module")
10+
@pytest_asyncio.fixture(scope="module")
2011
async def authorizer(topaz):
2112
client = AuthorizerClient(
2213
identity=Identity(type=IdentityType.IDENTITY_TYPE_NONE),
@@ -48,7 +39,7 @@ async def make_decision_request(client: AuthorizerClient) -> Dict[str, bool]:
4839
)
4940

5041

51-
@pytest.mark.asyncio
42+
@pytest.mark.asyncio(scope="module")
5243
async def test_decision_tree_grpc(authorizer: AuthorizerClient) -> None:
5344
expected = {
5445
"todoApp.DELETE.todos.__id": {"allowed": False},
@@ -63,7 +54,7 @@ async def test_decision_tree_grpc(authorizer: AuthorizerClient) -> None:
6354
assert result == expected
6455

6556

66-
@pytest.mark.asyncio
57+
@pytest.mark.asyncio(scope="module")
6758
async def test_decision_grpc(authorizer: AuthorizerClient) -> None:
6859
result = await make_decision_request(authorizer)
6960

0 commit comments

Comments
 (0)