Skip to content

Commit de07cca

Browse files
committed
🚨 Additional linting fixes
1 parent 0aca60f commit de07cca

File tree

5 files changed

+42
-34
lines changed

5 files changed

+42
-34
lines changed

apricot/apricot_server.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ def __init__(
4848
if self.debug:
4949
log.msg(f"Creating an OAuthClient for {backend}.")
5050
oauth_backend = OAuthClientMap[backend]
51-
oauth_backend_args = inspect.getfullargspec(oauth_backend.__init__).args
51+
oauth_backend_args = inspect.getfullargspec(
52+
oauth_backend.__init__ # type: ignore
53+
).args
5254
oauth_client = oauth_backend(
5355
client_id=client_id,
5456
client_secret=client_secret,

apricot/ldap/oauth_ldap_server_factory.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ def __init__(
1717
@param oauth_client: An OAuth client used to construct the LDAP tree
1818
"""
1919
# Create an LDAP lookup tree
20-
self.adaptor = OAuthLDAPTree(domain, oauth_client, enable_mirrored_groups)
20+
self.adaptor = OAuthLDAPTree(
21+
domain, oauth_client, enable_mirrored_groups=enable_mirrored_groups
22+
)
2123

2224
def __repr__(self) -> str:
2325
return f"{self.__class__.__name__} using adaptor {self.adaptor}"

apricot/oauth/keycloak_client.py

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
from .oauth_client import OAuthClient
66

77

8-
def get_single_value_attribute(obj: JSONDict, key: str, default=None) -> Any:
8+
def get_single_value_attribute(
9+
obj: JSONDict, key: str, default: str | None = None
10+
) -> Any:
911
for part in key.split("."):
10-
obj = obj.get(part)
12+
obj = obj.get(part) # type: ignore
1113
if obj is None:
1214
return default
1315
if isinstance(obj, list):
@@ -35,7 +37,7 @@ def __init__(
3537
self.realm = keycloak_realm
3638

3739
redirect_uri = "urn:ietf:wg:oauth:2.0:oob" # this is the "no redirect" URL
38-
scopes = [] # this is the default scope
40+
scopes: list[str] = [] # this is the default scope
3941
token_url = f"{self.base_url}/realms/{self.realm}/protocol/openid-connect/token"
4042

4143
super().__init__(
@@ -51,41 +53,40 @@ def extract_token(self, json_response: JSONDict) -> str:
5153
def groups(self) -> list[JSONDict]:
5254
output = []
5355
try:
54-
group_data = []
56+
group_data: list[JSONDict] = []
5557
while data := self.query(
5658
f"{self.base_url}/admin/realms/{self.realm}/groups?first={len(group_data)}&max={self.max_rows}&briefRepresentation=false",
5759
use_client_secret=False,
5860
):
59-
group_data.extend(data)
61+
group_data.extend(cast(list[JSONDict], data))
6062
if len(data) != self.max_rows:
6163
break
6264

6365
group_data = sorted(
6466
group_data,
65-
key=lambda g: int(
67+
key=lambda group: int(
6668
get_single_value_attribute(
67-
g, "attributes.gid", default="9999999999"
69+
group, "attributes.gid", default="9999999999"
6870
),
69-
10,
71+
base=10,
7072
),
7173
)
7274

7375
next_gid = max(
7476
*(
7577
int(
76-
get_single_value_attribute(g, "attributes.gid", default="-1"),
77-
10,
78+
get_single_value_attribute(
79+
group, "attributes.gid", default="-1"
80+
),
81+
base=10,
7882
)
7983
+ 1
80-
for g in group_data
84+
for group in group_data
8185
),
8286
3000,
8387
)
8488

85-
for group_dict in cast(
86-
list[JSONDict],
87-
group_data,
88-
):
89+
for group_dict in group_data:
8990
group_gid = get_single_value_attribute(
9091
group_dict, "attributes.gid", default=None
9192
)
@@ -122,46 +123,47 @@ def groups(self) -> list[JSONDict]:
122123
def users(self) -> list[JSONDict]:
123124
output = []
124125
try:
125-
user_data = []
126+
user_data: list[JSONDict] = []
126127
while data := self.query(
127128
f"{self.base_url}/admin/realms/{self.realm}/users?first={len(user_data)}&max={self.max_rows}&briefRepresentation=false",
128129
use_client_secret=False,
129130
):
130-
user_data.extend(data)
131+
user_data.extend(cast(list[JSONDict], data))
131132
if len(data) != self.max_rows:
132133
break
133134

134135
user_data = sorted(
135136
user_data,
136-
key=lambda u: int(
137+
key=lambda user: int(
137138
get_single_value_attribute(
138-
u, "attributes.uid", default="9999999999"
139+
user, "attributes.uid", default="9999999999"
139140
),
140-
10,
141+
base=10,
141142
),
142143
)
143144

144145
next_uid = max(
145146
*(
146147
int(
147-
get_single_value_attribute(g, "attributes.uid", default="-1"),
148-
10,
148+
get_single_value_attribute(
149+
user, "attributes.uid", default="-1"
150+
),
151+
base=10,
149152
)
150153
+ 1
151-
for g in user_data
154+
for user in user_data
152155
),
153156
3000,
154157
)
155158

156-
for user_dict in cast(
157-
list[JSONDict],
158-
sorted(user_data, key=lambda user: user["createdTimestamp"]),
159+
for user_dict in sorted(
160+
user_data, key=lambda user: user["createdTimestamp"]
159161
):
160162
user_uid = get_single_value_attribute(
161163
user_dict, "attributes.uid", default=None
162164
)
163165
if user_uid:
164-
user_uid = int(user_uid, 10)
166+
user_uid = int(user_uid, base=10)
165167
if not user_uid:
166168
user_uid = next_uid
167169
next_uid += 1

apricot/oauth/oauth_client.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def users(self) -> list[JSONDict]:
109109
"""
110110
pass
111111

112-
def query(self, url: str, *, use_client_secret=True) -> dict[str, Any]:
112+
def query(self, url: str, *, use_client_secret: bool = True) -> dict[str, Any]:
113113
"""
114114
Make a query against the OAuth backend
115115
"""
@@ -127,12 +127,12 @@ def query(self, url: str, *, use_client_secret=True) -> dict[str, Any]:
127127
**kwargs,
128128
)
129129

130-
def request(self, *args, method="GET", **kwargs) -> dict[str, Any]:
130+
def request(self, *args: Any, method: str = "GET", **kwargs: Any) -> dict[str, Any]:
131131
"""
132132
Make a request to the OAuth backend
133133
"""
134134

135-
def query_(*args, **kwargs) -> requests.Response:
135+
def query_(*args: Any, **kwargs: Any) -> requests.Response:
136136
return self.session_application.request( # type: ignore[no-any-return]
137137
method,
138138
*args,
@@ -147,8 +147,9 @@ def query_(*args, **kwargs) -> requests.Response:
147147
log.msg("Authentication token has expired.")
148148
self.bearer_token_ = None
149149
result = query_(*args, **kwargs)
150-
if result.status_code != HTTPStatus.NO_CONTENT:
151-
return result.json() # type: ignore
150+
if result.status_code == HTTPStatus.NO_CONTENT:
151+
return {}
152+
return result.json() # type: ignore
152153

153154
def verify(self, username: str, password: str) -> bool:
154155
"""

apricot/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import Any
22

33
JSONDict = dict[str, Any]
4+
JSONKey = list[Any] | dict[str, Any] | Any
45
LDAPAttributeDict = dict[str, list[str]]
56
LDAPControlTuple = tuple[str, bool, Any]

0 commit comments

Comments
 (0)