in microservices/storage_logging/main.py [0:0]
def storage_event():
envelope = request.get_json()
message = envelope['message']
attributes = message['attributes'] # Event meta data
if attributes['eventType'] != 'OBJECT_FINALIZE':
resp = {'message': 'This is not a file upload event.'}
return resp, 200
data = json.loads(base64.b64decode(message['data']).decode('utf-8')) # Event body
data['timestamp'] = datetime.datetime.utcnow() # Add timestamp
incomplete_key = ds_client.key('StorageLog') # Create a new key for kind 'StorageLog'.
event_entity = datastore.Entity(key=incomplete_key) # Create a new entity.
event_entity.update(data) # Update the entity's contents.
ds_client.put(event_entity) # Store the entity in Datastore.
return data, 200