-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(secretmanager): add sample code for receiving a Pub/Sub message (#…
…138) * feat(secretmanager): add pub/sub example * feat(secretmanager): fixed linter errors for added pub/sub example * Update samples/snippets/consume_event_notification.py Co-authored-by: Dina Graves Portman <[email protected]> * lint * update copyright year Co-authored-by: Dina Graves Portman <[email protected]> Co-authored-by: Anthonios Partheniou <[email protected]>
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright 2021 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
""" | ||
sample code for consuming an event notification in a cloud function. | ||
""" | ||
|
||
import base64 | ||
|
||
|
||
# [START secretmanager_consume_event_notification] | ||
def consume_event_notification(event, unused_context): | ||
""" | ||
consume_event_notification demonstrates how to consume and process a | ||
Pub/Sub notification from Secret Manager. | ||
Args: | ||
event (dict): Event payload. | ||
unused_context (google.cloud.functions.Context): Metadata for the event. | ||
""" | ||
event_type = event['attributes']['eventType'] | ||
secret_id = event['attributes']['secretId'] | ||
secret_metadata = base64.b64decode(event['data']).decode('utf-8') | ||
return f'Received {event_type} for {secret_id}. New metadata: {secret_metadata}' | ||
# [END secretmanager_consume_event_notification] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters