kiarina-lib-cloudflare-auth 1.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kiarina_lib_cloudflare_auth-1.4.0/.gitignore +34 -0
- kiarina_lib_cloudflare_auth-1.4.0/.vscode/settings.json +7 -0
- kiarina_lib_cloudflare_auth-1.4.0/CHANGELOG.md +33 -0
- kiarina_lib_cloudflare_auth-1.4.0/PKG-INFO +271 -0
- kiarina_lib_cloudflare_auth-1.4.0/README.md +245 -0
- kiarina_lib_cloudflare_auth-1.4.0/pyproject.toml +42 -0
- kiarina_lib_cloudflare_auth-1.4.0/src/kiarina/lib/cloudflare/auth/__init__.py +30 -0
- kiarina_lib_cloudflare_auth-1.4.0/src/kiarina/lib/cloudflare/auth/py.typed +0 -0
- kiarina_lib_cloudflare_auth-1.4.0/src/kiarina/lib/cloudflare/auth/settings.py +12 -0
- kiarina_lib_cloudflare_auth-1.4.0/tests/__init__.py +0 -0
- kiarina_lib_cloudflare_auth-1.4.0/tests/conftest.py +0 -0
- kiarina_lib_cloudflare_auth-1.4.0/tests/test_settings.py +13 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
# Python
|
2
|
+
__pycache__/
|
3
|
+
*.py[cod]
|
4
|
+
*.so
|
5
|
+
*.egg-info/
|
6
|
+
dist/
|
7
|
+
build/
|
8
|
+
.ruff_cache/
|
9
|
+
.mypy_cache/
|
10
|
+
.pytest_cache/
|
11
|
+
.coverage
|
12
|
+
coverage.xml
|
13
|
+
htmlcov/
|
14
|
+
|
15
|
+
# uv
|
16
|
+
.uv_cache/
|
17
|
+
|
18
|
+
# Virtual environments & config
|
19
|
+
.venv/
|
20
|
+
.env
|
21
|
+
|
22
|
+
# OS
|
23
|
+
.DS_Store
|
24
|
+
|
25
|
+
# Project specific
|
26
|
+
*.log
|
27
|
+
tmp/
|
28
|
+
|
29
|
+
# Test data
|
30
|
+
tests/data/large/
|
31
|
+
|
32
|
+
# mise tasks (always include)
|
33
|
+
!mise-tasks/
|
34
|
+
!mise-tasks/**
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
## [Unreleased]
|
9
|
+
|
10
|
+
## [1.4.0] - 2025-10-09
|
11
|
+
|
12
|
+
### Added
|
13
|
+
- Initial release of kiarina-lib-cloudflare-auth
|
14
|
+
- Cloudflare authentication library with configuration management using pydantic-settings-manager
|
15
|
+
- `CloudflareAuthSettings`: Pydantic settings model for Cloudflare authentication
|
16
|
+
- `account_id`: Cloudflare account ID (required)
|
17
|
+
- `api_token`: Cloudflare API token (required, protected with SecretStr)
|
18
|
+
- `settings_manager`: Global settings manager instance with multi-configuration support
|
19
|
+
- Type safety with full type hints and Pydantic validation
|
20
|
+
- Environment variable configuration support with `KIARINA_LIB_CLOUDFLARE_AUTH_` prefix
|
21
|
+
- Runtime configuration overrides via `cli_args`
|
22
|
+
- Multiple named configurations support (e.g., production, staging)
|
23
|
+
|
24
|
+
### Security
|
25
|
+
- **Enhanced credential protection**: API tokens use `SecretStr` for secure handling
|
26
|
+
- Tokens are masked in string representations and logs (displayed as `**********`)
|
27
|
+
- Prevents accidental exposure of sensitive data in debug output
|
28
|
+
- Access token values explicitly via `.get_secret_value()` method
|
29
|
+
- Follows the project-wide security policy for sensitive data
|
30
|
+
|
31
|
+
### Dependencies
|
32
|
+
- pydantic-settings>=2.10.1
|
33
|
+
- pydantic-settings-manager>=2.1.0
|
@@ -0,0 +1,271 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: kiarina-lib-cloudflare-auth
|
3
|
+
Version: 1.4.0
|
4
|
+
Summary: Cloudflare client library for kiarina namespace
|
5
|
+
Project-URL: Homepage, https://github.com/kiarina/kiarina-python
|
6
|
+
Project-URL: Repository, https://github.com/kiarina/kiarina-python
|
7
|
+
Project-URL: Issues, https://github.com/kiarina/kiarina-python/issues
|
8
|
+
Project-URL: Changelog, https://github.com/kiarina/kiarina-python/blob/main/packages/kiarina-lib-cloudflare-auth/CHANGELOG.md
|
9
|
+
Project-URL: Documentation, https://github.com/kiarina/kiarina-python/tree/main/packages/kiarina-lib-cloudflare-auth#readme
|
10
|
+
Author-email: kiarina <kiarinadawa@gmail.com>
|
11
|
+
Maintainer-email: kiarina <kiarinadawa@gmail.com>
|
12
|
+
License-Expression: MIT
|
13
|
+
Keywords: cdn,client,cloud,cloudflare,pydantic,settings
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
15
|
+
Classifier: Intended Audience :: Developers
|
16
|
+
Classifier: Operating System :: OS Independent
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
21
|
+
Classifier: Typing :: Typed
|
22
|
+
Requires-Python: >=3.12
|
23
|
+
Requires-Dist: pydantic-settings-manager>=2.1.0
|
24
|
+
Requires-Dist: pydantic-settings>=2.10.1
|
25
|
+
Description-Content-Type: text/markdown
|
26
|
+
|
27
|
+
# kiarina-lib-cloudflare-auth
|
28
|
+
|
29
|
+
A Python library for Cloudflare authentication with configuration management using pydantic-settings-manager.
|
30
|
+
|
31
|
+
## Features
|
32
|
+
|
33
|
+
- **Configuration Management**: Use `pydantic-settings-manager` for flexible configuration
|
34
|
+
- **Type Safety**: Full type hints and Pydantic validation
|
35
|
+
- **Secure Credential Handling**: API tokens are protected using `SecretStr`
|
36
|
+
- **Multiple Configurations**: Support for multiple named configurations (e.g., different accounts)
|
37
|
+
- **Environment Variable Support**: Configure via environment variables with `KIARINA_LIB_CLOUDFLARE_AUTH_` prefix
|
38
|
+
|
39
|
+
## Installation
|
40
|
+
|
41
|
+
```bash
|
42
|
+
pip install kiarina-lib-cloudflare-auth
|
43
|
+
```
|
44
|
+
|
45
|
+
## Quick Start
|
46
|
+
|
47
|
+
### Basic Usage
|
48
|
+
|
49
|
+
```python
|
50
|
+
from kiarina.lib.cloudflare.auth import CloudflareAuthSettings, settings_manager
|
51
|
+
|
52
|
+
# Configure Cloudflare authentication
|
53
|
+
settings_manager.user_config = {
|
54
|
+
"default": {
|
55
|
+
"account_id": "your-account-id",
|
56
|
+
"api_token": "your-api-token"
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
# Get settings
|
61
|
+
settings = settings_manager.settings
|
62
|
+
print(f"Account ID: {settings.account_id}")
|
63
|
+
print(f"API Token: {settings.api_token.get_secret_value()}") # Access secret value
|
64
|
+
```
|
65
|
+
|
66
|
+
### Environment Variable Configuration
|
67
|
+
|
68
|
+
Configure authentication using environment variables:
|
69
|
+
|
70
|
+
```bash
|
71
|
+
export KIARINA_LIB_CLOUDFLARE_AUTH_ACCOUNT_ID="your-account-id"
|
72
|
+
export KIARINA_LIB_CLOUDFLARE_AUTH_API_TOKEN="your-api-token"
|
73
|
+
```
|
74
|
+
|
75
|
+
```python
|
76
|
+
from kiarina.lib.cloudflare.auth import settings_manager
|
77
|
+
|
78
|
+
# Settings are automatically loaded from environment variables
|
79
|
+
settings = settings_manager.settings
|
80
|
+
print(f"Account ID: {settings.account_id}")
|
81
|
+
```
|
82
|
+
|
83
|
+
### Multiple Configurations
|
84
|
+
|
85
|
+
Manage multiple Cloudflare accounts:
|
86
|
+
|
87
|
+
```python
|
88
|
+
from kiarina.lib.cloudflare.auth import settings_manager
|
89
|
+
|
90
|
+
# Configure multiple accounts
|
91
|
+
settings_manager.user_config = {
|
92
|
+
"production": {
|
93
|
+
"account_id": "prod-account-id",
|
94
|
+
"api_token": "prod-api-token"
|
95
|
+
},
|
96
|
+
"staging": {
|
97
|
+
"account_id": "staging-account-id",
|
98
|
+
"api_token": "staging-api-token"
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
# Switch between configurations
|
103
|
+
settings_manager.active_key = "production"
|
104
|
+
prod_settings = settings_manager.settings
|
105
|
+
print(f"Production Account: {prod_settings.account_id}")
|
106
|
+
|
107
|
+
settings_manager.active_key = "staging"
|
108
|
+
staging_settings = settings_manager.settings
|
109
|
+
print(f"Staging Account: {staging_settings.account_id}")
|
110
|
+
```
|
111
|
+
|
112
|
+
## Configuration
|
113
|
+
|
114
|
+
This library uses [pydantic-settings-manager](https://github.com/kiarina/pydantic-settings-manager) for flexible configuration management.
|
115
|
+
|
116
|
+
### CloudflareAuthSettings
|
117
|
+
|
118
|
+
The `CloudflareAuthSettings` class provides the following configuration fields:
|
119
|
+
|
120
|
+
| Field | Type | Required | Description |
|
121
|
+
|-------|------|----------|-------------|
|
122
|
+
| `account_id` | `str` | Yes | Cloudflare account ID |
|
123
|
+
| `api_token` | `SecretStr` | Yes | Cloudflare API token (masked in logs) |
|
124
|
+
|
125
|
+
### Environment Variables
|
126
|
+
|
127
|
+
All settings can be configured via environment variables with the `KIARINA_LIB_CLOUDFLARE_AUTH_` prefix:
|
128
|
+
|
129
|
+
```bash
|
130
|
+
# Account ID
|
131
|
+
export KIARINA_LIB_CLOUDFLARE_AUTH_ACCOUNT_ID="your-account-id"
|
132
|
+
|
133
|
+
# API Token (will be automatically wrapped in SecretStr)
|
134
|
+
export KIARINA_LIB_CLOUDFLARE_AUTH_API_TOKEN="your-api-token"
|
135
|
+
```
|
136
|
+
|
137
|
+
### Programmatic Configuration
|
138
|
+
|
139
|
+
```python
|
140
|
+
from pydantic import SecretStr
|
141
|
+
from kiarina.lib.cloudflare.auth import CloudflareAuthSettings, settings_manager
|
142
|
+
|
143
|
+
# Direct settings object
|
144
|
+
settings = CloudflareAuthSettings(
|
145
|
+
account_id="your-account-id",
|
146
|
+
api_token=SecretStr("your-api-token")
|
147
|
+
)
|
148
|
+
|
149
|
+
# Via settings manager
|
150
|
+
settings_manager.user_config = {
|
151
|
+
"default": {
|
152
|
+
"account_id": "your-account-id",
|
153
|
+
"api_token": "your-api-token" # Automatically converted to SecretStr
|
154
|
+
}
|
155
|
+
}
|
156
|
+
```
|
157
|
+
|
158
|
+
### Runtime Overrides
|
159
|
+
|
160
|
+
```python
|
161
|
+
from kiarina.lib.cloudflare.auth import settings_manager
|
162
|
+
|
163
|
+
# Override specific settings at runtime
|
164
|
+
settings_manager.cli_args = {
|
165
|
+
"account_id": "override-account-id"
|
166
|
+
}
|
167
|
+
|
168
|
+
settings = settings_manager.settings
|
169
|
+
print(f"Account ID: {settings.account_id}") # Uses overridden value
|
170
|
+
```
|
171
|
+
|
172
|
+
## Security
|
173
|
+
|
174
|
+
### API Token Protection
|
175
|
+
|
176
|
+
API tokens are stored using Pydantic's `SecretStr` type, which provides the following security benefits:
|
177
|
+
|
178
|
+
- **Masked in logs**: Tokens are displayed as `**********` in string representations
|
179
|
+
- **Prevents accidental exposure**: Tokens won't appear in debug output or error messages
|
180
|
+
- **Explicit access required**: Must use `.get_secret_value()` to access the actual token
|
181
|
+
|
182
|
+
```python
|
183
|
+
from kiarina.lib.cloudflare.auth import settings_manager
|
184
|
+
|
185
|
+
settings = settings_manager.settings
|
186
|
+
|
187
|
+
# Token is masked in string representation
|
188
|
+
print(settings) # api_token=SecretStr('**********')
|
189
|
+
|
190
|
+
# Explicit access to get the actual token
|
191
|
+
token = settings.api_token.get_secret_value()
|
192
|
+
```
|
193
|
+
|
194
|
+
## API Reference
|
195
|
+
|
196
|
+
### CloudflareAuthSettings
|
197
|
+
|
198
|
+
```python
|
199
|
+
class CloudflareAuthSettings(BaseSettings):
|
200
|
+
account_id: str
|
201
|
+
api_token: SecretStr
|
202
|
+
```
|
203
|
+
|
204
|
+
Pydantic settings model for Cloudflare authentication.
|
205
|
+
|
206
|
+
**Fields:**
|
207
|
+
- `account_id` (str): Cloudflare account ID
|
208
|
+
- `api_token` (SecretStr): Cloudflare API token (protected)
|
209
|
+
|
210
|
+
### settings_manager
|
211
|
+
|
212
|
+
```python
|
213
|
+
settings_manager: SettingsManager[CloudflareAuthSettings]
|
214
|
+
```
|
215
|
+
|
216
|
+
Global settings manager instance for Cloudflare authentication.
|
217
|
+
|
218
|
+
**Properties:**
|
219
|
+
- `settings`: Get the current active settings
|
220
|
+
- `user_config`: Get/set user configuration
|
221
|
+
- `cli_args`: Get/set CLI arguments for runtime overrides
|
222
|
+
- `active_key`: Get/set active configuration key (for multi-config mode)
|
223
|
+
|
224
|
+
**Methods:**
|
225
|
+
- `clear()`: Clear cached settings
|
226
|
+
- `get_settings_by_key(key: str)`: Get settings by specific key
|
227
|
+
|
228
|
+
## Development
|
229
|
+
|
230
|
+
### Prerequisites
|
231
|
+
|
232
|
+
- Python 3.12+
|
233
|
+
|
234
|
+
### Setup
|
235
|
+
|
236
|
+
```bash
|
237
|
+
# Clone the repository
|
238
|
+
git clone https://github.com/kiarina/kiarina-python.git
|
239
|
+
cd kiarina-python
|
240
|
+
|
241
|
+
# Setup development environment
|
242
|
+
mise run setup
|
243
|
+
```
|
244
|
+
|
245
|
+
### Running Tests
|
246
|
+
|
247
|
+
```bash
|
248
|
+
# Run format, lint, type checks and tests
|
249
|
+
mise run package kiarina-lib-cloudflare-auth
|
250
|
+
|
251
|
+
# Coverage report
|
252
|
+
mise run package:test kiarina-lib-cloudflare-auth --coverage
|
253
|
+
```
|
254
|
+
|
255
|
+
## Dependencies
|
256
|
+
|
257
|
+
- [pydantic-settings](https://docs.pydantic.dev/latest/concepts/pydantic_settings/) - Settings management
|
258
|
+
- [pydantic-settings-manager](https://github.com/kiarina/pydantic-settings-manager) - Advanced settings management
|
259
|
+
|
260
|
+
## License
|
261
|
+
|
262
|
+
This project is licensed under the MIT License - see the [LICENSE](../../LICENSE) file for details.
|
263
|
+
|
264
|
+
## Contributing
|
265
|
+
|
266
|
+
This is a personal project, but contributions are welcome! Please feel free to submit issues or pull requests.
|
267
|
+
|
268
|
+
## Related Projects
|
269
|
+
|
270
|
+
- [kiarina-python](https://github.com/kiarina/kiarina-python) - The main monorepo containing this package
|
271
|
+
- [pydantic-settings-manager](https://github.com/kiarina/pydantic-settings-manager) - Configuration management library used by this package
|
@@ -0,0 +1,245 @@
|
|
1
|
+
# kiarina-lib-cloudflare-auth
|
2
|
+
|
3
|
+
A Python library for Cloudflare authentication with configuration management using pydantic-settings-manager.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
- **Configuration Management**: Use `pydantic-settings-manager` for flexible configuration
|
8
|
+
- **Type Safety**: Full type hints and Pydantic validation
|
9
|
+
- **Secure Credential Handling**: API tokens are protected using `SecretStr`
|
10
|
+
- **Multiple Configurations**: Support for multiple named configurations (e.g., different accounts)
|
11
|
+
- **Environment Variable Support**: Configure via environment variables with `KIARINA_LIB_CLOUDFLARE_AUTH_` prefix
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
```bash
|
16
|
+
pip install kiarina-lib-cloudflare-auth
|
17
|
+
```
|
18
|
+
|
19
|
+
## Quick Start
|
20
|
+
|
21
|
+
### Basic Usage
|
22
|
+
|
23
|
+
```python
|
24
|
+
from kiarina.lib.cloudflare.auth import CloudflareAuthSettings, settings_manager
|
25
|
+
|
26
|
+
# Configure Cloudflare authentication
|
27
|
+
settings_manager.user_config = {
|
28
|
+
"default": {
|
29
|
+
"account_id": "your-account-id",
|
30
|
+
"api_token": "your-api-token"
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
# Get settings
|
35
|
+
settings = settings_manager.settings
|
36
|
+
print(f"Account ID: {settings.account_id}")
|
37
|
+
print(f"API Token: {settings.api_token.get_secret_value()}") # Access secret value
|
38
|
+
```
|
39
|
+
|
40
|
+
### Environment Variable Configuration
|
41
|
+
|
42
|
+
Configure authentication using environment variables:
|
43
|
+
|
44
|
+
```bash
|
45
|
+
export KIARINA_LIB_CLOUDFLARE_AUTH_ACCOUNT_ID="your-account-id"
|
46
|
+
export KIARINA_LIB_CLOUDFLARE_AUTH_API_TOKEN="your-api-token"
|
47
|
+
```
|
48
|
+
|
49
|
+
```python
|
50
|
+
from kiarina.lib.cloudflare.auth import settings_manager
|
51
|
+
|
52
|
+
# Settings are automatically loaded from environment variables
|
53
|
+
settings = settings_manager.settings
|
54
|
+
print(f"Account ID: {settings.account_id}")
|
55
|
+
```
|
56
|
+
|
57
|
+
### Multiple Configurations
|
58
|
+
|
59
|
+
Manage multiple Cloudflare accounts:
|
60
|
+
|
61
|
+
```python
|
62
|
+
from kiarina.lib.cloudflare.auth import settings_manager
|
63
|
+
|
64
|
+
# Configure multiple accounts
|
65
|
+
settings_manager.user_config = {
|
66
|
+
"production": {
|
67
|
+
"account_id": "prod-account-id",
|
68
|
+
"api_token": "prod-api-token"
|
69
|
+
},
|
70
|
+
"staging": {
|
71
|
+
"account_id": "staging-account-id",
|
72
|
+
"api_token": "staging-api-token"
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
# Switch between configurations
|
77
|
+
settings_manager.active_key = "production"
|
78
|
+
prod_settings = settings_manager.settings
|
79
|
+
print(f"Production Account: {prod_settings.account_id}")
|
80
|
+
|
81
|
+
settings_manager.active_key = "staging"
|
82
|
+
staging_settings = settings_manager.settings
|
83
|
+
print(f"Staging Account: {staging_settings.account_id}")
|
84
|
+
```
|
85
|
+
|
86
|
+
## Configuration
|
87
|
+
|
88
|
+
This library uses [pydantic-settings-manager](https://github.com/kiarina/pydantic-settings-manager) for flexible configuration management.
|
89
|
+
|
90
|
+
### CloudflareAuthSettings
|
91
|
+
|
92
|
+
The `CloudflareAuthSettings` class provides the following configuration fields:
|
93
|
+
|
94
|
+
| Field | Type | Required | Description |
|
95
|
+
|-------|------|----------|-------------|
|
96
|
+
| `account_id` | `str` | Yes | Cloudflare account ID |
|
97
|
+
| `api_token` | `SecretStr` | Yes | Cloudflare API token (masked in logs) |
|
98
|
+
|
99
|
+
### Environment Variables
|
100
|
+
|
101
|
+
All settings can be configured via environment variables with the `KIARINA_LIB_CLOUDFLARE_AUTH_` prefix:
|
102
|
+
|
103
|
+
```bash
|
104
|
+
# Account ID
|
105
|
+
export KIARINA_LIB_CLOUDFLARE_AUTH_ACCOUNT_ID="your-account-id"
|
106
|
+
|
107
|
+
# API Token (will be automatically wrapped in SecretStr)
|
108
|
+
export KIARINA_LIB_CLOUDFLARE_AUTH_API_TOKEN="your-api-token"
|
109
|
+
```
|
110
|
+
|
111
|
+
### Programmatic Configuration
|
112
|
+
|
113
|
+
```python
|
114
|
+
from pydantic import SecretStr
|
115
|
+
from kiarina.lib.cloudflare.auth import CloudflareAuthSettings, settings_manager
|
116
|
+
|
117
|
+
# Direct settings object
|
118
|
+
settings = CloudflareAuthSettings(
|
119
|
+
account_id="your-account-id",
|
120
|
+
api_token=SecretStr("your-api-token")
|
121
|
+
)
|
122
|
+
|
123
|
+
# Via settings manager
|
124
|
+
settings_manager.user_config = {
|
125
|
+
"default": {
|
126
|
+
"account_id": "your-account-id",
|
127
|
+
"api_token": "your-api-token" # Automatically converted to SecretStr
|
128
|
+
}
|
129
|
+
}
|
130
|
+
```
|
131
|
+
|
132
|
+
### Runtime Overrides
|
133
|
+
|
134
|
+
```python
|
135
|
+
from kiarina.lib.cloudflare.auth import settings_manager
|
136
|
+
|
137
|
+
# Override specific settings at runtime
|
138
|
+
settings_manager.cli_args = {
|
139
|
+
"account_id": "override-account-id"
|
140
|
+
}
|
141
|
+
|
142
|
+
settings = settings_manager.settings
|
143
|
+
print(f"Account ID: {settings.account_id}") # Uses overridden value
|
144
|
+
```
|
145
|
+
|
146
|
+
## Security
|
147
|
+
|
148
|
+
### API Token Protection
|
149
|
+
|
150
|
+
API tokens are stored using Pydantic's `SecretStr` type, which provides the following security benefits:
|
151
|
+
|
152
|
+
- **Masked in logs**: Tokens are displayed as `**********` in string representations
|
153
|
+
- **Prevents accidental exposure**: Tokens won't appear in debug output or error messages
|
154
|
+
- **Explicit access required**: Must use `.get_secret_value()` to access the actual token
|
155
|
+
|
156
|
+
```python
|
157
|
+
from kiarina.lib.cloudflare.auth import settings_manager
|
158
|
+
|
159
|
+
settings = settings_manager.settings
|
160
|
+
|
161
|
+
# Token is masked in string representation
|
162
|
+
print(settings) # api_token=SecretStr('**********')
|
163
|
+
|
164
|
+
# Explicit access to get the actual token
|
165
|
+
token = settings.api_token.get_secret_value()
|
166
|
+
```
|
167
|
+
|
168
|
+
## API Reference
|
169
|
+
|
170
|
+
### CloudflareAuthSettings
|
171
|
+
|
172
|
+
```python
|
173
|
+
class CloudflareAuthSettings(BaseSettings):
|
174
|
+
account_id: str
|
175
|
+
api_token: SecretStr
|
176
|
+
```
|
177
|
+
|
178
|
+
Pydantic settings model for Cloudflare authentication.
|
179
|
+
|
180
|
+
**Fields:**
|
181
|
+
- `account_id` (str): Cloudflare account ID
|
182
|
+
- `api_token` (SecretStr): Cloudflare API token (protected)
|
183
|
+
|
184
|
+
### settings_manager
|
185
|
+
|
186
|
+
```python
|
187
|
+
settings_manager: SettingsManager[CloudflareAuthSettings]
|
188
|
+
```
|
189
|
+
|
190
|
+
Global settings manager instance for Cloudflare authentication.
|
191
|
+
|
192
|
+
**Properties:**
|
193
|
+
- `settings`: Get the current active settings
|
194
|
+
- `user_config`: Get/set user configuration
|
195
|
+
- `cli_args`: Get/set CLI arguments for runtime overrides
|
196
|
+
- `active_key`: Get/set active configuration key (for multi-config mode)
|
197
|
+
|
198
|
+
**Methods:**
|
199
|
+
- `clear()`: Clear cached settings
|
200
|
+
- `get_settings_by_key(key: str)`: Get settings by specific key
|
201
|
+
|
202
|
+
## Development
|
203
|
+
|
204
|
+
### Prerequisites
|
205
|
+
|
206
|
+
- Python 3.12+
|
207
|
+
|
208
|
+
### Setup
|
209
|
+
|
210
|
+
```bash
|
211
|
+
# Clone the repository
|
212
|
+
git clone https://github.com/kiarina/kiarina-python.git
|
213
|
+
cd kiarina-python
|
214
|
+
|
215
|
+
# Setup development environment
|
216
|
+
mise run setup
|
217
|
+
```
|
218
|
+
|
219
|
+
### Running Tests
|
220
|
+
|
221
|
+
```bash
|
222
|
+
# Run format, lint, type checks and tests
|
223
|
+
mise run package kiarina-lib-cloudflare-auth
|
224
|
+
|
225
|
+
# Coverage report
|
226
|
+
mise run package:test kiarina-lib-cloudflare-auth --coverage
|
227
|
+
```
|
228
|
+
|
229
|
+
## Dependencies
|
230
|
+
|
231
|
+
- [pydantic-settings](https://docs.pydantic.dev/latest/concepts/pydantic_settings/) - Settings management
|
232
|
+
- [pydantic-settings-manager](https://github.com/kiarina/pydantic-settings-manager) - Advanced settings management
|
233
|
+
|
234
|
+
## License
|
235
|
+
|
236
|
+
This project is licensed under the MIT License - see the [LICENSE](../../LICENSE) file for details.
|
237
|
+
|
238
|
+
## Contributing
|
239
|
+
|
240
|
+
This is a personal project, but contributions are welcome! Please feel free to submit issues or pull requests.
|
241
|
+
|
242
|
+
## Related Projects
|
243
|
+
|
244
|
+
- [kiarina-python](https://github.com/kiarina/kiarina-python) - The main monorepo containing this package
|
245
|
+
- [pydantic-settings-manager](https://github.com/kiarina/pydantic-settings-manager) - Configuration management library used by this package
|
@@ -0,0 +1,42 @@
|
|
1
|
+
[project]
|
2
|
+
name = "kiarina-lib-cloudflare-auth"
|
3
|
+
version = "1.4.0"
|
4
|
+
description = "Cloudflare client library for kiarina namespace"
|
5
|
+
readme = "README.md"
|
6
|
+
license = "MIT"
|
7
|
+
authors = [
|
8
|
+
{ name = "kiarina", email = "kiarinadawa@gmail.com" }
|
9
|
+
]
|
10
|
+
maintainers = [
|
11
|
+
{ name = "kiarina", email = "kiarinadawa@gmail.com" }
|
12
|
+
]
|
13
|
+
keywords = ["cloudflare", "client", "pydantic", "settings", "cloud", "cdn"]
|
14
|
+
classifiers = [
|
15
|
+
"Development Status :: 4 - Beta",
|
16
|
+
"Intended Audience :: Developers",
|
17
|
+
"Operating System :: OS Independent",
|
18
|
+
"Programming Language :: Python :: 3",
|
19
|
+
"Programming Language :: Python :: 3.12",
|
20
|
+
"Programming Language :: Python :: 3.13",
|
21
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
22
|
+
"Typing :: Typed",
|
23
|
+
]
|
24
|
+
requires-python = ">=3.12"
|
25
|
+
dependencies = [
|
26
|
+
"pydantic-settings>=2.10.1",
|
27
|
+
"pydantic-settings-manager>=2.1.0",
|
28
|
+
]
|
29
|
+
|
30
|
+
[project.urls]
|
31
|
+
Homepage = "https://github.com/kiarina/kiarina-python"
|
32
|
+
Repository = "https://github.com/kiarina/kiarina-python"
|
33
|
+
Issues = "https://github.com/kiarina/kiarina-python/issues"
|
34
|
+
Changelog = "https://github.com/kiarina/kiarina-python/blob/main/packages/kiarina-lib-cloudflare-auth/CHANGELOG.md"
|
35
|
+
Documentation = "https://github.com/kiarina/kiarina-python/tree/main/packages/kiarina-lib-cloudflare-auth#readme"
|
36
|
+
|
37
|
+
[build-system]
|
38
|
+
requires = ["hatchling"]
|
39
|
+
build-backend = "hatchling.build"
|
40
|
+
|
41
|
+
[tool.hatch.build.targets.wheel]
|
42
|
+
packages = ["src/kiarina"]
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import logging
|
2
|
+
from importlib import import_module
|
3
|
+
from importlib.metadata import version
|
4
|
+
from typing import TYPE_CHECKING
|
5
|
+
|
6
|
+
if TYPE_CHECKING:
|
7
|
+
from .settings import CloudflareAuthSettings, settings_manager
|
8
|
+
|
9
|
+
__version__ = version("kiarina-lib-cloudflare-auth")
|
10
|
+
|
11
|
+
__all__ = [
|
12
|
+
# .settings
|
13
|
+
"CloudflareAuthSettings",
|
14
|
+
"settings_manager",
|
15
|
+
]
|
16
|
+
|
17
|
+
logging.getLogger(__name__).addHandler(logging.NullHandler())
|
18
|
+
|
19
|
+
|
20
|
+
def __getattr__(name: str) -> object:
|
21
|
+
if name not in __all__:
|
22
|
+
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
|
23
|
+
|
24
|
+
module_map = {
|
25
|
+
"CloudflareAuthSettings": ".settings",
|
26
|
+
"settings_manager": ".settings",
|
27
|
+
}
|
28
|
+
|
29
|
+
globals()[name] = getattr(import_module(module_map[name], __name__), name)
|
30
|
+
return globals()[name]
|
File without changes
|
@@ -0,0 +1,12 @@
|
|
1
|
+
from pydantic import SecretStr
|
2
|
+
from pydantic_settings import BaseSettings
|
3
|
+
from pydantic_settings_manager import SettingsManager
|
4
|
+
|
5
|
+
|
6
|
+
class CloudflareAuthSettings(BaseSettings):
|
7
|
+
account_id: str
|
8
|
+
|
9
|
+
api_token: SecretStr
|
10
|
+
|
11
|
+
|
12
|
+
settings_manager = SettingsManager(CloudflareAuthSettings, multi=True)
|
File without changes
|
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
from kiarina.lib.cloudflare.auth import settings_manager
|
2
|
+
|
3
|
+
|
4
|
+
def test_settings():
|
5
|
+
settings_manager.user_config = {
|
6
|
+
"default": {
|
7
|
+
"account_id": "test",
|
8
|
+
"api_token": "testtoken",
|
9
|
+
},
|
10
|
+
}
|
11
|
+
settings = settings_manager.settings
|
12
|
+
assert settings.account_id == "test"
|
13
|
+
assert settings.api_token.get_secret_value() == "testtoken"
|