in terraform-modules/cloud-functions/src/provide-billing-permissions/main.py [0:0]
def get_billing_ac(billing_acc_secret_name,secret_project):
"""Function to fetch the billing account.
Args:
billing_acc_secret_name (string); secret that holds the billing account.
secret_project; project where the secret exists.
Returns:
account (string); billing account.
"""
from google.cloud import secretmanager_v1
secret = "projects/" + secret_project + "/secrets/" + billing_acc_secret_name + "/versions/latest"
client = secretmanager_v1.SecretManagerServiceClient()
request = secretmanager_v1.AccessSecretVersionRequest(
name=secret,
)
response = client.access_secret_version(request=request)
account = str(response.payload.data,'utf-8')
return(account)