@@ -51,9 +51,16 @@ def parse_common_details(
51
51
elif workflow_type == "archived_workflow" :
52
52
pass
53
53
54
+ user_name_str = ""
55
+ if workflow_details ["metadata" ].get ("labels" ):
56
+ user_name_str = convert_username_label_to_gen3username (
57
+ workflow_details ["metadata" ].get ("labels" ).get (GEN3_USER_METADATA_LABEL )
58
+ )
59
+
54
60
return {
55
61
"name" : workflow_details ["metadata" ].get ("name" ),
56
62
"phase" : phase ,
63
+ GEN3_USER_METADATA_LABEL : user_name_str ,
57
64
"submittedAt" : workflow_details ["metadata" ].get ("creationTimestamp" ),
58
65
"startedAt" : workflow_details ["status" ].get ("startedAt" ),
59
66
"finishedAt" : workflow_details ["status" ].get ("finishedAt" ),
@@ -72,12 +79,18 @@ def parse_details(
72
79
result ["arguments" ] = workflow_details ["spec" ].get ("arguments" )
73
80
result ["progress" ] = workflow_details ["status" ].get ("progress" )
74
81
result ["outputs" ] = workflow_details ["status" ].get ("outputs" , {})
75
- result [GEN3_USER_METADATA_LABEL ] = (
76
- workflow_details ["metadata" ].get ("labels" ).get (GEN3_USER_METADATA_LABEL )
77
- )
78
- result [GEN3_TEAM_PROJECT_METADATA_LABEL ] = convert_pod_label_to_gen3teamproject (
79
- workflow_details ["metadata" ].get ("labels" ).get (GEN3_TEAM_PROJECT_METADATA_LABEL )
80
- )
82
+ if workflow_details ["metadata" ].get ("labels" ):
83
+ result [GEN3_USER_METADATA_LABEL ] = convert_username_label_to_gen3username (
84
+ workflow_details ["metadata" ].get ("labels" ).get (GEN3_USER_METADATA_LABEL )
85
+ )
86
+ result [GEN3_TEAM_PROJECT_METADATA_LABEL ] = convert_pod_label_to_gen3teamproject (
87
+ workflow_details ["metadata" ]
88
+ .get ("labels" )
89
+ .get (GEN3_TEAM_PROJECT_METADATA_LABEL )
90
+ )
91
+ else :
92
+ result [GEN3_USER_METADATA_LABEL ] = None
93
+ result [GEN3_TEAM_PROJECT_METADATA_LABEL ] = None
81
94
return result
82
95
83
96
@@ -212,3 +225,32 @@ def get_username_from_token(header_and_or_token: str) -> str:
212
225
username = decoded .get ("context" , {}).get ("user" , {}).get ("name" )
213
226
logger .info (f"{ username } is submitting a workflow" )
214
227
return username
228
+
229
+
230
+ def convert_username_label_to_gen3username (label : str ) -> str :
231
+ """this function will reverse the conversion of a username to label as
232
+ defined by the convert_gen3username_to_pod_label function. eg "user--21" -> "!"
233
+
234
+ Args:
235
+ label (str): _description_
236
+
237
+ Returns:
238
+ : _description_
239
+ """
240
+ if label :
241
+ label = label .replace ("user-" , "" , 1 )
242
+ regex = r"-[0-9A-Za-z]{2}"
243
+ return re .sub (regex , _convert_to_label , label )
244
+ else :
245
+ return ""
246
+
247
+
248
+ def _convert_to_label (special_character_match : str ) -> str :
249
+ if match := special_character_match .group ():
250
+ match = match .strip ("-" )
251
+ try :
252
+ byte_array = bytearray .fromhex (match )
253
+ return byte_array .decode ()
254
+ except :
255
+ logger .info ("match is not hex value, return original" )
256
+ return "-" + match
0 commit comments