API Reference
Utilities and tools for Google Cloud
APIResolutionError
Bases: Exception
Raised when an API display name cannot be uniquely resolved to a service ID.
Source code in src/pdum/gcp/types/exceptions.py
6 7 8 9 | |
BillingAccount
dataclass
Information about a GCP billing account.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Billing account ID (for example |
display_name |
str
|
Human-friendly billing account name. |
status |
str
|
Status indicator such as |
Source code in src/pdum/gcp/types/billing_account.py
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 | |
__bool__()
Return True for regular billing accounts.
Notes
Truthiness does not reflect the status field; even a CLOSED account
is truthy. Use status to inspect openness if needed.
Source code in src/pdum/gcp/types/billing_account.py
27 28 29 30 31 32 33 34 35 36 | |
Container
dataclass
Bases: Resource
Base class for GCP resource containers (Organizations, Folders, and NO_ORG).
This base class provides common functionality for all container types that can hold projects and folders.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Container identifier (numeric for organizations/folders, empty for |
resource_name |
str
|
Fully-qualified resource name (e.g., |
display_name |
str
|
Human-readable label for the container. |
_credentials |
(Credentials, optional)
|
Cached credentials used for API calls when provided. |
Source code in src/pdum/gcp/types/container.py
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 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | |
cd(path, *, credentials=None)
Navigate to a child folder using a slash-separated path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path like |
required |
credentials
|
Credentials
|
Explicit credentials to use. If |
None
|
Returns:
| Type | Description |
|---|---|
Folder
|
The matching folder. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the path is empty or a component is not found. |
TypeError
|
If invoked on |
Source code in src/pdum/gcp/types/container.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | |
create_folder(display_name, *, credentials=None)
Create a new folder as a child of this container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display_name
|
str
|
Human-readable name for the folder. |
required |
credentials
|
Credentials
|
Explicit credentials to use. When omitted, stored credentials or ADC are used. |
None
|
Returns:
| Type | Description |
|---|---|
Folder
|
The newly created folder. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always raised on the base class; subclasses must implement this method. |
Source code in src/pdum/gcp/types/container.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
create_project(project_id, display_name, *, billing_account=None, credentials=None, timeout=600.0, polling_interval=5.0)
Create a new project under this container and optionally attach billing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
str
|
The new project's ID (must satisfy GCP constraints). |
required |
display_name
|
str
|
Human-friendly display name for the project. |
required |
billing_account
|
BillingAccount | str | None
|
Billing account to attach after creation. If omitted or falsy (e.g., |
None
|
credentials
|
Credentials
|
Explicit credentials to use. If |
None
|
timeout
|
float
|
Max seconds to wait for the long-running create operation. |
600.0
|
polling_interval
|
float
|
Seconds between operation polls. |
5.0
|
Returns:
| Type | Description |
|---|---|
Project
|
The created project materialized as a Project instance. |
Raises:
| Type | Description |
|---|---|
HttpError
|
If any API call fails. |
TimeoutError
|
If creation does not complete within |
RuntimeError
|
If the create operation completes with an error. |
Notes
This method mutates GCP estate (creates resources, may attach billing). Do not run in CI. Prefer invoking manually with appropriate credentials.
Source code in src/pdum/gcp/types/container.py
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 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | |
folders(*, credentials=None)
List folders that are direct children of this container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credentials
|
Credentials
|
Explicit credentials to use. When omitted, stored credentials or ADC are used. |
None
|
Returns:
| Type | Description |
|---|---|
list[Folder]
|
Direct child folders of this container. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always raised on the base class; subclasses must implement this method. |
Source code in src/pdum/gcp/types/container.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
list_roles(*, credentials=None, user_email=None)
List IAM roles for a user on this container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credentials
|
Credentials
|
Explicit credentials to use. When omitted, stored credentials or ADC are used. |
None
|
user_email
|
str
|
Identity to query. If omitted, the email associated with the credentials is used. |
None
|
Returns:
| Type | Description |
|---|---|
list[Role]
|
Roles that directly bind the user on this container. |
Source code in src/pdum/gcp/types/container.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
parent(*, credentials=None)
Get the parent container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credentials
|
Credentials
|
Explicit credentials to use. When omitted, stored credentials or ADC are used. |
None
|
Returns:
| Type | Description |
|---|---|
Container or None
|
The parent container (organization or folder), or |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always raised on the base class; subclasses must implement this method. |
Source code in src/pdum/gcp/types/container.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
projects(*, credentials=None)
List projects that are direct children of this container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credentials
|
Credentials
|
Explicit credentials to use. When omitted, stored credentials or ADC are used. |
None
|
Returns:
| Type | Description |
|---|---|
list[Project]
|
Direct child projects of this container. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always raised on the base class; subclasses must implement this method. |
Source code in src/pdum/gcp/types/container.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
tree(*, credentials=None, _prefix='', _is_last=True)
Print a visual tree of this container and its children.
Source code in src/pdum/gcp/types/container.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
walk_projects(*, credentials=None, active_only=True)
Recursively yield all projects within this container and its subfolders.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credentials
|
Credentials
|
Explicit credentials to use. When omitted, stored credentials or ADC are used. |
None
|
active_only
|
bool
|
If |
True
|
Yields:
| Type | Description |
|---|---|
Project
|
Projects discovered in this container and all nested folders. |
Source code in src/pdum/gcp/types/container.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
Folder
dataclass
Bases: Container
Information about a GCP folder.
Source code in src/pdum/gcp/types/folder.py
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 | |
create_folder(display_name, *, credentials=None)
Create a folder directly under this folder.
Source code in src/pdum/gcp/types/folder.py
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 | |
folders(*, credentials=None)
List direct child folders of this folder.
Source code in src/pdum/gcp/types/folder.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
parent(*, credentials=None)
Return the parent container.
Source code in src/pdum/gcp/types/folder.py
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 | |
projects(*, credentials=None)
List direct child projects of this folder.
Source code in src/pdum/gcp/types/folder.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
MultiRegion
Bases: Enum
Canonical set of Google Cloud multi-regions.
Source code in src/pdum/gcp/types/region.py
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 | |
description
property
Human-readable description for the multi-region.
multi_region_id
property
Identifier for the multi-region (e.g., nam5).
read_write_regions
property
Regions that accept read-write traffic.
witness_region
property
Witness region used for tie-breaking.
from_multi_region_id(multi_region_id)
classmethod
Return the enum entry matching multi_region_id.
Source code in src/pdum/gcp/types/region.py
143 144 145 146 147 148 149 150 151 | |
Organization
dataclass
Bases: Container
Information about a GCP organization.
Source code in src/pdum/gcp/types/organization.py
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 | |
add_user_as_owner(user_email, *, credentials=None)
Grant a user a standard set of high-privilege org roles.
Source code in src/pdum/gcp/types/organization.py
166 167 168 169 170 171 172 | |
add_user_roles(user_email, roles_to_add, *, credentials=None)
Add a user to one or more IAM roles at the Organization level.
Source code in src/pdum/gcp/types/organization.py
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 | |
billing_accounts(*, credentials=None, open_only=True)
List billing accounts scoped to this organization.
Source code in src/pdum/gcp/types/organization.py
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 | |
create_folder(display_name, *, credentials=None)
Create a folder directly under this organization.
Source code in src/pdum/gcp/types/organization.py
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 | |
folders(*, credentials=None)
List direct child folders of this organization.
Source code in src/pdum/gcp/types/organization.py
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 | |
lookup(org_id, *, credentials=None)
classmethod
Return an Organization by id using CRM v3.
Source code in src/pdum/gcp/types/organization.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
parent(*, credentials=None)
Return the parent container (organizations are roots, so None).
Source code in src/pdum/gcp/types/organization.py
38 39 40 | |
projects(*, credentials=None)
List direct child projects of this organization.
Source code in src/pdum/gcp/types/organization.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
Project
dataclass
Bases: Resource
Information about a GCP project.
Source code in src/pdum/gcp/types/project.py
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 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | |
add_user_as_owner(user_email, *, credentials=None)
Add a user to the project's Owners (roles/owner) binding.
Source code in src/pdum/gcp/types/project.py
356 357 358 359 360 361 | |
billing_account(*, credentials=None)
Return the project's billing account or NO_BILLING_ACCOUNT.
Source code in src/pdum/gcp/types/project.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
bootstrap_quota_project(*, credentials=None, timeout=300.0, verbose=True, polling_interval=5.0)
Enable the required APIs for using this project as a quota project.
Source code in src/pdum/gcp/types/project.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
create_firestore_db(database_id='(default)', *, region, credentials=None, concurrency_mode=gfa_database.Database.ConcurrencyMode.OPTIMISTIC, edition=gfa_database.Database.DatabaseEdition.STANDARD)
Create a Firestore Native database for this project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database_id
|
str
|
Identifier for the database. Use the special |
"(default)"
|
region
|
Region or MultiRegion
|
Target region or multi-region to host the database. |
required |
credentials
|
Credentials
|
Explicit credentials to use. When omitted, stored project credentials or ADC are used. |
None
|
concurrency_mode
|
ConcurrencyMode
|
Optional concurrency mode override. Defaults to |
OPTIMISTIC
|
edition
|
DatabaseEdition
|
Firestore edition to provision. Defaults to |
STANDARD
|
Returns:
| Type | Description |
|---|---|
Operation
|
Long-running operation representing the create database request. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Source code in src/pdum/gcp/types/project.py
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
enable_apis(api_list, *, credentials=None, timeout=300.0, verbose=True, polling_interval=5.0)
Enable multiple APIs for this project using batch enable.
Source code in src/pdum/gcp/types/project.py
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 | |
enabled_apis(*, credentials=None)
List enabled APIs for this project.
Source code in src/pdum/gcp/types/project.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
ensure_apis(apis, *, credentials=None, timeout=300.0, verbose=True, polling_interval=5.0)
Ensure the given APIs are enabled for this project.
Source code in src/pdum/gcp/types/project.py
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 | |
give_user_role(role, user_email, *, credentials=None, verbose=True)
Grant an IAM role to a user on this project.
Source code in src/pdum/gcp/types/project.py
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | |
list_roles(*, credentials=None, user_email=None)
List IAM roles for a user on this project.
Source code in src/pdum/gcp/types/project.py
297 298 299 300 301 302 303 304 305 306 307 | |
lookup(project_id, *, credentials=None)
classmethod
Return a Project by id using CRM v3 and resolve its parent.
Source code in src/pdum/gcp/types/project.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | |
suggest_name(*, prefix=None, random_digits=5)
classmethod
Suggest a valid GCP project id using an optional prefix.
Source code in src/pdum/gcp/types/project.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
update_billing_account(billing_account, *, credentials=None)
Update this project's billing account.
Source code in src/pdum/gcp/types/project.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
update_billing_account_for_id(project_id, billing_account, *, credentials=None)
classmethod
Class-level variant to update billing using a project id.
Source code in src/pdum/gcp/types/project.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
Region
Bases: Enum
Canonical set of Google Cloud regions.
Source code in src/pdum/gcp/types/region.py
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 | |
continent
property
Continent grouping for the region.
description
property
Human-readable description for the region.
region_id
property
Region identifier (e.g., us-west1).
from_region_id(region_id)
classmethod
Return the enum entry matching region_id.
Source code in src/pdum/gcp/types/region.py
79 80 81 82 83 84 85 86 87 | |
doctor(*, credentials=None, console=None)
Run environment diagnostics for pdum.gcp.
This prints a human-friendly report:
1) Identity and quota project status (ADC).
2) Enabled APIs on the quota project vs. required APIs used by this package.
3) Organization-level role coverage for the current identity vs. a standard
high-privilege set used by Organization.add_user_as_owner.
Notes
- Read-only: does not mutate any resources.
- Role detection is based on direct user bindings; group-based grants may not appear. Use IAM policy viewers to validate group grants.
Source code in src/pdum/gcp/admin.py
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 | |
get_email(*, credentials=None)
Return the email for the provided credentials or ADC.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credentials
|
Credentials
|
Explicit Google Cloud credentials to use. If |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The email address associated with the active identity. |
Raises:
| Type | Description |
|---|---|
DefaultCredentialsError
|
If no credentials can be found. |
AttributeError
|
If an email cannot be extracted from the credential type. |
Examples:
>>> from pdum.gcp.admin import get_email
>>> get_email()
'user@example.com'
Source code in src/pdum/gcp/admin.py
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 | |
get_iam_policy(resource, *, credentials=None)
Return the IAM policy for a Resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource
|
Resource
|
Any CRM resource implementing |
required |
credentials
|
Credentials
|
Explicit credentials to use; if omitted, uses the resource's stored creds or ADC. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
The IAM policy for the resource. |
Source code in src/pdum/gcp/admin.py
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 | |
list_organizations(*, credentials=None)
List organizations visible to the caller.
Uses Cloud Resource Manager v1 to search all organizations the current
identity can see. If projects exist outside an organization, NO_ORG is
appended to the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credentials
|
Credentials
|
Explicit credentials to use. If |
None
|
Returns:
| Type | Description |
|---|---|
list[Organization]
|
Organizations accessible to the caller, plus |
Raises:
| Type | Description |
|---|---|
DefaultCredentialsError
|
If no credentials can be found. |
HttpError
|
If the API call fails. |
Notes
Requires the Cloud Resource Manager API and basic permissions on target organizations (e.g., Viewer).
Source code in src/pdum/gcp/admin.py
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 | |
list_roles(resource, *, user_email=None, credentials=None)
List IAM roles for a user on a Resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource
|
Resource
|
Any CRM resource implementing |
required |
user_email
|
str
|
If provided, list roles for this email. If omitted, uses the email derived from the provided ADC/credentials. |
None
|
credentials
|
Credentials
|
Explicit credentials to use; if omitted, uses the resource's stored creds or ADC. |
None
|
Returns:
| Type | Description |
|---|---|
list[Role]
|
Roles that directly bind the user on the resource. |
Source code in src/pdum/gcp/admin.py
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 | |
lookup_api(display_name)
Resolve a human-friendly API name to its service id.
Uses normalization, substring checks (for short queries), and fuzzy matching against the bundled API map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display_name
|
str
|
Human-readable API name, e.g. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Service id such as |
Raises:
| Type | Description |
|---|---|
APIResolutionError
|
If no match or multiple ambiguous matches are found. |
FileNotFoundError
|
If the API map data file is missing. |
Examples:
>>> from pdum.gcp import lookup_api
>>> lookup_api("Compute Engine")
'compute.googleapis.com'
>>> lookup_api("Big Query")
'bigquery.googleapis.com'
Source code in src/pdum/gcp/admin.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | |
quota_project(*, credentials=None)
Return the active quota (billing) project from ADC credentials.
This reads credentials.quota_project_id from Application Default
Credentials (ADC) and looks up the corresponding Project. The quota
project determines which project is billed for requests made with ADC.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credentials
|
Credentials
|
Explicit credentials to use. If |
None
|
Returns:
| Type | Description |
|---|---|
Project
|
The resolved quota project. |
Raises:
| Type | Description |
|---|---|
DefaultCredentialsError
|
If no credentials can be found. |
ValueError
|
If the credentials do not have a quota project set. Use:
|
HttpError
|
If the project lookup API call fails. |
Examples:
>>> from pdum.gcp.admin import quota_project
>>> qp = quota_project()
>>> qp.id
'my-quota-project'
Source code in src/pdum/gcp/admin.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
walk_projects(*, credentials=None, active_only=True)
Yield all projects across all accessible organizations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credentials
|
Credentials
|
Explicit credentials to use. If |
None
|
active_only
|
bool
|
If |
True
|
Yields:
| Type | Description |
|---|---|
Project
|
Projects from organizations and nested folders. |
Raises:
| Type | Description |
|---|---|
DefaultCredentialsError
|
If no credentials can be found. |
HttpError
|
If any API call fails. |
Notes
Traversal may take time in estates with many organizations/folders.
Source code in src/pdum/gcp/admin.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |