No project description provided
Project description
GCP Impersonation wrapper
The gcp-impersonation-wrapper is a small util used to impersonate service accounts using service account. We pass the main credentials, list service accounts we can impersonate and then actually impersonate like so:
#!/usr/bin/env python3
from src.service_account import ServiceAccount
if __name__ == "__main__":
# Insert credentials here
credentials = None
service_account = ServiceAccount(
project_id="your-project-id",
impersonator_credentials=credentials
)
# Can be used in a with statement
with service_account.impersonate(
service_account_email="your-service-account-email",
target_scopes=["https://www.googleapis.com/auth/cloud-platform"],
service="iam",
version="v1"
) as impersonated_service_account:
# do something with the impersonated service account
service_accounts_the_impersonated_sacc_can_see = impersonated_service_account.service.projects(
).serviceAccounts().list().execute()
print(service_accounts_the_impersonated_sacc_can_see)
# Or as a variable
impersonated_service_account = service_account.impersonate(
service_account_email="your-service-account-email",
target_scopes=["https://www.googleapis.com/auth/cloud-platform"],
service="iam",
version="v1"
)
service_accounts_the_impersonated_sacc_can_see = impersonated_service_account.service.projects(
).serviceAccounts().list().execute()
To list the impersonatable service accounts we do:
#!/usr/bin/env python3
from src.service_account import ServiceAccount
if __name__ == "__main__":
# Insert credentials here
credentials = None
service_account = ServiceAccount(
project_id="your-project-id",
impersonator_credentials=credentials
)
# This returns a list of email like ["john@doe.com", "jane@doe.com", ....]
service_account_emails_we_can_impersonate = service_account.list_all_impersonatable_service_account_emails()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for gcp-impersonation-wrapper-0.0.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5ef103de15a54a2a23efaf534baeac634f07cd386f4724353f4688431a4f5ba |
|
MD5 | 7e6e6d12b38bef0282edeeb632f3bf71 |
|
BLAKE2b-256 | 1d57bb373eba89efc01ebc45864a92a47d75a207d584f3238cfd66e50475d123 |
Close
Hashes for gcp_impersonation_wrapper-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3369ad0d75ce66396d74d5260336819f221a6209026fe6977a48c3f009789d8 |
|
MD5 | 1d7fcf524eb9993e68d469c3a8e749b6 |
|
BLAKE2b-256 | 7694b7150bf2da72c7af5933ab64532322b676aa47af96fc2b2f47bbfcca1fce |