-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
18 lines (16 loc) · 1.04 KB
/
main.py
File metadata and controls
18 lines (16 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import base64
import functions_framework
import json
# Triggered from a message on a Cloud Pub/Sub topic.
@functions_framework.cloud_event
def hello_pubsub(cloud_event):
# Print out the data from Pub/Sub, to prove that it worked
asset_data = base64.b64decode(cloud_event.data["message"]["data"])
asset_list = json.loads(asset_data)
asset_feed_data = asset_list['asset']
if asset_feed_data['assetType'] == "cloudfunctions.googleapis.com/CloudFunction":
print("Function Name:", asset_feed_data['name'],"\nAsset Type: Cloud Function 1st Generation")
elif asset_feed_data['assetType'] == "run.googleapis.com/Service" and "goog-managed-by" in asset_feed_data["resource"]["data"]["metadata"]["labels"]:
print("Function Name:", asset_feed_data['name'],"\nAsset Type: Cloud Function 2nd Generation")
elif asset_feed_data['assetType'] == "run.googleapis.com/Service" and "goog-managed-by" not in asset_feed_data["resource"]["data"]["metadata"]["labels"]:
print("Function Name:", asset_feed_data['name'],"\nAsset Type: Cloud Run Service")