Skip to content

Commit edafc0c

Browse files
committed
🚨 Fix linting issues
1 parent e7e3cdb commit edafc0c

File tree

6 files changed

+59
-18
lines changed

6 files changed

+59
-18
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ To do this, you will need to provide the `--redis-host` and `--redis-port` argum
2626

2727
### Configure background refresh [Optional]
2828

29-
By default Apricot will refresh on demand when the data is older than 60 seconds.
30-
If it takes a long time to fetch all users and groups, or you want to ensure that each request prompty gets a respose, you may want to configure background refresh to have it periodically be refreshed in the background.
29+
By default Apricot will refresh the LDAP tree whenever it is accessed and it contains data older than 60 seconds.
30+
If it takes a long time to fetch all users and groups, or you want to ensure that each request gets a prompt response, you may want to configure background refresh to have it periodically be refreshed in the background.
3131

32-
This is enabled with the `--background-refresh` flag, which uses the `--refresh-interval=60` parameter as the interval to refresh the ldap database.
32+
This is enabled with the `--background-refresh` flag, which uses the `--refresh-interval` parameter as the interval to refresh the ldap database.
3333

3434
### Using TLS [Optional]
3535

apricot/apricot_server.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import inspect
22
import sys
3-
from typing import Any, cast, Optional
3+
from typing import Any, Optional, cast
44

55
from twisted.internet import reactor, task
6-
from twisted.internet.endpoints import serverFromString, quoteStringArgument
6+
from twisted.internet.endpoints import quoteStringArgument, serverFromString
77
from twisted.internet.interfaces import IReactorCore, IStreamServerEndpoint
88
from twisted.python import log
99

