Cat Feeder  1.0.0
The Cat feeder project
Loading...
Searching...
No Matches
docs_constants.py
Go to the documentation of this file.
1r"""
2# +==== BEGIN CatFeeder =================+
3# LOGO:
4# ..............(..../\
5# ...............)..(.')
6# ..............(../..)
7# ...............\‍(__)|
8# Inspired by Joan Stark
9# source https://www.asciiart.eu/
10# animals/cats
11# /STOP
12# PROJECT: CatFeeder
13# FILE: docs_constants.py
14# CREATION DATE: 26-11-2025
15# LAST Modified: 14:46:12 19-12-2025
16# DESCRIPTION:
17# This is the backend server in charge of making the actual website work.
18# /STOP
19# COPYRIGHT: (c) Cat Feeder
20# PURPOSE: The file containing the constants for the documentation handler.
21# // AR
22# +==== END CatFeeder =================+
23"""
24from enum import Enum
25
26from display_tty import Disp, initialise_logger
27
28from ..config import EnvLoader, TOMLLoader
29
30IDISP: Disp = initialise_logger("docs_constants", False)
31
32# Environement initialisation
33ENV: EnvLoader = EnvLoader()
34
35# toml config file
36TOML: TOMLLoader = TOMLLoader()
37
38
39class DocumentationProvider(str, Enum):
40 """Enumeration of available documentation providers.
41
42 Each provider offers a different interface for viewing API documentation.
43 Multiple providers can be enabled simultaneously.
44 """
45 SWAGGER = "swagger"
46 REDOC = "redoc"
47 RAPIDOC = "rapidoc"
48 SCALAR = "scalar"
49 ELEMENTS = "elements"
50 EDITOR = "editor"
51 EXPLORER = "explorer"
52 RAPIPDF = "rapipdf"
53
54
55# OpenAPI configuration
56OPENAPI_URL: str = TOML.get_toml_variable(
57 "Documentation", "openapi_url", "/openapi.json"
58)
59OPENAPI_TITLE: str = TOML.get_toml_variable(
60 "Documentation", "api_title", "CatFeeder API"
61)
62OPENAPI_VERSION: str = TOML.get_toml_variable(
63 "Documentation", "api_version", "1.0.0"
64)
65OPENAPI_DESCRIPTION: str = TOML.get_toml_variable(
66 "Documentation", "api_description",
67 "API documentation for the CatFeeder server"
68)
69
70# Contact information
71CONTACT_INFO: dict = TOML.get_toml_variable(
72 "Documentation.contact", "info", {
73 "name": "Asperguide Team",
74 "url": "https://github.com/Asperguide",
75 "email": "support@asperguide.com",
76 }
77)
78
79# License information
80LICENSE_INFO: dict = TOML.get_toml_variable(
81 "Documentation.license", "info", {
82 "name": "Proprietary",
83 "url": "https://github.com/Asperguide/back-end/blob/prod/LICENSE",
84 }
85)
86
87# Server information
88SERVERS: list = TOML.get_toml_variable(
89 "Documentation", "servers", [
90 {"url": "http://localhost:5000", "description": "Development server"},
91 {"url": "https://api.asperguide.fr", "description": "Production server"},
92 ]
93)
94
95# Tags metadata for grouping endpoints
96TAGS_METADATA: list = TOML.get_toml_variable(
97 "Documentation", "tags_metadata", [
98 {"name": "Welcome", "description": "Welcome and health check endpoints"},
99 {"name": "Authentication",
100 "description": "Authentication and authorization operations"},
101 {"name": "Users", "description": "User management operations"},
102 {"name": "Server", "description": "Server management and control operations"},
103 {"name": "Documentation", "description": "API documentation endpoints"},
104 ]
105)
106
107# Environment variables for enabling/disabling providers
108try:
109 ENABLE_REDOC: bool = ENV.get_environment_variable(
110 "ENABLE_REDOC"
111 ).lower() == "true"
112except (ValueError, AttributeError):
113 ENABLE_REDOC: bool = False
114 IDISP.log_debug(
115 "ENABLE_REDOC not set, defaulting to False"
116 )
117
118try:
119 ENABLE_EDITOR: bool = ENV.get_environment_variable(
120 "ENABLE_EDITOR"
121 ).lower() == "true"
122except (ValueError, AttributeError):
123 ENABLE_EDITOR: bool = False
124 IDISP.log_debug(
125 "ENABLE_EDITOR not set, defaulting to False"
126 )
127
128try:
129 ENABLE_SCALAR: bool = ENV.get_environment_variable(
130 "ENABLE_SCALAR"
131 ).lower() == "true"
132except (ValueError, AttributeError):
133 ENABLE_SCALAR: bool = False
134 IDISP.log_debug(
135 "ENABLE_SCALAR not set, defaulting to False"
136 )
137
138try:
139 ENABLE_SWAGGER: bool = ENV.get_environment_variable(
140 "ENABLE_SWAGGER"
141 ).lower() == "true"
142except (ValueError, AttributeError):
143 ENABLE_SWAGGER: bool = True
144 IDISP.log_debug(
145 "ENABLE_SWAGGER not set, defaulting to True"
146 )
147
148try:
149 ENABLE_RAPIDOC: bool = ENV.get_environment_variable(
150 "ENABLE_RAPIDOC"
151 ).lower() == "true"
152except (ValueError, AttributeError):
153 ENABLE_RAPIDOC: bool = False
154 IDISP.log_debug(
155 "ENABLE_RAPIDOC not set, defaulting to False"
156 )
157
158try:
159 ENABLE_RAPIPDF: bool = ENV.get_environment_variable(
160 "ENABLE_RAPIPDF"
161 ).lower() == "true"
162except (ValueError, AttributeError):
163 ENABLE_RAPIPDF: bool = False
164 IDISP.log_debug(
165 "ENABLE_RAPIPDF not set, defaulting to False"
166 )
167
168try:
169 ENABLE_EXPLORER: bool = ENV.get_environment_variable(
170 "ENABLE_EXPLORER"
171 ).lower() == "true"
172except (ValueError, AttributeError):
173 ENABLE_EXPLORER: bool = False
174 IDISP.log_debug(
175 "ENABLE_EXPLORER not set, defaulting to False"
176 )
177
178try:
179 ENABLE_ELEMENTS: bool = ENV.get_environment_variable(
180 "ENABLE_ELEMENTS"
181 ).lower() == "true"
182except (ValueError, AttributeError):
183 ENABLE_ELEMENTS: bool = False
184 IDISP.log_debug(
185 "ENABLE_ELEMENTS not set, defaulting to False"
186 )
187
188# Build default providers list based on environment variables
189_enabled_providers = []
190if ENABLE_SWAGGER:
191 _enabled_providers.append(DocumentationProvider.SWAGGER)
192if ENABLE_REDOC:
193 _enabled_providers.append(DocumentationProvider.REDOC)
194if ENABLE_RAPIDOC:
195 _enabled_providers.append(DocumentationProvider.RAPIDOC)
196if ENABLE_SCALAR:
197 _enabled_providers.append(DocumentationProvider.SCALAR)
198if ENABLE_EDITOR:
199 _enabled_providers.append(DocumentationProvider.EDITOR)
200if ENABLE_EXPLORER:
201 _enabled_providers.append(DocumentationProvider.EXPLORER)
202if ENABLE_RAPIPDF:
203 _enabled_providers.append(DocumentationProvider.RAPIPDF)
204if ENABLE_ELEMENTS:
205 _enabled_providers.append(DocumentationProvider.ELEMENTS)
206
207DEFAULT_PROVIDERS: tuple[DocumentationProvider, ...] = tuple(
208 _enabled_providers)
209
210# CDN versions from TOML configuration
211RAPIDOC_CDN_VERSION: str = TOML.get_toml_variable(
212 "Documentation.cdn_versions", "rapidoc", "9.3.4"
213)
214SCALAR_CDN_VERSION: str = TOML.get_toml_variable(
215 "Documentation.cdn_versions", "scalar", "1.24.0"
216)
217ELEMENTS_CDN_VERSION: str = TOML.get_toml_variable(
218 "Documentation.cdn_versions", "elements", "8.4.7"
219)
220EDITOR_CDN_VERSION: str = TOML.get_toml_variable(
221 "Documentation.cdn_versions", "editor", "5.0.0"
222)
223EXPLORER_CDN_VERSION: str = TOML.get_toml_variable(
224 "Documentation.cdn_versions", "explorer", "0.0.58"
225)
226RAPIPDF_CDN_VERSION: str = TOML.get_toml_variable(
227 "Documentation.cdn_versions", "rapipdf", "2.2.1"
228)
229
230# OAuth2 configuration for documentation
231OAUTH2_REDIRECT_URL: str = TOML.get_toml_variable(
232 "Documentation", "oauth2_redirect_url", "/docs/oauth2-redirect"
233)
234ENABLE_OAUTH2_DOCS: bool = TOML.get_toml_variable(
235 "Documentation", "enable_oauth2", False
236)
237
238# OAuth2 scopes for API documentation (from TOML or defaults)
239_DEFAULT_OAUTH2_SCOPES: dict[str, str] = {
240 "read": "Read access to API resources",
241 "write": "Write access to API resources",
242 "admin": "Administrative access to API resources",
243}
244OAUTH2_SCOPES: dict[str, str] = TOML.get_toml_variable(
245 "Documentation", "oauth2_scopes", _DEFAULT_OAUTH2_SCOPES
246)
247
248# OAuth2 URLs from environment variables (sensitive data)
249try:
250 OAUTH2_AUTHORIZATION_URL: str = ENV.get_environment_variable(
251 "DOCS_OAUTH2_AUTHORIZATION_URL"
252 )
253except ValueError:
254 OAUTH2_AUTHORIZATION_URL: str = ""
255 IDISP.log_debug(
256 "DOCS_OAUTH2_AUTHORIZATION_URL not set in environment"
257 )
258
259try:
260 OAUTH2_TOKEN_URL: str = ENV.get_environment_variable(
261 "DOCS_OAUTH2_TOKEN_URL"
262 )
263except ValueError:
264 OAUTH2_TOKEN_URL: str = ""
265 IDISP.log_debug(
266 "DOCS_OAUTH2_TOKEN_URL not set in environment"
267 )