aiondemand / aiondemand/AIOD-rest-api

Centralize configuration

未關閉
#67 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
enhancement
主要語言
Python
星號
36
分支
78
PR 合併指標
30 天內沒有已合併 PR

描述

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.

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。