@@ -71,12 +71,18 @@ def __init__(
7171
if self.debug:
7272
log.msg("Creating an LDAPServerFactory.")
7373
factory = OAuthLDAPServerFactory(
74-
domain, oauth_client, background_refresh=background_refresh, enable_mirrored_groups=enable_mirrored_groups, refresh_interval=refresh_interval
74+
domain,
75+
oauth_client,
76+
background_refresh=background_refresh,
77+
enable_mirrored_groups=enable_mirrored_groups,
78+
refresh_interval=refresh_interval,
7579
)
7680

7781
if background_refresh:
7882
if self.debug:
79-
log.msg(f"Starting background refresh (interval={factory.adaptor.refresh_interval})")
83+
log.msg(
84+
f"Starting background refresh (interval={factory.adaptor.refresh_interval})"
85+
)
8086
loop = task.LoopingCall(factory.adaptor.refresh)
8187
loop.start(factory.adaptor.refresh_interval)
8288

@@ -88,11 +94,18 @@ def __init__(
8894

8995
# Attach a listening endpoint
9096
if tls_port:
91-
if not (tls_certificate or tls_private_key):
92-
raise ValueError("No TLS certificate or private key provided. Make sure you provide these parameters or disable TLS by not providing the TLS port")
97+
if not tls_certificate:
98+
msg = "No TLS certificate provided. Please provide one with --tls-certificate or disable TLS by not providing the --tls-port argument."
99+
raise ValueError(msg)
100+
if not tls_private_key:
101+
msg = "No TLS private key provided. Please provide one with --tls-private-key or disable TLS by not providing the --tls-port argument."
102+
raise ValueError(msg)
93103
if self.debug:
94104
log.msg("Attaching a listening endpoint (TLS).")
95-
ssl_endpoint: IStreamServerEndpoint = serverFromString(reactor, f"ssl:{tls_port}:privateKey={quoteStringArgument(tls_private_key)}:certKey={quoteStringArgument(tls_certificate)}")
105+
ssl_endpoint: IStreamServerEndpoint = serverFromString(
106+
reactor,
107+
f"ssl:{tls_port}:privateKey={quoteStringArgument(tls_private_key)}:certKey={quoteStringArgument(tls_certificate)}",
108+
)
96109
ssl_endpoint.listen(factory)
97110

98111
# Load the Twisted reactor

apricot/cache/redis_cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class RedisCache(UidCache):
99
def __init__(self, redis_host: str, redis_port: int) -> None:
1010
self.redis_host = redis_host
1111
self.redis_port = redis_port
12-
self.cache_: "redis.Redis[str]" | None = None # noqa: UP037
12+
self.cache_: "redis.Redis[str]" | None = None
1313

1414
@property
1515
def cache(self) -> "redis.Redis[str]":

apricot/ldap/oauth_ldap_server_factory.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,30 @@
99

1010
class OAuthLDAPServerFactory(ServerFactory):
1111
def __init__(
12-
self, domain: str, oauth_client: OAuthClient, *, background_refresh: bool, enable_mirrored_groups: bool, refresh_interval: int,
12+
self,
13+
domain: str,
14+
oauth_client: OAuthClient,
15+
*,
16+
background_refresh: bool,
17+
enable_mirrored_groups: bool,
18+
refresh_interval: int,
1319
):
1420
"""
15-
Initialise an LDAPServerFactory
21+
Initialise an OAuthLDAPServerFactory
1622
23+
@param background_refresh: Whether to refresh the LDAP tree in the background rather than on access
24+
@param domain: The root domain of the LDAP tree
25+
@param enable_mirrored_groups: Create a mirrored LDAP group-of-groups for each group-of-users
1726
@param oauth_client: An OAuth client used to construct the LDAP tree
27+
@param refresh_interval: Interval in seconds after which the tree must be refreshed
1828
"""
1929
# Create an LDAP lookup tree
2030
self.adaptor = OAuthLDAPTree(
21-
domain, oauth_client, background_refresh=background_refresh, enable_mirrored_groups=enable_mirrored_groups, refresh_interval=refresh_interval
31+
domain,
32+
oauth_client,
33+
background_refresh=background_refresh,
34+
enable_mirrored_groups=enable_mirrored_groups,
35+
refresh_interval=refresh_interval,
2236
)
2337

2438
def __repr__(self) -> str:

apricot/ldap/oauth_ldap_tree.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ def __init__(
2020
*,
2121
background_refresh: bool,
2222
enable_mirrored_groups: bool,
23-
refresh_interval,
23+
refresh_interval: int,
2424
) -> None:
2525
"""
2626
Initialise an OAuthLDAPTree
2727
28+
@param background_refresh: Whether to refresh the LDAP tree in the background rather than on access
2829
@param domain: The root domain of the LDAP tree
30+
@param enable_mirrored_groups: Create a mirrored LDAP group-of-groups for each group-of-users
2931
@param oauth_client: An OAuth client used to construct the LDAP tree
3032
@param refresh_interval: Interval in seconds after which the tree must be refreshed
3133
"""
@@ -48,15 +50,20 @@ def root(self) -> OAuthLDAPEntry:
4850
Lazy-load the LDAP tree on request
4951
5052
@return: An OAuthLDAPEntry for the tree
53+
54+
@raises: ValueError.
5155
"""
5256
if not self.background_refresh:
5357
self.refresh()
58+
if not self.root_:
59+
msg = "LDAP tree could not be loaded"
60+
raise ValueError(msg)
5461
return self.root_
5562

56-
def refresh(self):
63+
def refresh(self) -> None:
5764
if (
58-
not self.root_
59-
or (time.monotonic() - self.last_update) > self.refresh_interval
65+
not self.root_
66+
or (time.monotonic() - self.last_update) > self.refresh_interval
6067
):
6168
# Update users and groups from the OAuth server
6269
log.msg("Retrieving OAuth data.")

apricot/oauth/oauth_data_adaptor.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ class OAuthDataAdaptor:
2424
def __init__(
2525
self, domain: str, oauth_client: OAuthClient, *, enable_mirrored_groups: bool
2626
):
27+
"""
28+
Initialise an OAuthDataAdaptor
29+
30+
@param domain: The root domain of the LDAP tree
31+
@param enable_mirrored_groups: Create a mirrored LDAP group-of-groups for each group-of-users
32+
@param oauth_client: An OAuth client used to construct the LDAP tree
33+
"""
2734
self.debug = oauth_client.debug
2835
self.oauth_client = oauth_client
2936
self.root_dn = "DC=" + domain.replace(".", ",DC=")

0 commit comments

Comments
 (0)