Coverage for slidge/core/config.py: 100%

83 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-11-07 05:11 +0000

1from datetime import timedelta 

2from pathlib import Path 

3from typing import Optional 

4 

5from slixmpp import JID as JIDType 

6 

7 

8class _TimedeltaSeconds(timedelta): 

9 def __new__(cls, s: str): 

10 return super().__new__(cls, seconds=int(s)) 

11 

12 

13# REQUIRED, so not default value 

14 

15LEGACY_MODULE: str 

16LEGACY_MODULE__DOC = ( 

17 "Importable python module containing (at least) " 

18 "a BaseGateway and a LegacySession subclass" 

19) 

20 

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" 

30 

31SECRET: str 

32SECRET__DOC = "The gateway component's secret (required to connect to the XMPP server)" 

33 

34JID: JIDType 

35JID__DOC = "The gateway component's JID" 

36JID__SHORT = "j" 

37 

38PORT: str = "5347" 

39PORT__DOC = "The XMPP server's port for incoming component connections" 

40PORT__SHORT = "p" 

41 

42# Dynamic default (depends on other values) 

43 

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 

50 

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 

57 

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 

65 

66# Optional, so default value + type hint if default is None 

67 

68ADMINS: tuple[JIDType, ...] = () 

69ADMINS__DOC = "JIDs of the gateway admins" 

70 

71 

72UPLOAD_SERVICE: Optional[str] = None 

73UPLOAD_SERVICE__DOC = ( 

74 "JID of an HTTP upload service the gateway can use. " 

75 "This is optional, as it should be automatically determined via service" 

76 "discovery." 

77) 

78 

79SECRET_KEY: Optional[str] = None 

80SECRET_KEY__DOC = "Encryption for disk storage. Deprecated." 

81 

82NO_ROSTER_PUSH = False 

83NO_ROSTER_PUSH__DOC = "Do not fill users' rosters with legacy contacts automatically" 

84 

85ROSTER_PUSH_PRESENCE_SUBSCRIPTION_REQUEST_FALLBACK = True 

86ROSTER_PUSH_PRESENCE_SUBSCRIPTION_REQUEST_FALLBACK__DOC = ( 

87 "If True, legacy contacts will send a presence request subscription " 

88 "when privileged roster push does not work, eg, if XEP-0356 (privileged " 

89 "entity) is not available for the component." 

90) 

91 

92AVATAR_SIZE = 200 

93AVATAR_SIZE__DOC = ( 

94 "Maximum image size (width and height), image ratio will be preserved" 

95) 

96 

97USE_ATTACHMENT_ORIGINAL_URLS = False 

98USE_ATTACHMENT_ORIGINAL_URLS__DOC = ( 

99 "For legacy plugins in which attachments are publicly downloadable URLs, " 

100 "let XMPP clients directly download them from this URL. Note that this will " 

101 "probably leak your client IP to the legacy network." 

102) 

103 

104UPLOAD_REQUESTER: Optional[str] = None 

105UPLOAD_REQUESTER__DOC = ( 

106 "Set which JID should request the upload slots. Defaults to the component JID." 

107) 

108 

109NO_UPLOAD_PATH: Optional[str] = None 

110NO_UPLOAD_PATH__DOC = ( 

111 "Instead of using the XMPP server's HTTP upload component, copy files to this dir. " 

112 "You need to set NO_UPLOAD_URL_PREFIX too if you use this option, and configure " 

113 "an web server to serve files in this dir." 

114) 

115 

116NO_UPLOAD_URL_PREFIX: Optional[str] = None 

117NO_UPLOAD_URL_PREFIX__DOC = ( 

118 "Base URL that servers files in the dir set in the no-upload-path option, " 

119 "eg https://example.com:666/slidge-attachments/" 

120) 

121 

122NO_UPLOAD_METHOD: str = "copy" 

123NO_UPLOAD_METHOD__DOC = ( 

124 "Whether to 'copy', 'move', 'hardlink' or 'symlink' the files in no-upload-path." 

125) 

126 

127NO_UPLOAD_FILE_READ_OTHERS = False 

128NO_UPLOAD_FILE_READ_OTHERS__DOC = ( 

129 "After writing a file in NO_UPLOAD_PATH, change its permission so that 'others' can" 

130 " read it." 

131) 

132 

133IGNORE_DELAY_THRESHOLD = _TimedeltaSeconds("300") 

