kiarina-lib-google-cloud-storage 1.5.0__py3-none-any.whl → 1.6.1__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.
@@ -7,7 +7,11 @@ from .settings import settings_manager
7
7
 
8
8
 
9
9
  def get_blob(
10
- config_key: str | None = None, blob_name: str | None = None, **kwargs: Any
10
+ blob_name: str | None = None,
11
+ *,
12
+ config_key: str | None = None,
13
+ auth_config_key: str | None = None,
14
+ **kwargs: Any,
11
15
  ) -> storage.Blob:
12
16
  settings = settings_manager.get_settings_by_key(config_key)
13
17
 
@@ -20,5 +24,5 @@ def get_blob(
20
24
  if settings.blob_name_prefix:
21
25
  blob_name = f"{settings.blob_name_prefix}/{blob_name}"
22
26
 
23
- bucket = get_bucket(config_key, **kwargs)
27
+ bucket = get_bucket(config_key, auth_config_key=auth_config_key, **kwargs)
24
28
  return bucket.blob(blob_name)
@@ -6,11 +6,16 @@ from ._get_storage_client import get_storage_client
6
6
  from .settings import settings_manager
7
7
 
8
8
 
9
- def get_bucket(config_key: str | None = None, **kwargs: Any) -> storage.Bucket:
9
+ def get_bucket(
10
+ config_key: str | None = None,
11
+ *,
12
+ auth_config_key: str | None = None,
13
+ **kwargs: Any,
14
+ ) -> storage.Bucket:
10
15
  settings = settings_manager.get_settings_by_key(config_key)
11
16
 
12
17
  if settings.bucket_name is None:
13
18
  raise ValueError("bucket_name is not set in the settings")
14
19
 
15
- client = get_storage_client(config_key, **kwargs)
20
+ client = get_storage_client(auth_config_key, **kwargs)
16
21
  return client.bucket(settings.bucket_name)
@@ -3,10 +3,10 @@ from typing import Any
3
3
  from google.cloud import storage # type: ignore[import-untyped]
4
4
  from kiarina.lib.google.auth import get_credentials
5
5
 
6
- from .settings import settings_manager
7
6
 
8
-
9
- def get_storage_client(config_key: str | None = None, **kwargs: Any) -> storage.Client:
10
- settings = settings_manager.get_settings_by_key(config_key)
11
- credentials = get_credentials(settings.google_auth_config_key)
7
+ def get_storage_client(
8
+ auth_config_key: str | None = None,
9
+ **kwargs: Any,
10
+ ) -> storage.Client:
11
+ credentials = get_credentials(auth_config_key)
12
12
  return storage.Client(credentials=credentials, **kwargs)
@@ -3,8 +3,6 @@ from pydantic_settings_manager import SettingsManager
3
3
 
4
4
 
5
5
  class GoogleCloudStorageSettings(BaseSettings):
6
- google_auth_config_key: str | None = None
7
-
8
6
  bucket_name: str | None = None
9
7
 
10
8
  blob_name_prefix: str | None = None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kiarina-lib-google-cloud-storage
3
- Version: 1.5.0
3
+ Version: 1.6.1
4
4
  Summary: Google Cloud Storage client library for kiarina namespace
5
5
  Project-URL: Homepage, https://github.com/kiarina/kiarina-python
6
6
  Project-URL: Repository, https://github.com/kiarina/kiarina-python
@@ -105,7 +105,6 @@ from kiarina.lib.google.cloud_storage import get_blob, settings_manager
105
105
  # Configure once (typically in your app initialization)
106
106
  settings_manager.user_config = {
107
107
  "default": {
108
- "google_auth_config_key": "default",
109
108
  "bucket_name": "my-app-data",
110
109
  "blob_name_prefix": "production/v1"
111
110
  }
@@ -126,7 +125,6 @@ content = blob.download_as_text()
126
125
  # Set once in your deployment environment
127
126
  export KIARINA_LIB_GOOGLE_CLOUD_STORAGE_BUCKET_NAME="my-app-data"
128
127
  export KIARINA_LIB_GOOGLE_CLOUD_STORAGE_BLOB_NAME_PREFIX="production/v1"
129
- export KIARINA_LIB_GOOGLE_CLOUD_STORAGE_GOOGLE_AUTH_CONFIG_KEY="default"
130
128
  ```
131
129
 
132
130
  ```python
@@ -145,23 +143,35 @@ Deploy the same application code to different environments with different config
145
143
 
146
144
  ```yaml
147
145
  # config/production.yaml
146
+ google_auth:
147
+ default:
148
+ type: "service_account"
149
+ service_account_file: "/secrets/prod-sa-key.json"
150
+
148
151
  google_cloud_storage:
149
152
  default:
150
- google_auth_config_key: "production"
151
153
  bucket_name: "prod-us-west1-app-data"
152
154
  blob_name_prefix: "v2/production"
153
155
 
154
156
  # config/staging.yaml
157
+ google_auth:
158
+ default:
159
+ type: "service_account"
160
+ service_account_file: "/secrets/staging-sa-key.json"
161
+
155
162
  google_cloud_storage:
156
163
  default:
157
- google_auth_config_key: "staging"
158
164
  bucket_name: "staging-app-data"
159
165
  blob_name_prefix: "v2/staging"
160
166
 
161
167
  # config/development.yaml
168
+ google_auth:
169
+ default:
170
+ type: "user_account"
171
+ authorized_user_file: "~/.config/gcloud/application_default_credentials.json"
172
+
162
173
  google_cloud_storage:
163
174
  default:
164
- google_auth_config_key: "development"
165
175
  bucket_name: "dev-local-data"
166
176
  blob_name_prefix: "v2/dev"
167
177
  ```
@@ -193,15 +203,28 @@ Support multiple tenants with isolated storage, without changing application cod
193
203
  ```python
194
204
  from kiarina.lib.google.cloud_storage import settings_manager, get_blob
195
205
 
196
- # Configure tenant-specific storage
206
+ # Configure tenant-specific storage and authentication
207
+ from kiarina.lib.google.auth import settings_manager as auth_settings_manager
208
+
209
+ # Authentication configuration (separate from storage)
210
+ auth_settings_manager.user_config = {
211
+ "tenant_acme": {
212
+ "type": "service_account",
213
+ "service_account_file": "/secrets/acme-sa-key.json"
214
+ },
215
+ "tenant_globex": {
216
+ "type": "service_account",
217
+ "service_account_file": "/secrets/globex-sa-key.json"
218
+ }
219
+ }
220
+
221
+ # Storage configuration (separate from authentication)
197
222
  settings_manager.user_config = {
198
223
  "tenant_acme": {
199
- "google_auth_config_key": "tenant_acme",
200
224
  "bucket_name": "acme-corp-data",
201
225
  "blob_name_prefix": "app-data"
202
226
  },
203
227
  "tenant_globex": {
204
- "google_auth_config_key": "tenant_globex",
205
228
  "bucket_name": "globex-data",
206
229
  "blob_name_prefix": "app-data"
207
230
  }
@@ -211,7 +234,11 @@ settings_manager.user_config = {
211
234
  def save_document(tenant_id: str, doc_id: str, content: bytes):
212
235
  """Save document for any tenant"""
213
236
  config_key = f"tenant_{tenant_id}"
214
- blob = get_blob(config_key=config_key, blob_name=f"documents/{doc_id}.pdf")
237
+ blob = get_blob(
238
+ blob_name=f"documents/{doc_id}.pdf",
239
+ config_key=config_key,
240
+ auth_config_key=config_key
241
+ )
215
242
  blob.upload_from_string(content)
216
243
 
217
244
  def list_documents(tenant_id: str) -> list[str]:
@@ -219,7 +246,7 @@ def list_documents(tenant_id: str) -> list[str]:
219
246
  from kiarina.lib.google.cloud_storage import get_bucket
220
247
 
221
248
  config_key = f"tenant_{tenant_id}"
222
- bucket = get_bucket(config_key=config_key)
249
+ bucket = get_bucket(config_key=config_key, auth_config_key=config_key)
223
250
 
224
251
  # Get prefix from settings
225
252
  settings = settings_manager.get_settings_by_key(config_key)
@@ -247,7 +274,6 @@ def mock_storage_config():
247
274
  """Configure test storage"""
248
275
  settings_manager.user_config = {
249
276
  "test": {
250
- "google_auth_config_key": "test",
251
277
  "bucket_name": "test-bucket",
252
278
  "blob_name_prefix": f"test-run-{datetime.now().isoformat()}"
253
279
  }
@@ -312,13 +338,14 @@ This library uses [pydantic-settings-manager](https://github.com/kiarina/pydanti
312
338
 
313
339
  | Field | Type | Required | Description |
314
340
  |-------|------|----------|-------------|
315
- | `google_auth_config_key` | `str \| None` | No | Configuration key for kiarina-lib-google-auth |
316
341
  | `bucket_name` | `str \| None` | Yes* | Google Cloud Storage bucket name |
317
342
  | `blob_name_prefix` | `str \| None` | No | Prefix for blob names (e.g., "production/v1") |
318
343
  | `blob_name` | `str \| None` | No | Default blob name (rarely used) |
319
344
 
320
345
  *Required when using `get_bucket()` or `get_blob()`
321
346
 
347
+ **Note:** Authentication is configured separately through `auth_config_key` parameters in the API functions, which reference configurations in [kiarina-lib-google-auth](../kiarina-lib-google-auth/).
348
+
322
349
  ### Configuration Methods
323
350
 
324
351
  #### 1. Programmatic Configuration
@@ -328,7 +355,6 @@ from kiarina.lib.google.cloud_storage import settings_manager
328
355
 
329
356
  settings_manager.user_config = {
330
357
  "default": {
331
- "google_auth_config_key": "default",
332
358
  "bucket_name": "my-bucket",
333
359
  "blob_name_prefix": "app-data"
334
360
  }
@@ -340,11 +366,12 @@ settings_manager.user_config = {
340
366
  All settings can be configured via environment variables with the `KIARINA_LIB_GOOGLE_CLOUD_STORAGE_` prefix:
341
367
 
342
368
  ```bash
343
- export KIARINA_LIB_GOOGLE_CLOUD_STORAGE_GOOGLE_AUTH_CONFIG_KEY="default"
344
369
  export KIARINA_LIB_GOOGLE_CLOUD_STORAGE_BUCKET_NAME="my-bucket"
345
370
  export KIARINA_LIB_GOOGLE_CLOUD_STORAGE_BLOB_NAME_PREFIX="app-data"
346
371
  ```
347
372
 
373
+ **Note:** Authentication is configured separately via `KIARINA_LIB_GOOGLE_AUTH_*` environment variables. See [kiarina-lib-google-auth](../kiarina-lib-google-auth/) for details.
374
+
348
375
  #### 3. Configuration Files (with YAML)
349
376
 
350
377
  ```python
@@ -360,33 +387,50 @@ settings_manager.user_config = config["google_cloud_storage"]
360
387
 
361
388
  ### Integration with kiarina-lib-google-auth
362
389
 
363
- This library integrates seamlessly with [kiarina-lib-google-auth](../kiarina-lib-google-auth/) for authentication:
390
+ This library integrates seamlessly with [kiarina-lib-google-auth](../kiarina-lib-google-auth/) for authentication.
391
+
392
+ **Key Design:** Authentication and storage configurations are **completely separate**, allowing flexible combinations.
364
393
 
365
394
  ```python
366
395
  from kiarina.lib.google.auth import settings_manager as auth_settings_manager
367
396
  from kiarina.lib.google.cloud_storage import settings_manager as storage_settings_manager
368
397
 
369
- # Configure authentication
398
+ # Configure authentication (separate)
370
399
  auth_settings_manager.user_config = {
371
400
  "default": {
372
401
  "type": "service_account",
373
402
  "service_account_file": "~/service-account-key.json"
403
+ },
404
+ "user_auth": {
405
+ "type": "user_account",
406
+ "authorized_user_file": "~/.config/gcloud/application_default_credentials.json"
374
407
  }
375
408
  }
376
409
 
377
- # Configure storage (references auth config)
410
+ # Configure storage (separate)
378
411
  storage_settings_manager.user_config = {
379
412
  "default": {
380
- "google_auth_config_key": "default", # References auth config above
381
413
  "bucket_name": "my-bucket"
414
+ },
415
+ "backup": {
416
+ "bucket_name": "my-backup-bucket"
382
417
  }
383
418
  }
384
419
 
385
- # Use authenticated storage
420
+ # Use with default authentication
386
421
  from kiarina.lib.google.cloud_storage import get_bucket
387
- bucket = get_bucket() # Automatically authenticated
422
+ bucket = get_bucket() # Uses default auth + default storage
423
+
424
+ # Mix and match configurations
425
+ bucket = get_bucket(config_key="backup", auth_config_key="user_auth")
426
+ # Uses user_auth authentication + backup storage configuration
388
427
  ```
389
428
 
429
+ **Benefits of Separation:**
430
+ - **Flexibility**: Use same auth with multiple buckets, or multiple auths with same bucket
431
+ - **Clarity**: Clear distinction between "who" (auth) and "where" (storage)
432
+ - **Reusability**: Share authentication across different storage configurations
433
+
390
434
  ## API Reference
391
435
 
392
436
  ### get_storage_client()
@@ -395,13 +439,13 @@ Get a Google Cloud Storage client with credentials from kiarina-lib-google-auth.
395
439
 
396
440
  ```python
397
441
  def get_storage_client(
398
- config_key: str | None = None,
442
+ auth_config_key: str | None = None,
399
443
  **kwargs: Any
400
444
  ) -> storage.Client
401
445
  ```
402
446
 
403
447
  **Parameters:**
404
- - `config_key`: Configuration key to use (default: None uses active key)
448
+ - `auth_config_key`: Configuration key for kiarina-lib-google-auth (default: None uses active key)
405
449
  - `**kwargs`: Additional arguments passed to `storage.Client()`
406
450
 
407
451
  **Returns:**
@@ -410,7 +454,7 @@ def get_storage_client(
410
454
  **Example:**
411
455
  ```python
412
456
  client = get_storage_client()
413
- client = get_storage_client(config_key="production")
457
+ client = get_storage_client(auth_config_key="production")
414
458
  client = get_storage_client(project="my-project") # Override project
415
459
  ```
416
460
 
@@ -421,12 +465,15 @@ Get a Google Cloud Storage bucket.
421
465
  ```python
422
466
  def get_bucket(
423
467
  config_key: str | None = None,
468
+ *,
469
+ auth_config_key: str | None = None,
424
470
  **kwargs: Any
425
471
  ) -> storage.Bucket
426
472
  ```
427
473
 
428
474
  **Parameters:**
429
- - `config_key`: Configuration key to use (default: None uses active key)
475
+ - `config_key`: Configuration key for storage settings (default: None uses active key)
476
+ - `auth_config_key`: Configuration key for authentication (default: None uses active key)
430
477
  - `**kwargs`: Additional arguments passed to `get_storage_client()`
431
478
 
432
479
  **Returns:**
@@ -439,6 +486,7 @@ def get_bucket(
439
486
  ```python
440
487
  bucket = get_bucket()
441
488
  bucket = get_bucket(config_key="production")
489
+ bucket = get_bucket(config_key="production", auth_config_key="prod_auth")
442
490
 
443
491
  # Use native google-cloud-storage API
444
492
  for blob in bucket.list_blobs(prefix="users/"):
@@ -451,15 +499,18 @@ Get a Google Cloud Storage blob.
451
499
 
452
500
  ```python
453
501
  def get_blob(
454
- config_key: str | None = None,
455
502
  blob_name: str | None = None,
503
+ *,
504
+ config_key: str | None = None,
505
+ auth_config_key: str | None = None,
456
506
  **kwargs: Any
457
507
  ) -> storage.Blob
458
508
  ```
459
509
 
460
510
  **Parameters:**
461
- - `config_key`: Configuration key to use (default: None uses active key)
462
511
  - `blob_name`: Blob name (default: None uses settings.blob_name)
512
+ - `config_key`: Configuration key for storage settings (default: None uses active key)
513
+ - `auth_config_key`: Configuration key for authentication (default: None uses active key)
463
514
  - `**kwargs`: Additional arguments passed to `get_bucket()`
464
515
 
465
516
  **Returns:**
@@ -478,6 +529,13 @@ blob = get_blob(blob_name="data.json")
478
529
  # Actual blob name will be "production/v1/data.json"
479
530
  blob = get_blob(blob_name="data.json")
480
531
 
532
+ # With custom configurations
533
+ blob = get_blob(
534
+ blob_name="data.json",
535
+ config_key="production",
536
+ auth_config_key="prod_auth"
537
+ )
538
+
481
539
  # Use native google-cloud-storage API
482
540
  blob.upload_from_string("content")
483
541
  content = blob.download_as_text()
@@ -0,0 +1,9 @@
1
+ kiarina/lib/google/cloud_storage/__init__.py,sha256=q2AdOOOHUj_D-eot8_1-atrIaCKsCg0YatUOdq3kVVE,1184
2
+ kiarina/lib/google/cloud_storage/_get_blob.py,sha256=ymvAwPZmPYC407jmLgc0uCOoo3qGh8B2zssAVkLHX_I,817
3
+ kiarina/lib/google/cloud_storage/_get_bucket.py,sha256=SaGIQqRb9UOJaosGf2pXduAEYscE_T21AHCNTaZtRGo,597
4
+ kiarina/lib/google/cloud_storage/_get_storage_client.py,sha256=lmBR2I9_vcyb0PfsiSz0BPFYBwQ6zVci75cmk9GUN5U,359
5
+ kiarina/lib/google/cloud_storage/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ kiarina/lib/google/cloud_storage/settings.py,sha256=q47sa7CjegzXT2jhIDFbAc1huESQzZ3N1tlcmtKnLGU,334
7
+ kiarina_lib_google_cloud_storage-1.6.1.dist-info/METADATA,sha256=Nq6mP13cIxD4ETZRGSuWHXWy5sX7ZRbwF7IMAZ6ymLc,22959
8
+ kiarina_lib_google_cloud_storage-1.6.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
9
+ kiarina_lib_google_cloud_storage-1.6.1.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- kiarina/lib/google/cloud_storage/__init__.py,sha256=q2AdOOOHUj_D-eot8_1-atrIaCKsCg0YatUOdq3kVVE,1184
2
- kiarina/lib/google/cloud_storage/_get_blob.py,sha256=baZ7msH9xPme3jw0mI9x2NzikapdeSyBqH_6iDdgohI,728
3
- kiarina/lib/google/cloud_storage/_get_bucket.py,sha256=Y7gX-igAkLoLhxa3cDazTAcNX_X_uUjJRUs93lcRg98,534
4
- kiarina/lib/google/cloud_storage/_get_storage_client.py,sha256=XTsjQdVN4_tqO1KX-pC4-st7As7mMxeB1XhagzuJLaY,463
5
- kiarina/lib/google/cloud_storage/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- kiarina/lib/google/cloud_storage/settings.py,sha256=QSY37za-Vi3S7fQLX7AzC5m65QxjxtuYYT9wq08Ee0o,381
7
- kiarina_lib_google_cloud_storage-1.5.0.dist-info/METADATA,sha256=SCFb0PFxO75UWAhAtGMGVTMb3KvU0N7QPjc_2MdRUuY,20994
8
- kiarina_lib_google_cloud_storage-1.5.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
9
- kiarina_lib_google_cloud_storage-1.5.0.dist-info/RECORD,,