Skip to content

Commit 0ddf98d

Browse files
authored
Merge pull request #19 from SPHTech-Platform/feature/disable-alerts
removing local.external_id
2 parents 5702b5d + 313beed commit 0ddf98d

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

locals.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ locals {
33

44
secret_name = "/aquacspm/secret-cspm"
55

6-
external_id = jsondecode(aws_lambda_invocation.external_id.result)["ExternalId"]
6+
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"]
77
# public_ip = "13.215.18.141/32"
88

99
aqua_cspm_role_policy_arns = [

src/lambda_function/index.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,22 @@ def lambda_handler(event, ctxt):
2525
aqua_secret = conf['aqua_secret']
2626
except Exception as e:
2727
LOGGER.error('Error retrieving Keys: {e}')
28-
return json.dumps({'status': 'FAILED', 'message': 'Error retrieving Keys'})
28+
failRetKey = {'status': 'FAILED', 'message': 'Error retrieving Keys'}
29+
return failRetKey
2930

3031
if event['LogicalResourceId'] == 'ExternalIDInvoke':
3132
LOGGER.info('ExtID creation started :{}'.format(event))
32-
try:
33-
extid = get_ext_id(aqua_url, aqua_api_key, aqua_secret)
34-
resData = {'ExternalId': extid}
35-
return resData
36-
except Exception as e:
37-
LOGGER.error(e)
38-
return json.dumps({'status': 'FAILED', 'message': str(e)})
33+
max_attempts = 3
34+
for i in range(max_attempts):
35+
try:
36+
extid = get_ext_id(aqua_url, aqua_api_key, aqua_secret)
37+
resData = {'ExternalId': extid}
38+
return resData
39+
except Exception as e:
40+
LOGGER.error(e)
41+
if i == max_attempts - 1:
42+
failExtID = {'status': 'FAILED', 'message': str(e)}
43+
return failExtID
3944

4045
elif event['LogicalResourceId'] == 'OnboardingInvoke':
4146
LOGGER.info('Onboarding started :{}'.format(event))
@@ -49,10 +54,12 @@ def lambda_handler(event, ctxt):
4954
register(aqua_url, aqua_api_key, aqua_secret, acc, role_arn, extid, g_id)
5055
LOGGER.info(f'Account registered {acc}')
5156
onbData = {'AccountId': acc, 'Registered': True}
52-
return json.dumps({'status': 'SUCCESS', 'data': onbData})
57+
sucMsg = {'status': 'SUCCESS', 'data': onbData}
58+
return sucMsg
5359
except Exception as e:
5460
LOGGER.error(e)
55-
return json.dumps({'status': 'FAILED', 'message': str(e)})
61+
errMsg = {'status': 'FAILED', 'message': str(e)}
62+
return errMsg
5663

5764

5865
def get_conf(secret):
80 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)