kiarina-lib-google 2.0.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.
Files changed (25) hide show
  1. kiarina_lib_google-2.0.0/.env.sample +1 -0
  2. kiarina_lib_google-2.0.0/.gitignore +35 -0
  3. kiarina_lib_google-2.0.0/.vscode/settings.json +8 -0
  4. kiarina_lib_google-2.0.0/CHANGELOG.md +316 -0
  5. kiarina_lib_google-2.0.0/PKG-INFO +354 -0
  6. kiarina_lib_google-2.0.0/README.md +327 -0
  7. kiarina_lib_google-2.0.0/pyproject.toml +43 -0
  8. kiarina_lib_google-2.0.0/src/kiarina/lib/google/__init__.py +58 -0
  9. kiarina_lib_google-2.0.0/src/kiarina/lib/google/_helpers/get_credentials.py +64 -0
  10. kiarina_lib_google-2.0.0/src/kiarina/lib/google/_helpers/get_self_signed_jwt.py +23 -0
  11. kiarina_lib_google-2.0.0/src/kiarina/lib/google/_settings.py +123 -0
  12. kiarina_lib_google-2.0.0/src/kiarina/lib/google/_types/credentials.py +13 -0
  13. kiarina_lib_google-2.0.0/src/kiarina/lib/google/_types/credentials_cache.py +21 -0
  14. kiarina_lib_google-2.0.0/src/kiarina/lib/google/_utils/get_default_credentials.py +35 -0
  15. kiarina_lib_google-2.0.0/src/kiarina/lib/google/_utils/get_service_account_credentials.py +35 -0
  16. kiarina_lib_google-2.0.0/src/kiarina/lib/google/_utils/get_user_account_credentials.py +81 -0
  17. kiarina_lib_google-2.0.0/src/kiarina/lib/google/py.typed +0 -0
  18. kiarina_lib_google-2.0.0/test_settings.sample.yaml +32 -0
  19. kiarina_lib_google-2.0.0/tests/__init__.py +0 -0
  20. kiarina_lib_google-2.0.0/tests/conftest.py +27 -0
  21. kiarina_lib_google-2.0.0/tests/test_get_credentials.py +52 -0
  22. kiarina_lib_google-2.0.0/tests/test_get_default_credentials.py +34 -0
  23. kiarina_lib_google-2.0.0/tests/test_get_self_signed_jwt.py +9 -0
  24. kiarina_lib_google-2.0.0/tests/test_get_service_account_credentials.py +27 -0
  25. kiarina_lib_google-2.0.0/tests/test_get_user_account_credentials.py +76 -0
