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.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 566768a80a15da341430ecdb27eecd2af6ee0438cd4ae63c6d4c92398d8c16d6 |
|
MD5 | 8e17ea937e301184c95bc89f18f653d1 |
|
BLAKE2b-256 | 9c6fb53f1f56dbf007aa4db1305250e87d04134e9e47810eeee9e097b4c23efb |
Close
Hashes for gcp_impersonation_wrapper-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59ca04600e2d6777b1fd943aa81eba9f244f243bc527726dbad33af7da6c3c8a |
|
MD5 | 101264bab6fb7fc4cb52460da9e8932e |
|
BLAKE2b-256 | f4ebb3a871763983276055bd123936a8ece47f4f84cc6d5f884816b6acc41d33 |