Skip to content

Commit 93c6302

Browse files
committed
adding call to token dispenser
1 parent 695d816 commit 93c6302

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

bignbit/utils.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)