Skip to content

Commit

Permalink
Merge pull request #19 from SPHTech-Platform/feature/disable-alerts
Browse files Browse the repository at this point in the history
removing local.external_id
  • Loading branch information
uchinda-sph authored Feb 28, 2023
2 parents 5702b5d + 313beed commit 0ddf98d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ locals {

secret_name = "/aquacspm/secret-cspm"

external_id = jsondecode(aws_lambda_invocation.external_id.result)["ExternalId"]
external_id = jsondecode(aws_lambda_invocation.external_id.result)["status"] == "FAILED" ? jsondecode(aws_lambda_invocation.external_id.result)["message"] : jsondecode(aws_lambda_invocation.external_id.result)["ExternalId"]
# public_ip = "13.215.18.141/32"

aqua_cspm_role_policy_arns = [
Expand Down
27 changes: 17 additions & 10 deletions src/lambda_function/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,22 @@ def lambda_handler(event, ctxt):
aqua_secret = conf['aqua_secret']
except Exception as e:
LOGGER.error('Error retrieving Keys: {e}')
return json.dumps({'status': 'FAILED', 'message': 'Error retrieving Keys'})
failRetKey = {'status': 'FAILED', 'message': 'Error retrieving Keys'}
return failRetKey

if event['LogicalResourceId'] == 'ExternalIDInvoke':
LOGGER.info('ExtID creation started :{}'.format(event))
try:
extid = get_ext_id(aqua_url, aqua_api_key, aqua_secret)
resData = {'ExternalId': extid}
return resData
except Exception as e:
LOGGER.error(e)
return json.dumps({'status': 'FAILED', 'message': str(e)})
max_attempts = 3
for i in range(max_attempts):
try:
extid = get_ext_id(aqua_url, aqua_api_key, aqua_secret)
resData = {'ExternalId': extid}
return resData
except Exception as e:
LOGGER.error(e)
if i == max_attempts - 1:
failExtID = {'status': 'FAILED', 'message': str(e)}
return failExtID

elif event['LogicalResourceId'] == 'OnboardingInvoke':
LOGGER.info('Onboarding started :{}'.format(event))
Expand All @@ -49,10 +54,12 @@ def lambda_handler(event, ctxt):
register(aqua_url, aqua_api_key, aqua_secret, acc, role_arn, extid, g_id)
LOGGER.info(f'Account registered {acc}')
onbData = {'AccountId': acc, 'Registered': True}
return json.dumps({'status': 'SUCCESS', 'data': onbData})
sucMsg = {'status': 'SUCCESS', 'data': onbData}
return sucMsg
except Exception as e:
LOGGER.error(e)
return json.dumps({'status': 'FAILED', 'message': str(e)})
errMsg = {'status': 'FAILED', 'message': str(e)}
return errMsg


def get_conf(secret):
Expand Down
Binary file modified src/lambda_function/lambda_function.zip
Binary file not shown.

0 comments on commit 0ddf98d

Please sign in to comment.