134IGNORE_DELAY_THRESHOLD__DOC = ( 

135 "Threshold, in seconds, below which the <delay> information is stripped " 

136 "out of emitted stanzas." 

137) 

138 

139PARTIAL_REGISTRATION_TIMEOUT = 3600 

140PARTIAL_REGISTRATION_TIMEOUT__DOC = ( 

141 "Timeout before registration and login. Only useful for legacy networks where " 

142 "a single step registration process is not enough." 

143) 

144 

145LAST_SEEN_FALLBACK = False 

146LAST_SEEN_FALLBACK__DOC = ( 

147 "When using XEP-0319 (Last User Interaction in Presence), use the presence status" 

148 " to display the last seen information in the presence status. Useful for clients" 

149 " that do not implement XEP-0319. Because of implementation details, this can increase" 

150 " RAM usage and might be deprecated in the future. Ask your client dev for XEP-0319" 

151 " support ;o)." 

152) 

153 

154QR_TIMEOUT = 60 

155QR_TIMEOUT__DOC = "Timeout for QR code flashing confirmation." 

156 

157LAST_MESSAGE_CORRECTION_RETRACTION_WORKAROUND = False 

158LAST_MESSAGE_CORRECTION_RETRACTION_WORKAROUND__DOC = ( 

159 "If the legacy service does not support last message correction but supports" 

160 " message retractions, slidge can 'retract' the edited message when you edit from" 

161 " an XMPP client, as a workaround. This may only work for editing messages" 

162 " **once**. If the legacy service does not support retractions and this is set to" 

163 " true, when XMPP clients attempt to correct, this will send a new message." 

164) 

165 

166FIX_FILENAME_SUFFIX_MIME_TYPE = False 

167FIX_FILENAME_SUFFIX_MIME_TYPE__DOC = ( 

168 "Fix the Filename suffix based on the Mime Type of the file. Some clients (eg" 

169 " Conversations) may not inline files that have a wrong suffix for the MIME Type." 

170 " Therefore the MIME Type of the file is checked, if the suffix is not valid for" 

171 " that MIME Type, a valid one will be picked." 

172) 

173 

174LOG_FILE: Optional[Path] = None 

175LOG_FILE__DOC = "Log to a file instead of stdout/err" 

176 

177LOG_FORMAT: str = "%(levelname)s:%(name)s:%(message)s" 

178LOG_FORMAT__DOC = ( 

179 "Optionally, a format string for logging messages. Refer to " 

180 "https://docs.python.org/3/library/logging.html#logrecord-attributes " 

181 "for available options." 

182) 

183 

184MAM_MAX_DAYS = 7 

185MAM_MAX_DAYS__DOC = "Maximum number of days for group archive retention." 

186 

187CORRECTION_EMPTY_BODY_AS_RETRACTION = True 

188CORRECTION_EMPTY_BODY_AS_RETRACTION__DOC = ( 

189 "Treat last message correction to empty message as a retraction. " 

190 "(this is what cheogram do for retraction)" 

191) 

192 

193ATTACHMENT_MAXIMUM_FILE_NAME_LENGTH = 200 

194ATTACHMENT_MAXIMUM_FILE_NAME_LENGTH__DOC = ( 

195 "Some legacy network provide ridiculously long filenames, strip above this limit, " 

196 "preserving suffix." 

197) 

198 

199ALWAYS_INVITE_WHEN_ADDING_BOOKMARKS = True 

200ALWAYS_INVITE_WHEN_ADDING_BOOKMARKS__DOC = ( 

201 "Send an invitation to join MUCs when adding them to the bookmarks. While this " 

202 "should not be necessary, it helps with clients that do not support :xep:`0402` " 

203 "or that do not respect the auto-join flag." 

204) 

205 

206AVATAR_RESAMPLING_THREADS = 2 

207AVATAR_RESAMPLING_THREADS__DOC = ( 

208 "Number of additional threads to use for avatar resampling. Even in a single-core " 

209 "context, this makes avatar resampling non-blocking." 

210) 

211 

212DEV_MODE = False 

213DEV_MODE__DOC = ( 

214 "Enables an interactive python shell via chat commands, for admins." 

215 "Not safe to use in prod, but great during dev." 

216) 

217 

218STRIP_LEADING_EMOJI_ADHOC = False 

219STRIP_LEADING_EMOJI_ADHOC__DOC = ( 

220 "Strip the leading emoji in ad-hoc command names, if present, in case you " 

221 "are a emoji-hater." 

222)