Skip to content

Commit 5d4209e

Browse files
committed
🚨 Fix linting issues
1 parent 2d08678 commit 5d4209e

File tree

8 files changed

+37
-34
lines changed

8 files changed

+37
-34
lines changed

README.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,23 +151,23 @@ Do this as follows:
151151

152152
- Create a new `Client` in your `Keycloak` instance.
153153
- Under `General Settings`:
154-
- Client type: `OpenID Connect`
155-
- Client name: `apricot`
154+
- Client type: `OpenID Connect`
155+
- Client name: `apricot`
156156
- Under `Capability config`
157157
- Enable `Client authentication`
158158
- Enable the following authentication flows and disable the rest:
159159
- `Direct access grants`
160160
- `Service accounts roles`
161161
- Save the client
162162
- For the client you have just created
163-
- Under `Credentials` copy `client secret`
164-
- Under `Service accounts roles`:
165-
- Click on `Assign role` then `Filter by clients`
166-
- Assign the following roles:
167-
- `realm-management` > `view-users`
168-
- `realm-management` > `manage-users`
169-
- `realm-management` > `query-groups`
170-
- `realm-management` > `query-users`
163+
- Under `Credentials` copy `client secret`
164+
- Under `Service accounts roles`:
165+
- Click on `Assign role` then `Filter by clients`
166+
- Assign the following roles:
167+
- `realm-management` > `view-users`
168+
- `realm-management` > `manage-users`
169+
- `realm-management` > `query-groups`
170+
- `realm-management` > `query-users`
171171

172172
## Disabling Apricot groups
173173

@@ -203,7 +203,6 @@ member: CN=sherlock.holmes,OU=users,DC=example,DC=com
203203

204204
:exclamation: You can disable the creation of these groups with the `--disable-primary-groups` command line option :exclamation:
205205

206-
207206
## Mirrored groups
208207

209208
Apricot creates a group-of-groups for each group of users.

apricot/apricot_server.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22

33
import inspect
44
import sys
5-
from typing import Any, Self, cast
5+
from typing import TYPE_CHECKING, Any, Self, cast
66

77
from twisted.internet import reactor, task
88
from twisted.internet.endpoints import quoteStringArgument, serverFromString
9-
from twisted.internet.interfaces import IReactorCore, IStreamServerEndpoint
109
from twisted.python import log
1110

1211
from apricot.cache import LocalCache, RedisCache, UidCache
1312
from apricot.ldap import OAuthLDAPServerFactory
1413
from apricot.oauth import OAuthBackend, OAuthClientMap, OAuthDataAdaptor
1514

15+
if TYPE_CHECKING:
16+
from twisted.internet.interfaces import IReactorCore, IStreamServerEndpoint
17+
1618

