importosfromgoogle.cloudimportsecretmanagerimportloggingclient=secretmanager.SecretManagerServiceClient()secret_name="my-secret"project_id=os.environ.get('GCP_PROJECT')resource_name="projects/{}/secrets/{}/versions/latest".format(project_id,secret_name)response=client.access_secret_version(resource_name)secret_string=response.payload.data.decode('UTF-8')defnew_measures_handler(data,context):"""Background Cloud Function to be triggered by Cloud Storage.
Args:
event (dict): The dictionary with data specific to this type of event.
context (google.cloud.functions.Context): The Cloud Functions
event metadata.
"""logging.info(secret_string)print('File: {}.'.format(data['name']))
and if I deploy it like this on GCP it works as expected. Google Cloud Build builds the function and deploys it. Project and respectively project secret can be accessed. But, when I uncomment my test step in .yaml and it gets executed on Google Cloud Build
My main.py looks like this:
and if I deploy it like this on GCP it works as expected. Google Cloud Build builds the function and deploys it. Project and respectively project secret can be accessed. But, when I uncomment my test step in .yaml and it gets executed on Google Cloud Build
I start getting the error. As you say, I need to mock it somehow. This is how my current test looks like:
OK, so your test should monkeypatch the environment like this:
You'll probably need to monkeypatch
secretmanager.SecretManagerServiceClient
as well.