Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit fa93250

Browse files
add github actions
1 parent 508420e commit fa93250

16 files changed

+112
-28
lines changed

.github/workflows/setup.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# This workflow will install Python dependencies, run tests and lint
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
4+
name: CI
5+
6+
on:
7+
push:
8+
branches: [ "develop" ]
9+
pull_request:
10+
branches: [ "develop" ]
11+
12+
jobs:
13+
cpython:
14+
runs-on: ${{ matrix.os }}
15+
strategy:
16+
matrix:
17+
os:
18+
- ubuntu-latest
19+
python-version:
20+
- "3.10"
21+
- "3.11"
22+
- "3.12"
23+
24+
steps:
25+
- uses: actions/checkout@v4
26+
- name: Set up ${{ matrix.python-version }} on ${{ matrix.os }}
27+
uses: actions/setup-python@v5
28+
with:
29+
python-version: ${{ matrix.python-version }}
30+
31+
- name: Install dependencies
32+
run: |
33+
python -m pip install --upgrade pip
34+
pip install .[dev]
35+
36+
- name: Run ruff
37+
run: |
38+
ruff check .
39+
40+
- name: Run mypy
41+
run: |
42+
mypy src

.ruff.toml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
line-length = 79
2+
target-version = "py310"
3+
src = ["src"]
4+
5+
include = ["src/**.py"]
6+
lint.select = ["ALL"]
7+
lint.ignore = [
8+
"ARG",
9+
"ANN",
10+
"D",
11+
"EM101",
12+
"EM102",
13+
"PT001",
14+
"PT023",
15+
"SIM108",
16+
"SIM114",
17+
"TRY003",
18+
"TCH003",
19+
"PLW2901",
20+
"RET505",
21+
"PLR0913",
22+
"UP038",
23+
"TCH001",
24+
"SIM103",
25+
"PERF401",
26+
"PLR2004",
27+
"PYI034",
28+
]

pyproject.toml

+8-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ requires = ["setuptools>=75.2.0"]
33
build-backend = "setuptools.build_meta"
44

