Coverage for slidge/core/config.py: 100%
73 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-04 08:17 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-04 08:17 +0000
1from datetime import timedelta
2from pathlib import Path
3from typing import Optional, Self
5from slixmpp import JID as JIDType
8class _TimedeltaSeconds(timedelta):
9 def __new__(cls, s: str) -> Self:
10 return super().__new__(cls, seconds=int(s))
13# REQUIRED, so not default value
15LEGACY_MODULE: str
16LEGACY_MODULE__DOC = (
17 "Importable python module containing (at least) "
18 "a BaseGateway and a LegacySession subclass"
19)
21SERVER: str = "localhost"
22SERVER__DOC = (
23 "The XMPP server's host name. Defaults to localhost, which is the "
24 "standard way of running slidge, on the same host as the XMPP server. "
25 "The 'Jabber Component Protocol' (XEP-0114) does not mention encryption, "
26 "so you *should* provide encryption another way, eg via port forwarding, if "
27 "you change this."
28)
29SERVER__SHORT = "s"
31SECRET: str
32SECRET__DOC = "The gateway component's secret (required to connect to the XMPP server)"
34JID: JIDType
35JID__DOC = "The gateway component's JID"
36JID__SHORT = "j"
38PORT: str = "5347"
39PORT__DOC = "The XMPP server's port for incoming component connections"
40PORT__SHORT = "p"
42# Dynamic default (depends on other values)
44HOME_DIR: Path
45HOME_DIR__DOC = (
46 "Directory where slidge will writes it persistent data and cache. "
47 "Defaults to /var/lib/slidge/${SLIDGE_JID}. "
48)
49HOME_DIR__DYNAMIC_DEFAULT = True
51DB_URL: str
52DB_URL__DOC = (
53 "Database URL, see <https://docs.sqlalchemy.org/en/20/core/engines.html#database-urls>. "
54 "Defaults to sqlite:///${HOME_DIR}/slidge.sqlite"
55)
56DB_URL__DYNAMIC_DEFAULT = True
58USER_JID_VALIDATOR: str
59USER_JID_VALIDATOR__DOC = (
60 "Regular expression to restrict users that can register to the gateway, by JID. "
61 "Defaults to .*@${SLIDGE_SERVER}, but since SLIDGE_SERVER is usually localhost, "
62 "you probably want to change that to .*@example.com"
63)
64USER_JID_VALIDATOR__DYNAMIC_DEFAULT = True
66# Optional, so default value + type hint if default is None
68ADMINS: tuple[JIDType, ...] = ()
69ADMINS__DOC = "JIDs of the gateway admins"
71UPLOAD_SERVICE: Optional[str] = None
72UPLOAD_SERVICE__DOC = (
73 "JID of an HTTP upload service the gateway can use. "
74 "This is optional, as it should be automatically determined via service"
75 "discovery."
76)
78AVATAR_SIZE = 200
79AVATAR_SIZE__DOC = (
80 "Maximum image size (width and height), image ratio will be preserved"
81)
83USE_ATTACHMENT_ORIGINAL_URLS = False
84USE_ATTACHMENT_ORIGINAL_URLS__DOC = (
85 "For legacy plugins in which attachments are publicly downloadable URLs, "
86 "let XMPP clients directly download them from this URL. Note that this will "
87 "probably leak your client IP to the legacy network."
88)
90UPLOAD_REQUESTER: Optional[str] = None
91UPLOAD_REQUESTER__DOC = (
92 "Set which JID should request the upload slots. Defaults to the component JID."
93)
95NO_UPLOAD_PATH: Optional[str] = None
96NO_UPLOAD_PATH__DOC = (
97 "Instead of using the XMPP server's HTTP upload component, copy files to this dir. "
98 "You need to set NO_UPLOAD_URL_PREFIX too if you use this option, and configure "
99 "an web server to serve files in this dir."
100)
102NO_UPLOAD_URL_PREFIX: Optional[str] = None
103NO_UPLOAD_URL_PREFIX__DOC = (
104 "Base URL that servers files in the dir set in the no-upload-path option, "
105 "eg https://example.com:666/slidge-attachments/"
106)
108NO_UPLOAD_METHOD: str = "copy"
109NO_UPLOAD_METHOD__DOC = (
110 "Whether to 'copy', 'move', 'hardlink' or 'symlink' the files in no-upload-path."
111)
113NO_UPLOAD_FILE_READ_OTHERS = False
114NO_UPLOAD_FILE_READ_OTHERS__DOC = (
115 "After writing a file in NO_UPLOAD_PATH, change its permission so that 'others' can"
116 " read it."
117)
119IGNORE_DELAY_THRESHOLD = _TimedeltaSeconds("300")
120IGNORE_DELAY_THRESHOLD__DOC = (
121 "Threshold, in seconds, below which the <delay> information is stripped "
122 "out of emitted stanzas."
123)
125PARTIAL_REGISTRATION_TIMEOUT = 3600
126PARTIAL_REGISTRATION_TIMEOUT__DOC = (
127 "Timeout before registration and login. Only useful for legacy networks where "
128 "a single step registration process is not enough."
129)
131QR_TIMEOUT = 60
132QR_TIMEOUT__DOC = "Timeout for QR code flashing confirmation."
134FIX_FILENAME_SUFFIX_MIME_TYPE = False
135FIX_FILENAME_SUFFIX_MIME_TYPE__DOC = (
136 "Fix the Filename suffix based on the Mime Type of the file. Some clients (eg"
137 " Conversations) may not inline files that have a wrong suffix for the MIME Type."
138 " Therefore the MIME Type of the file is checked, if the suffix is not valid for"
139 " that MIME Type, a valid one will be picked."
140)
142LOG_FILE: Optional[Path] = None
143LOG_FILE__DOC = "Log to a file instead of stdout/err"
145LOG_FORMAT: str = "%(levelname)s:%(name)s:%(message)s"
146LOG_FORMAT__DOC = (
147 "Optionally, a format string for logging messages. Refer to "
148 "https://docs.python.org/3/library/logging.html#logrecord-attributes "
149 "for available options."
150)
152MAM_MAX_DAYS = 7
153MAM_MAX_DAYS__DOC = "Maximum number of days for group archive retention."
155ATTACHMENT_MAXIMUM_FILE_NAME_LENGTH = 200
156ATTACHMENT_MAXIMUM_FILE_NAME_LENGTH__DOC = (
157 "Some legacy network provide ridiculously long filenames, strip above this limit, "
158 "preserving suffix."
159)
161AVATAR_RESAMPLING_THREADS = 2
162AVATAR_RESAMPLING_THREADS__DOC = (
163 "Number of additional threads to use for avatar resampling. Even in a single-core "
164 "context, this makes avatar resampling non-blocking."
165)
167DEV_MODE = False
168DEV_MODE__DOC = (
169 "Enables an interactive python shell via chat commands, for admins."
170 "Not safe to use in prod, but great during dev."
171)
173STRIP_LEADING_EMOJI_ADHOC = False
174STRIP_LEADING_EMOJI_ADHOC__DOC = (
175 "Strip the leading emoji in ad-hoc command names, if present, in case you "
176 "are a emoji-hater."
177)
179COMPONENT_NAME: Optional[str] = None
180COMPONENT_NAME__DOC = (
181 "Overrides the default component name with a custom one. This is seen in service discovery and as the nickname "
182 "of the component in chat windows."
183)
185WELCOME_MESSAGE: Optional[str] = None
186WELCOME_MESSAGE__DOC = (
187 "Overrides the default welcome message received by newly registered users."
188)