1719
class ApricotServer:
1820
"""The Apricot server running via Twisted."""
@@ -139,7 +141,7 @@ def __init__(
139141
ssl_endpoint.listen(factory)
140142

141143
# Load the Twisted reactor
142-
self.reactor = cast(IReactorCore, reactor)
144+
self.reactor = cast("IReactorCore", reactor)
143145

144146
def run(self: Self) -> None:
145147
"""Start the Twisted reactor."""

apricot/cache/redis_cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ def set(self: Self, identifier: str, uid_value: int) -> None:
4242
self.cache.set(identifier, uid_value)
4343

4444
def values(self: Self, keys: list[str]) -> list[int]:
45-
return [int(cast(str, v)) for v in self.cache.mget(keys)]
45+
return [int(cast("str", v)) for v in self.cache.mget(keys)]

apricot/cache/uid_cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def get_uid(
5555
min_value = min_value or 0
5656
next_uid = max(self._get_max_uid(category) + 1, min_value)
5757
self.set(identifier_, next_uid)
58-
return cast(int, self.get(identifier_))
58+
return cast("int", self.get(identifier_))
5959

6060
def _get_max_uid(self: Self, category: str | None) -> int:
6161
"""Get maximum UID for a given category.

apricot/ldap/oauth_ldap_entry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def add_child(
7575
except LDAPEntryAlreadyExists:
7676
log.msg(f"Refusing to add child '{rdn.getText()}' as it already exists.")
7777
output = self._children[rdn.getText()]
78-
return cast(OAuthLDAPEntry, output)
78+
return cast("OAuthLDAPEntry", output)
7979

8080
def bind(self: Self, password: bytes) -> defer.Deferred[OAuthLDAPEntry]:
8181
def _bind(password: bytes) -> OAuthLDAPEntry:
@@ -89,4 +89,4 @@ def _bind(password: bytes) -> OAuthLDAPEntry:
8989
return defer.maybeDeferred(_bind, password)
9090

9191
def list_children(self: Self) -> list[OAuthLDAPEntry]:
92-
return [cast(OAuthLDAPEntry, entry) for entry in self._children.values()]
92+
return [cast("OAuthLDAPEntry", entry) for entry in self._children.values()]

apricot/oauth/keycloak_client.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
from __future__ import annotations
22

33
import operator
4-
from typing import Any, Self, cast
4+
from typing import TYPE_CHECKING, Any, Self, cast
55

66
from twisted.python import log
77

8-
from apricot.typedefs import JSONDict
9-
108
from .oauth_client import OAuthClient
119

10+
if TYPE_CHECKING:
11+
from apricot.typedefs import JSONDict
12+
1213

1314
class KeycloakClient(OAuthClient):
1415
"""OAuth client for the Keycloak backend."""
@@ -56,7 +57,7 @@ def groups(self: Self) -> list[JSONDict]:
5657
f"{self.base_url}/admin/realms/{self.realm}/groups?first={len(group_data)}&max={self.max_rows}&briefRepresentation=false",
5758
use_client_secret=False,
5859
):
59-
group_data.extend(cast(list[JSONDict], data))
60+
group_data.extend(cast("list[JSONDict]", data))
6061
if len(data) != self.max_rows:
6162
break
6263

@@ -99,7 +100,7 @@ def groups(self: Self) -> list[JSONDict]:
99100
use_client_secret=False,
100101
)
101102
attributes["memberUid"] = [
102-
user["username"] for user in cast(list[JSONDict], members)
103+
user["username"] for user in cast("list[JSONDict]", members)
103104
]
104105
output.append(attributes)
105106
except KeyError as exc:
@@ -115,7 +116,7 @@ def users(self: Self) -> list[JSONDict]:
115116
f"{self.base_url}/admin/realms/{self.realm}/users?first={len(user_data)}&max={self.max_rows}&briefRepresentation=false",
116117
use_client_secret=False,
117118
):
118-
user_data.extend(cast(list[JSONDict], data))
119+
user_data.extend(cast("list[JSONDict]", data))
119120
if len(data) != self.max_rows:
120121
break
121122

apricot/oauth/microsoft_entra_client.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
from __future__ import annotations
22

33
import operator
4-
from typing import Any, Self, cast
4+
from typing import TYPE_CHECKING, Any, Self, cast
55

66
from twisted.python import log
77

8-
from apricot.typedefs import JSONDict
9-
108
from .oauth_client import OAuthClient
119

10+
if TYPE_CHECKING:
11+
from apricot.typedefs import JSONDict
12+
1213

1314
class MicrosoftEntraClient(OAuthClient):
1415
"""OAuth client for the Microsoft Entra backend."""
@@ -50,7 +51,7 @@ def groups(self: Self) -> list[JSONDict]:
5051
f"https://graph.microsoft.com/v1.0/groups?$select={','.join(queries)}",
5152
)
5253
for group_dict in cast(
53-
list[JSONDict],
54+
"list[JSONDict]",
5455
sorted(group_data["value"], key=operator.itemgetter("createdDateTime")),
5556
):
5657
try:
@@ -92,7 +93,7 @@ def users(self: Self) -> list[JSONDict]:
9293
f"https://graph.microsoft.com/v1.0/users?$select={','.join(queries)}",
9394
)
9495
for user_dict in cast(
95-
list[JSONDict],
96+
"list[JSONDict]",
9697
sorted(user_data["value"], key=operator.itemgetter("createdDateTime")),
9798
):
9899
# Get user attributes

pyproject.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@ strict = true # enable all optional error checking flags
168168

169169
[[tool.mypy.overrides]]
170170
module = [
171-
"ldaptor.*",
172-
"pydantic.*",
173-
"requests_oauthlib.*",
174-
"twisted.*",
175-
"zope.interface.*",
171+
"ldaptor.*",
172+
"pydantic.*",
173+
"requests_oauthlib.*",
174+
"twisted.*",
175+
"zope.interface.*",
176176
]
177177
ignore_missing_imports = true

0 commit comments

Comments
 (0)