-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsubmissions.py
More file actions
85 lines (71 loc) · 2.9 KB
/
submissions.py
File metadata and controls
85 lines (71 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import json
import os
from globus_sdk import GlobusAPIError
from dynamo_manager import DynamoManager
from automate_manager import AutomateManager
from utils import get_secret
status_codes = {
"SUCCEEDED": "S",
"ACTIVE": "P",
"FAILED": "F",
"UNKNOWN": "U"
}
def format_status_record(status:dict, automate_manager:AutomateManager) -> dict:
usr_msg = ("Status of {}submission {} ({})\n"
"Submitted by {} at {}\n\n").format("TEST " if status["test"] else "",
status["source_id"],
status["title"],
status["submitter"],
status["submission_time"])
automate_status = {
"status": "UNKNOWN",
"details": {
"description": "Unknown"
}
}
if 'action-id' in status:
try:
automate_status = automate_manager.get_status(status['action_id'])
except GlobusAPIError:
automate_status["details"]['description'] = "Flow not found"
else:
automate_status["details"]['description'] = "Submission prior to GlobusAutomate"
return {
"source_id": status["source_id"],
"status_message": usr_msg,
"status_list": "need more status data",
"status_code": status_codes[automate_status['status']],
"title": status["title"],
"submitter": status["submitter"],
"submission_time": status["submission_time"],
"description": automate_status['details']['description'],
"test": status["test"],
"active": automate_status['status'] == "ACTIVE",
"original_submission": json.loads(status["original_submission"])
}
def lambda_handler(event, context):
user_id = event['requestContext']['authorizer']['user_id']
if 'filters' in event['body']:
provided_filters = json.loads(event['body'])['filters']
else:
provided_filters = []
dynamo_manager = DynamoManager()
automate_manager = AutomateManager(get_secret(secret_name=os.environ['MDF_SECRETS_NAME'],
region_name=os.environ['MDF_AWS_REGION']))
automate_manager.authenticate()
if event["pathParameters"] and "user_id" in event['pathParameters']:
requested_user_id = event['pathParameters']['user_id']
else:
requested_user_id = user_id
filters = [("user_id", "==", requested_user_id)]
filters.extend(provided_filters)
print(f"Final filters = {filters}")
scan_res = dynamo_manager.scan_table("status", filters=filters)
response = [format_status_record(status, automate_manager) for status in scan_res['results']]
return {
'statusCode' : 200,
'headers': {"content-type": "application/json"},
'body': json.dumps({
"submissions": response
})
}