@@ -0,0 +1 @@
1
+ KIARINA_LIB_GOOGLE_TEST_SETTINGS_FILE=/path/to/your/test_settings.yaml
@@ -0,0 +1,35 @@
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
+ packages/*/test_settings.yaml
29
+
30
+ # Test data
31
+ tests/data/large/
32
+
33
+ # mise tasks (always include)
34
+ !.mise/tasks/
35
+ !.mise/tasks/**
@@ -0,0 +1,8 @@
1
+ {
2
+ "python.testing.pytestArgs": [
3
+ "tests"
4
+ ],
5
+ "python.testing.unittestEnabled": false,
6
+ "python.testing.pytestEnabled": true,
7
+ "python.envFile": "${workspaceFolder}/.env"
8
+ }
@@ -0,0 +1,316 @@
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
+ ## [2.0.0] - 2026-06-10
11
+
12
+ ### Changed (BREAKING)
13
+ - **kiarina-lib-google**: Package renamed from `kiarina-lib-google-auth` to `kiarina-lib-google`.
14
+ - Python module namespace simplified from `kiarina.lib.google.auth` to `kiarina.lib.google`.
15
+ - `GoogleAuthSettings` has been renamed to `GoogleSettings`.
16
+ - Environment variable prefix changed from `KIARINA_LIB_GOOGLE_AUTH_` to `KIARINA_LIB_GOOGLE_`.
17
+
18
+ ## [1.37.0] - 2026-05-27
19
+
20
+ ### Changed
21
+ - No changes
22
+
23
+ ## [1.35.0] - 2026-01-31
24
+
25
+ ### Changed
26
+ - No changes
27
+
28
+ ## [1.34.0] - 2026-01-31
29
+
30
+ ### Changed
31
+ - No changes
32
+
33
+ ## [1.33.1] - 2026-01-31
34
+
35
+ ### Changed
36
+ - No changes
37
+
38
+ ## [1.33.0] - 2026-01-31
39
+
40
+ ### Changed
41
+ - No changes
42
+
43
+ ## [1.32.0] - 2026-01-30
44
+
45
+ ### Changed
46
+ - No changes
47
+
48
+ ## [1.31.1] - 2026-01-29
49
+
50
+ ### Changed
51
+ - No changes
52
+
53
+ ## [1.31.0] - 2026-01-29
54
+
55
+ ### Changed
56
+ - No changes
57
+
58
+ ## [1.30.0] - 2026-01-27
59
+
60
+ ### Changed
61
+ - No changes
62
+
63
+ ## [1.29.0] - 2026-01-16
64
+
65
+ ### Changed
66
+ - No changes
67
+
68
+ ## [1.28.0] - 2026-01-16
69
+
70
+ ### Changed
71
+ - No changes
72
+
73
+ ## [1.27.0] - 2026-01-12
74
+
75
+ ### Changed
76
+ - No changes
77
+
78
+ ## [1.26.0] - 2026-01-09
79
+
80
+ ### Changed
81
+ - No changes
82
+
83
+ ## [1.25.1] - 2026-01-08
84
+
85
+ ### Changed
86
+ - No changes
87
+
88
+ ## [1.25.0] - 2026-01-08
89
+
90
+ ### Changed
91
+ - No changes
92
+
93
+ ## [1.24.0] - 2026-01-08
94
+
95
+ ### Changed
96
+ - No changes
97
+
98
+ ## [1.23.0] - 2026-01-06
99
+
100
+ ### Changed
101
+ - No changes
102
+
103
+ ## [1.22.1] - 2026-01-06
104
+
105
+ ### Changed
106
+ - Upgraded dependencies and removed unnecessary type ignore comments
107
+
108
+ ## [1.22.0] - 2026-01-05
109
+
110
+ ### Changed
111
+ - No changes
112
+
113
+ ## [1.21.1] - 2026-01-05
114
+
115
+ ### Changed
116
+ - No changes
117
+
118
+ ## [1.21.0] - 2025-12-30
119
+
120
+ ### Changed
121
+ - No changes
122
+
123
+ ## [1.20.1] - 2025-12-25
124
+
125
+ ### Changed
126
+ - No changes
127
+
128
+ ## [1.20.0] - 2025-12-19
129
+
130
+ ### Changed
131
+ - No changes
132
+
133
+ ## [1.19.0] - 2025-12-19
134
+
135
+ ### Changed
136
+ - No changes
137
+
138
+ ## [1.18.2] - 2025-12-17
139
+
140
+ ### Changed
141
+ - No changes
142
+
143
+ ## [1.18.1] - 2025-12-16
144
+
145
+ ### Changed
146
+ - No changes
147
+
148
+ ## [1.18.0] - 2025-12-16
149
+
150
+ ### Changed
151
+ - No changes
152
+
153
+ ## [1.17.0] - 2025-12-15
154
+
155
+ ### Changed
156
+ - No changes
157
+
158
+ ## [1.16.0] - 2025-12-15
159
+
160
+ ### Changed
161
+ - No changes
162
+
163
+ ## [1.15.1] - 2025-12-14
164
+
165
+ ### Changed
166
+ - No changes
167
+
168
+ ## [1.15.0] - 2025-12-13
169
+
170
+ ### Added
171
+ - **API key authentication**: Added support for API key authentication method
172
+ - New `type: "api_key"` option in `GoogleSettings`
173
+ - New `api_key` field for storing API keys securely with `SecretStr`
174
+ - Enables direct API key usage for Google APIs that support it
175
+
176
+ ## [1.14.0] - 2025-12-13
177
+
178
+ ### Fixed
179
+ - **Service account credentials**: Fixed scope application for service account credentials
180
+ - `get_service_account_credentials()` now accepts `scopes` parameter
181
+ - Scopes are properly applied via `with_scopes()` method
182
+ - Resolves `invalid_scope` errors when using service account credentials with Google APIs
183
+
184
+ ## [1.13.0] - 2025-12-09
185
+
186
+ ### Changed
187
+ - No changes
188
+
189
+ ## [1.12.0] - 2025-12-05
190
+
191
+ ### Changed
192
+ - Refactored internal module structure following project architecture rules
193
+ - Renamed function parameters for consistency (`config_key` → `settings_key`)
194
+
195
+ ## [1.11.2] - 2025-12-02
196
+
197
+ ### Changed
198
+ - No changes
199
+
200
+ ## [1.11.1] - 2025-12-01
201
+
202
+ ### Changed
203
+ - No changes
204
+
205
+ ## [1.11.0] - 2025-12-01
206
+
207
+ ### Changed
208
+ - No changes
209
+
210
+ ## [1.10.0] - 2025-12-01
211
+
212
+ ### Changed
213
+ - No changes
214
+
215
+ ## [1.9.0] - 2025-11-26
216
+
217
+ ### Changed
218
+ - No changes
219
+
220
+ ## [1.8.0] - 2025-10-24
221
+
222
+ ### Changed
223
+ - No changes
224
+
225
+ ## [1.7.0] - 2025-10-21
226
+
227
+ ### Changed
228
+ - Simplified credentials retrieval and caching logic in user account credentials handling
229
+
230
+ ## [1.6.3] - 2025-10-13
231
+
232
+ ### Changed
233
+ - Updated `pydantic-settings-manager` dependency from `>=2.1.0` to `>=2.3.0`
234
+ - Improved test configuration approach using YAML-based settings file instead of individual environment variables
235
+ - Tests now use `pydantic-settings-manager` with multiple named configurations for different authentication scenarios
236
+ - Added `test_settings.sample.yaml` as a template for test configuration
237
+ - Added `.env.sample` to document required environment variables
238
+ - Reorganized `GoogleSettings` field order for better readability (common fields first)
239
+ - Enhanced test coverage with more comprehensive authentication method tests
240
+ - Simplified test fixtures using session-scoped `load_settings` fixture
241
+
242
+ ## [1.6.2] - 2025-10-10
243
+
244
+ ### Changed
245
+ - No changes
246
+
247
+ ## [1.6.1] - 2025-10-10
248
+
249
+ ### Changed
250
+ - No changes
251
+
252
+ ## [1.6.0] - 2025-10-10
253
+
254
+ ### Changed
255
+ - No changes
256
+
257
+ ## [1.5.0] - 2025-10-10
258
+
259
+ ### Changed
260
+ - No changes
261
+
262
+ ## [1.4.0] - 2025-10-09
263
+
264
+ ### Added
265
+ - Initial release of kiarina-lib-google
266
+ - Google Cloud authentication library with configuration management using pydantic-settings-manager
267
+ - Multiple authentication methods:
268
+ - Default credentials (Application Default Credentials)
269
+ - Service account authentication (from file or JSON data)
270
+ - User account authentication (OAuth2 authorized user credentials)
271
+ - Service account impersonation with configurable scopes
272
+ - Credentials caching support with `CredentialsCache` protocol
273
+ - Self-signed JWT generation for service accounts
274
+ - Type safety with full type hints and Pydantic validation
275
+ - Environment variable configuration support with `KIARINA_LIB_GOOGLE_` prefix
276
+ - Runtime configuration overrides
277
+ - Multiple named configurations support via pydantic-settings-manager
278
+ - Automatic credential refresh for user accounts
279
+ - Stable cache key generation for user account credentials
280
+ - Default scopes for GCP, Google Drive, and Google Sheets
281
+
282
+ ### Features
283
+ - **`get_credentials()`**: Main function to obtain credentials based on configuration
284
+ - **`get_self_signed_jwt()`**: Generate self-signed JWTs for service account authentication
285
+ - **`get_default_credentials()`**: Utility to get default Google credentials (ADC)
286
+ - **`get_service_account_credentials()`**: Utility to get service account credentials
287
+ - **`get_user_account_credentials()`**: Utility to get user account credentials with caching
288
+ - **`GoogleSettings`**: Pydantic settings model with comprehensive configuration options
289
+ - **`CredentialsCache`**: Protocol for implementing custom credentials caching strategies
290
+ - **`Credentials`**: Type alias for all supported credential types
291
+
292
+ ### Security
293
+ - **Enhanced credential protection**: Changed `service_account_data`, `client_secret_data`, and `authorized_user_data` fields to use `SecretStr`
294
+ - Credentials are now masked in string representations and logs (displayed as `**********`)
295
+ - Prevents accidental exposure of sensitive data in debug output
296
+ - Access secret values explicitly via `.get_secret_value()` method
297
+ - Minimal breaking change: only affects direct field access (use `get_*_data()` methods instead)
298
+
299
+ ### Configuration Options
300
+ - `type`: Authentication type (default, service_account, user_account)
301
+ - `service_account_file`: Path to service account key file
302
+ - `service_account_data`: Service account key data as JSON string
303
+ - `service_account_email`: Service account email address
304
+ - `authorized_user_file`: Path to authorized user credentials file
305
+ - `authorized_user_data`: Authorized user credentials as JSON string
306
+ - `user_account_email`: User account email address
307
+ - `client_secret_file`: Path to OAuth2 client secret file
308
+ - `client_secret_data`: OAuth2 client secret as JSON string
309
+ - `impersonate_service_account`: Target service account for impersonation
310
+ - `scopes`: List of OAuth2 scopes
311
+ - `project_id`: GCP project ID
312
+
313
+ ### Dependencies
314
+ - google-api-python-client>=2.184.0
315
+ - pydantic-settings>=2.10.1
316
+ - pydantic-settings-manager>=2.1.0
@@ -0,0 +1,354 @@
1
+ Metadata-Version: 2.4
2
+ Name: kiarina-lib-google
3
+ Version: 2.0.0
4
+ Summary: Google Cloud 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-google/CHANGELOG.md
9
+ Project-URL: Documentation, https://github.com/kiarina/kiarina-python/tree/main/packages/kiarina-lib-google#readme
10
+ Author-email: kiarina <kiarinadawa@gmail.com>
11
+ Maintainer-email: kiarina <kiarinadawa@gmail.com>
12
+ License-Expression: MIT
13
+ Keywords: client,cloud,gcp,google,google-cloud,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: google-api-python-client>=2.184.0
24
+ Requires-Dist: pydantic-settings-manager>=3.2.0
25
+ Requires-Dist: pydantic-settings>=2.10.1
26
+ Description-Content-Type: text/markdown
27
+
28
+ # kiarina-lib-google
29
+
30
+ A Python library for Google Cloud authentication with configuration management using pydantic-settings-manager.
31
+
32
+ ## Features
33
+
34
+ - **Multiple Authentication Methods**: Default credentials (ADC), service accounts, and user accounts
35
+ - **Service Account Impersonation**: Delegated access with configurable scopes
36
+ - **Configuration Management**: Flexible configuration with pydantic-settings-manager
37
+ - **Credentials Caching**: Automatic caching and refresh for user accounts
38
+ - **Self-Signed JWT**: Generate JWTs for service account authentication
39
+ - **Type Safety**: Full type hints and Pydantic validation
40
+
41
+ ## Installation
42
+
43
+ ```bash
44
+ pip install kiarina-lib-google
45
+ ```
46
+
47
+ ## Quick Start
48
+
49
+ ### Default Credentials (ADC)
50
+
51
+ ```python
52
+ from kiarina.lib.google import get_credentials
53
+
54
+ # Uses Application Default Credentials
55
+ credentials = get_credentials()
56
+ ```
57
+
58
+ ### Service Account
59
+
60
+ ```python
61
+ from kiarina.lib.google import get_credentials, GoogleSettings
62
+
63
+ # From key file
64
+ credentials = get_credentials(
65
+ settings=GoogleSettings(
66
+ type="service_account",
67
+ service_account_file="~/path/to/key.json"
68
+ )
69
+ )
70
+
71
+ # From JSON data
72
+ credentials = get_credentials(
73
+ settings=GoogleSettings(
74
+ type="service_account",
75
+ service_account_data='{"type":"service_account",...}'
76
+ )
77
+ )
78
+ ```
79
+
80
+ ### User Account (OAuth2)
81
+
82
+ ```python
83
+ # From authorized user file
84
+ credentials = get_credentials(
85
+ settings=GoogleSettings(
86
+ type="user_account",
87
+ authorized_user_file="~/.config/gcloud/application_default_credentials.json",
88
+ scopes=["https://www.googleapis.com/auth/drive"]
89
+ )
90
+ )
91
+ ```
92
+
93
+ ### Service Account Impersonation
94
+
95
+ ```python
96
+ # Impersonate a service account
97
+ credentials = get_credentials(
98
+ settings=GoogleSettings(
99
+ type="service_account",
100
+ service_account_file="~/source-key.json",
101
+ impersonate_service_account="target@project.iam.gserviceaccount.com",
102
+ scopes=["https://www.googleapis.com/auth/cloud-platform"]
103
+ )
104
+ )
105
+ ```
106
+
107
+ **Note**: Source principal requires `roles/iam.serviceAccountTokenCreator` role.
108
+
109
+ ### Credentials Caching
110
+
111
+ ```python
112
+ from kiarina.lib.google import CredentialsCache
113
+
114
+ class InMemoryCache(CredentialsCache):
115
+ def __init__(self):
116
+ self._cache: str | None = None
117
+
118
+ def get(self) -> str | None:
119
+ return self._cache
120
+
121
+ def set(self, value: str) -> None:
122
+ self._cache = value
123
+
124
+ # Use cache for user account credentials
125
+ credentials = get_credentials(
126
+ settings=GoogleSettings(
127
+ type="user_account",
128
+ authorized_user_file="~/authorized-user.json",
129
+ scopes=["https://www.googleapis.com/auth/drive"]
130
+ ),
131
+ cache=InMemoryCache()
132
+ )
133
+ ```
134
+
135
+ ### Self-Signed JWT
136
+
137
+ ```python
138
+ from kiarina.lib.google import get_self_signed_jwt
139
+
140
+ jwt_token = get_self_signed_jwt(
141
+ settings=GoogleSettings(
142
+ type="service_account",
143
+ service_account_file="~/key.json"
144
+ ),
145
+ audience="https://your-service.example.com/"
146
+ )
147
+ ```
148
+
149
+ ## Configuration
150
+
151
+ ### YAML Configuration (Recommended)
152
+
153
+ ```yaml
154
+ kiarina.lib.google:
155
+ development:
156
+ type: user_account
157
+ authorized_user_file: ~/.config/gcloud/application_default_credentials.json
158
+ scopes:
159
+ - https://www.googleapis.com/auth/cloud-platform
160
+
161
+ production:
162
+ type: service_account
163
+ service_account_file: /secrets/prod-sa-key.json
164
+ project_id: your-project-id
165
+ scopes:
166
+ - https://www.googleapis.com/auth/cloud-platform
167
+
168
+ impersonation:
169
+ type: service_account
170
+ service_account_file: ~/source-key.json
171
+ impersonate_service_account: target@project.iam.gserviceaccount.com
172
+ scopes:
173
+ - https://www.googleapis.com/auth/cloud-platform
174
+ ```
175
+
176
+ Load configuration:
177
+
178
+ ```python
179
+ from pydantic_settings_manager import load_user_configs
180
+ import yaml
181
+
182
+ with open("config.yaml") as f:
183
+ config = yaml.safe_load(f)
184
+ load_user_configs(config)
185
+
186
+ # Use configured credentials
187
+ from kiarina.lib.google import get_credentials
188
+ credentials = get_credentials("production")
189
+ ```
190
+
191
+ ### Environment Variables
192
+
193
+ ```bash
194
+ export KIARINA_LIB_GOOGLE_TYPE="service_account"
195
+ export KIARINA_LIB_GOOGLE_SERVICE_ACCOUNT_FILE="~/key.json"
196
+ export KIARINA_LIB_GOOGLE_PROJECT_ID="your-project-id"
197
+ export KIARINA_LIB_GOOGLE_SCOPES="https://www.googleapis.com/auth/cloud-platform"
198
+ ```
199
+
200
+ ### Programmatic Configuration
201
+
202
+ ```python
203
+ from kiarina.lib.google import settings_manager
204
+
205
+ settings_manager.user_config = {
206
+ "dev": {
207
+ "type": "user_account",
208
+ "authorized_user_file": "~/.config/gcloud/application_default_credentials.json"
209
+ },
210
+ "prod": {
211
+ "type": "service_account",
212
+ "service_account_file": "/secrets/key.json"
213
+ }
214
+ }
215
+
216
+ settings_manager.active_key = "prod"
217
+ credentials = get_credentials()
218
+ ```
219
+
220
+ ## API Reference
221
+
222
+ ### Main Functions
223
+
224
+ #### `get_credentials(settings_key=None, *, settings=None, scopes=None, cache=None)`
225
+
226
+ Get Google Cloud credentials based on configuration.
227
+
228
+ **Parameters:**
229
+ - `settings_key` (str | None): Configuration key for multi-config setup
230
+ - `settings` (GoogleSettings | None): Settings object (overrides settings_key)
231
+ - `scopes` (list[str] | None): OAuth2 scopes (overrides settings.scopes)
232
+ - `cache` (CredentialsCache | None): Credentials cache for user accounts
233
+
234
+ **Returns:** `Credentials` - Google Cloud credentials
235
+
236
+ #### `get_self_signed_jwt(settings_key=None, *, settings=None, audience)`
237
+
238
+ Generate a self-signed JWT for service account authentication.
239
+
240
+ **Parameters:**
241
+ - `settings_key` (str | None): Configuration key
242
+ - `settings` (GoogleSettings | None): Settings object
243
+ - `audience` (str): JWT audience (target service URL)
244
+
245
+ **Returns:** `str` - Self-signed JWT token
246
+
247
+ ### Utility Functions
248
+
249
+ #### `get_default_credentials()`
250
+
251
+ Get default credentials using Application Default Credentials (ADC).
252
+
253
+ **Returns:** `Credentials`
254
+
255
+ #### `get_service_account_credentials(*, service_account_file=None, service_account_data=None)`
256
+
257
+ Get service account credentials from file or data.
258
+
259
+ **Returns:** `google.oauth2.service_account.Credentials`
260
+
261
+ #### `get_user_account_credentials(*, authorized_user_file=None, authorized_user_data=None, scopes, cache=None)`
262
+
263
+ Get user account credentials from file or data with optional caching.
264
+
265
+ **Returns:** `google.oauth2.credentials.Credentials`
266
+
267
+ ### Configuration
268
+
269
+ #### `GoogleSettings`
270
+
271
+ Pydantic settings model for authentication configuration.
272
+
273
+ **Key Fields:**
274
+ - `type`: Authentication type (`"default"`, `"service_account"`, `"user_account"`)
275
+ - `service_account_file`: Path to service account key file
276
+ - `service_account_data`: Service account key data (JSON string, SecretStr)
277
+ - `authorized_user_file`: Path to authorized user file
278
+ - `authorized_user_data`: Authorized user data (JSON string, SecretStr)
279
+ - `impersonate_service_account`: Target service account email for impersonation
280
+ - `scopes`: OAuth2 scopes (default: cloud-platform, drive, spreadsheets)
281
+ - `project_id`: GCP project ID
282
+
283
+ **Helper Methods:**
284
+ - `get_service_account_data()`: Parse service_account_data JSON
285
+ - `get_client_secret_data()`: Parse client_secret_data JSON
286
+ - `get_authorized_user_data()`: Parse authorized_user_data JSON
287
+
288
+ #### `CredentialsCache` (Protocol)
289
+
290
+ Protocol for implementing credentials cache.
291
+
292
+ **Methods:**
293
+ - `get() -> str | None`: Retrieve cached credentials (JSON string)
294
+ - `set(value: str) -> None`: Store credentials (JSON string)
295
+
296
+ ## Authentication Priority
297
+
298
+ ### Default Credentials
299
+
300
+ Uses Application Default Credentials (ADC) in this order:
301
+
302
+ 1. `GOOGLE_APPLICATION_CREDENTIALS` environment variable (service account)
303
+ 2. `gcloud auth application-default login` credentials (user account)
304
+ 3. Compute Engine metadata server (compute engine)
305
+
306
+ ### Default Scopes
307
+
308
+ - `https://www.googleapis.com/auth/cloud-platform` - All GCP resources
309
+ - `https://www.googleapis.com/auth/drive` - Google Drive
310
+ - `https://www.googleapis.com/auth/spreadsheets` - Google Sheets
311
+
312
+ Override by specifying custom scopes in configuration or function call.
313
+
314
+ ## Testing
315
+
316
+ ### Setup Test Configuration
317
+
318
+ > [!Note] ADC tests
319
+ > Tests that depend on default credentials (ADC) require you to be authenticated with Google Cloud. Run `gcloud auth application-default login` before running the tests.
320
+
321
+ ```bash
322
+ # Copy sample configuration
323
+ cp packages/kiarina-lib-google/test_settings.sample.yaml \
324
+ packages/kiarina-lib-google/test_settings.yaml
325
+
326
+ # Edit with your credentials
327
+ # Set environment variable
328
+ export KIARINA_LIB_GOOGLE_TEST_SETTINGS_FILE="packages/kiarina-lib-google/test_settings.yaml"
329
+ ```
330
+
331
+ ### Run Tests
332
+
333
+ ```bash
334
+ # Run all checks
335
+ mise run package kiarina-lib-google
336
+
337
+ # Run tests with coverage
338
+ mise run package:test kiarina-lib-google --coverage
339
+ ```
340
+
341
+ ## Dependencies
342
+
343
+ - [google-api-python-client](https://github.com/googleapis/google-api-python-client) - Google API client
344
+ - [pydantic-settings](https://docs.pydantic.dev/latest/concepts/pydantic_settings/) - Settings management
345
+ - [pydantic-settings-manager](https://github.com/kiarina/pydantic-settings-manager) - Advanced settings management
346
+
347
+ ## License
348
+
349
+ MIT License - see the [LICENSE](../../LICENSE) file for details.
350
+
351
+ ## Related Projects
352
+
353
+ - [kiarina-python](https://github.com/kiarina/kiarina-python) - Main monorepo
354
+ - [pydantic-settings-manager](https://github.com/kiarina/pydantic-settings-manager) - Configuration management library