kiarina-lib-cloudflare-auth 1.4.0__py3-none-any.whl

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.
@@ -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)
@@ -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,6 @@
1
+ kiarina/lib/cloudflare/auth/__init__.py,sha256=UILxUtBirbJjQutAJArE5iEzL7E0n7Ufj5fbYd1aoZs,779
2
+ kiarina/lib/cloudflare/auth/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ kiarina/lib/cloudflare/auth/settings.py,sha256=xbtp_4_5TAX45VWBVrxDCrIplQndQEYwFpsvcWP8uo0,293
4
+ kiarina_lib_cloudflare_auth-1.4.0.dist-info/METADATA,sha256=6qE96rxyFmA2x86KJwd_s6oaSLv34ZPD0MOxwUEC42A,7985
5
+ kiarina_lib_cloudflare_auth-1.4.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
6
+ kiarina_lib_cloudflare_auth-1.4.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any