55
[project]
6-
name = 'aiokycloak'
6+
name = 'aiokeycloak'
77
description = ''
88
requires-python = '>= 3.10.0'
99
version = '0.0.1'
@@ -17,8 +17,14 @@ dependencies = [
1717

1818
[project.optional-dependencies]
1919
aiohttp = ['aiohttp==3.10.0']
20+
integrations = [
21+
'aiokeycloak[aiohttp]',
22+
]
2023
linters = [
2124
'mypy==1.12.1',
2225
'ruff==0.7.0',
2326
]
24-
dev = ['aiokycloak[linters]']
27+
dev = [
28+
'aiokeycloak[linters]',
29+
'aiokeycloak[integrations]'
30+
]

src/aiokeycloak/client.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
from typing import Any, TypeVar
44
from uuid import UUID
55

6-
from aiokeycloak.methods.assign_realm_roles_to_user import AssignRealmRolesToUser
6+
from aiokeycloak.methods.assign_realm_roles_to_user import (
7+
AssignRealmRolesToUser,
8+
)
79
from aiokeycloak.methods.base import KeycloakMethod
810
from aiokeycloak.methods.create_user import CreateUser
911
from aiokeycloak.methods.delete_user import DeleteUser
@@ -23,7 +25,6 @@
2325
from aiokeycloak.types.user import User
2426
from aiokeycloak.types.users import Users
2527

26-
2728
T = TypeVar("T", bound=KeycloakType)
2829

2930

@@ -47,14 +48,14 @@ async def get_realms_roles(
4748
self,
4849
realm_name: str,
4950
*,
50-
max: int | None = None,
51+
max_: int | None = None,
5152
first: int | None = None,
5253
search: str | None = None,
5354
brief_representation: bool | None = None,
5455
) -> RealmRoles:
5556
method = GetRealmRoles(
5657
realm_name=realm_name,
57-
max=max,
58+
max=max_,
5859
first=first,
5960
search=search,
6061
access_token=self._access_token,
@@ -119,7 +120,7 @@ async def get_users(
119120
first: int | None = None,
120121
first_name: str | None = None,
121122
last_name: str | None = None,
122-
max: int | None = None,
123+
max_: int | None = None,
123124
username: str | None = None,
124125
) -> Users:
125126
method = GetUsers(
@@ -133,7 +134,7 @@ async def get_users(
133134
first=first,
134135
first_name=first_name,
135136
last_name=last_name,
136-
max=max,
137+
max=max_,
137138
username=username,
138139
)
139140
return await self.send_request(method)

src/aiokeycloak/methods/assign_realm_roles_to_user.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class AssignRealmRolesToUser(KeycloakMethod[Success]):
2323
def build_request_context(self) -> RequestContext:
2424
return RequestContext(
2525
body=[
26-
{"name": realm_role_name} for realm_role_name in self.realm_roles_names
26+
{"name": realm_role_name}
27+
for realm_role_name in self.realm_roles_names
2728
],
2829
url_format={
2930
"realm_name": self.realm_name,

src/aiokeycloak/methods/base.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from abc import abstractmethod
22
from dataclasses import dataclass
3-
from enum import auto, StrEnum
3+
from enum import StrEnum, auto
44
from typing import Any, Protocol, TypeVar
55

66
from aiokeycloak.types.base import KeycloakType
77

8-
98
T = TypeVar("T", bound=KeycloakType)
109

1110

src/aiokeycloak/methods/get_users.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,7 @@ def build_request_context(self) -> RequestContext:
5050
"Content-Type": "application/json",
5151
"Authorization": f"Bearer {self.access_token}",
5252
},
53-
query_parameters={data[0]: data[1] for data in query_parameters if data[1]},
53+
query_parameters={
54+
data[0]: data[1] for data in query_parameters if data[1]
55+
},
5456
)

src/aiokeycloak/sessions/aiohttp.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ def _load_http_method(self, http_method: HTTPMethodType) -> AioHTTPMethod:
3636
elif http_method == HTTPMethodType.DELETE:
3737
return self._client_session.delete
3838
else:
39-
raise ValueError("Unknown http method %r" % http_method)
39+
msg = f"Unknown http method {http_method!r}"
40+
raise ValueError(msg)
4041

4142
async def _send_request(
4243
self,

src/aiokeycloak/sessions/base.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from abc import abstractmethod
22
from asyncio import Protocol
33
from dataclasses import dataclass
4-
from typing import Any, cast, TypeVar
4+
from typing import Any, TypeVar, cast
55

66
from aiokeycloak.errors import (
77
KeycloakError,
@@ -11,7 +11,6 @@
1111
from aiokeycloak.methods.base import HTTPMethodType, KeycloakMethod
1212
from aiokeycloak.types.base import FromResponse, KeycloakType
1313

14-
1514
T = TypeVar("T", bound=KeycloakType)
1615

1716

@@ -34,10 +33,10 @@ class ResponseDS:
3433

3534
def error_handling(response: ResponseDS) -> None:
3635
if not isinstance(response.body, dict):
37-
return None
36+
return
3837

3938
if response.http_status < 400:
40-
return None
39+
return
4140

4241
error: str = (
4342
response.body.get("error")
@@ -52,16 +51,18 @@ def error_handling(response: ResponseDS) -> None:
5251
"http_status": response.http_status,
5352
}
5453
if "Unauthorized" in error:
54+
msg = f"Unauthorized client. {error}"
5555
raise UnauthorizedError(
56-
"Unauthorized client. %s" % error,
56+
msg,
5757
**error_data,
5858
)
5959

6060
if "User exists" in error:
6161
raise UserExistsError(error, **error_data)
6262

63+
msg = f"An error has occurred. Url {response.url!r}. {error!r}."
6364
raise KeycloakError(
64-
"An error has occurred. Url %r. %r." % (response.url, error),
65+
msg,
6566
**error_data,
6667
)
6768

src/aiokeycloak/token_decoders/access.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import json
2-
from typing import Any, cast, Final
2+
from typing import Any, Final, cast
33

44
from jwcrypto import jwk, jwt # type: ignore[import-untyped]
55

6-
76
BEGIN_PUBLIC_KEY: Final = "-----BEGIN PUBLIC KEY-----\n"
87
END_PUBLIC_KEY: Final = "\n-----END PUBLIC KEY-----"
98

@@ -13,7 +12,11 @@ def __init__(self, access_token: str) -> None:
1312
self._access_token = access_token
1413

1514
def decode(
16-
self, public_key: str, validate: bool = True, **kwargs: Any
15+
self,
16+
public_key: str,
17+
*,
18+
validate: bool = True,
19+
**kwargs: Any,
1720
) -> dict[str, Any]:
1821
if not validate:
1922
full_jwt = jwt.JWT(jwt=self._access_token, **kwargs)

src/aiokeycloak/types/access_token.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from enum import StrEnum
55
from typing import Any
66

7-
from adaptix import name_mapping, Retort
7+
from adaptix import Retort, name_mapping
88

99
from aiokeycloak.types.base import FromResponse, KeycloakType
1010

src/aiokeycloak/types/realm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from dataclasses import dataclass
22

3-
from adaptix import name_mapping, Retort
3+
from adaptix import Retort, name_mapping
44

55
from aiokeycloak.types.base import FromResponse, KeycloakType
66

src/aiokeycloak/types/realm_role.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import Any, cast
55
from uuid import UUID
66

7-
from adaptix import name_mapping, NameStyle, Retort
7+
from adaptix import NameStyle, Retort, name_mapping
88

99
from aiokeycloak.types.base import FromResponse, KeycloakType
1010

src/aiokeycloak/types/realm_roles.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
from dataclasses import dataclass
44

5-
from aiokeycloak.types.realm_role import RealmRole
65
from aiokeycloak.types.base import FromResponse, KeycloakType
6+
from aiokeycloak.types.realm_role import RealmRole
77

88

99
@dataclass(frozen=True, slots=True)

src/aiokeycloak/types/user.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import Any, cast
55
from uuid import UUID
66

7-
from adaptix import name_mapping, NameStyle, Retort
7+
from adaptix import NameStyle, Retort, name_mapping
88

99
from aiokeycloak.types.base import FromResponse, KeycloakType
1010

src/aiokeycloak/types/users.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def from_response(
2222
FromResponse(
2323
body=body,
2424
headers=data.headers,
25-
)
25+
),
2626
),
2727
)
2828
return cls(users=users)

0 commit comments

Comments
 (0)