-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadgen.toml
More file actions
236 lines (198 loc) · 5.11 KB
/
readgen.toml
File metadata and controls
236 lines (198 loc) · 5.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# ReadGen - Readme Generator CLI tool configuration file
[ReadGen]
title = "Config Manager"
content = """
### ${project.name} (${project.version})
${project.description}
"""
[Features]
content = """
- **Multiple Provider Support**
- Built-in Environment Variables (.env) support
- Built-in GCP Secret Manager integration
- Configurable provider priority
- Easy to extend with custom providers
- **Type Safety & Flexibility**
- Strong typing support
- Optional value handling
- Default value support
- Attribute-style access
- **Developer Friendly**
- Simple API
- Clear error messages
- Comprehensive logging
- Easy to test
"""
[Installation]
content = """
```bash
$ pip install tbi-config-manager
```
### Prerequisites
- Python ${project.requires-python}
- GCP credentials (optional, GCP project Service Account, for Secret Manager support)
"""
[Configuration]
title = "How to Use"
content = """
Basic usage example:
```python
from config_manager import ConfigManager, Provider
# Default to environment variables only
config = ConfigManager()
value = config.get("DATABASE_URL")
# With specific .env file
config = ConfigManager(env_file=".env.dev")
# ENV has higher priority than GCP.
config = ConfigManager(
providers=[Provider.ENV, Provider.GCP],
project_id="your-project-id",
credentials_path="path/to/credentials.json",
secret_prefix="APP" # Will use "APP_" as prefix
)
# GCP has higher priority than ENV.
config = ConfigManager(
providers=[Provider.GCP, Provider.ENV]
...
)
# Only use GCP Secret Manager
config = ConfigManager(
providers=[Provider.GCP]
...
)
DATABASE_URL = config.get("DATABASE_URL")
...
```
In your `config.py`:
```python
from config_manager import ConfigManager, Provider
config = ConfigManager(
providers=[Provider.ENV, Provider.GCP],
project_id="config-manager",
credentials_path="path/to/credentials.json",
secret_prefix="PROD" # Will use "PROD_" as prefix
)
# Access configs as attributes
DATABASE_URL = config.get("DATABASE_URL")
API_KEY = config.get("API_KEY")
ENV = config.get("ENV", default="dev")
PROVIDER = config.get("PROVIDER", "GCP") # Optional parameter with default
```
"""
[Development]
title = "How to Contribute"
content = """
## Setup
```bash
git clone https://github.com/TaiwanBigdata/config-manager.git
cd readgen
python -m venv env
source env/bin/activate # Linux/Mac
pip install -e .
```
## Implementing Custom Providers
The config-manager library is designed for extensibility. Here's how to implement your own configuration provider:
### 1. Add New Provider Type
Add your provider type to the enum
`src/config_manager/typing.py`
```python
from enum import Enum
class Provider(Enum):
\"""Available configuration provider types\"""
ENV = "env" # Environment variables
GCP = "gcp" # Google Cloud Secret Manager
REDIS = "redis" # Your new provider
```
### 2. Implement Provider Class
Create your provider implementation under providers directory
`src/config_manager/providers/redis.py`
```python
from config_manager import ConfigProvider
from typing import Optional
# Inherit from the base abstract class ConfigProvider
class RedisProvider(ConfigProvider):
def __init__(self, redis_url: str, prefix: str = ""):
self.redis_url = redis_url
self.prefix = prefix
self._client = redis.Redis.from_url(redis_url)
# Required interface implementations
def get(self, key: str) -> Optional[str]: ...
def has(self, key: str) -> bool: ...
def reload(self) -> None: ...
@property
def name(self) -> str: ...
```
### 3. Register Provider
Register your provider in factory
`src/config_manager/providers/factory.py`
```python
class ProviderFactory:
...
# Register providers here
ProviderFactory.register(Provider.ENV, EnvProvider)
ProviderFactory.register(Provider.GCP, GCPProvider)
```
### 4. Export Provider
Export your provider in the module level
`src/config_manager/providers/__init__.py`
```python
from .redis import RedisProvider
__all__ = [
...
"RedisProvider",
]
```
Export your provider in the package level
`src/config_manager/__init__.py`
```python
from .providers import ProviderFactory, EnvProvider, GCPProvider, RedisProvider
__all__ = [
...
"RedisProvider",
]
```
### Examples of Potential Custom Providers
- AWS Secrets Manager
- Azure Key Vault
- HashiCorp Vault
- Redis
- MongoDB
- Local JSON/YAML files
- Remote HTTP endpoints
### Each provider needs to implement the ConfigProvider interface and handle:
- Configuration retrieval
- Key existence checking
- Reloading mechanism
- Error handling
"""
[Dependencies]
content = """
### Core
- python-dotenv>=1.0.0
- google-cloud-secret-manager>=2.0.0
- typing-extensions>=4.0.0
"""
[License]
content = "This project is licensed under the ${project.license} License."
[directory]
title = "Project Structure"
enable = true
exclude_patterns = [
".cursorrules",
".env*",
"**/.DS_Store",
".git/",
".gitignore",
"env/",
"**/__pycache__/",
"jupyterlab",
"secrets",
"build",
"dist",
"secrets/*",
]
show_files = true
show_comments = true
[env]
enable = false
env_file = ".env"