aiondemand / aiondemand/AIOD-rest-api
Centralize configuration
- Vorherrschende Sprache
- Python
- Sterne
- 36
- Forks
- 77
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
Currently, the API configuration is managed by two different files: .env and config.toml. To simplify the setup and avoid confusion, it is recommended to select one of these files and delete the other. Since the TOML format provides more functionality and flexibility, it would be better to choose this file as the primary configuration file.
The configuration variables defined in these files are read in various project files using different methods. For example:
```python
username = db_config.get("name", "root")
client_id = os.getenv("KEYCLOAK_CLIENT_ID")
```
To centralize these operations and avoid potential issues in the future, it would be beneficial to implement a Config class that consolidates all these operations and holds the values in a single instance.
Here's an example of how you could define the Config class using Python's dataclasses module:
```python
import dataclasses
@dataclasses.dataclass
class Config:
name: str = db_config.get("name", "root")
```
In this example, the Config class is defined using the dataclass decorator from the dataclasses module. The name attribute is defined with a default value of db_config.get("name", "root"), which means it will use the value specified in the db_config dictionary if available, or default to 'root' if not provided.
You can expand the Config class by adding additional attributes that correspond to the configuration variables used in your project. By using a centralized Config class, you can easily access and manage these configuration values throughout your codebase, providing a more organized and maintainable solution.
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.