File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -325,9 +325,36 @@ def get_harmony_client(environment_str: str) -> Client:
325325 HARMONY_CLIENT = None
326326
327327 if not HARMONY_CLIENT :
328+ # Create a boto3 Lambda client for token retrieval
329+ lambda_client = boto3 .client ('lambda' , region_name = 'us-west-2' )
330+
331+ # Retrieve EDL credentials (username/password)
332+ edl_user , edl_pass = get_edl_creds ()
333+
334+ # Prepare payload to request an access token from the Lambda "token-dispenser"
335+ payload = {
336+ "action" : "edl" ,
337+ "edl_user" : edl_user ,
338+ "edl_pass" : edl_pass ,
339+ "edl_env" : environment_str ,
340+ "minimum_alive_secs" : 300 # keep token valid for at least 5 minutes
341+ }
342+
343+ # Invoke the Lambda synchronously and get the token
344+ response = lambda_client .invoke (
345+ FunctionName = 'token-dispenser' ,
346+ InvocationType = 'RequestResponse' , # wait for response
347+ Payload = json .dumps (payload ).encode ('utf-8' )
348+ )
349+
350+ # Read the payload from Lambda response and parse JSON
351+ response_payload = response ['Payload' ].read ()
352+ token = json .loads (response_payload )['access-token' ]
353+
354+ # Instantiate Harmony client with retrieved token
328355 HARMONY_CLIENT = Client (
329356 env = harmony_environ ,
330- auth = get_edl_creds () ,
357+ token = token ,
331358 should_validate_auth = HARMONY_SHOULD_VALIDATE_AUTH
332359 )
333360
You can’t perform that action at this time.
0 commit comments