in aws-cloudknox-config/ssm/CloudKnox_IAMRightsize.py [0:0]
def get_access_token(ck_config=None):
"""
Authenticate CloudKnox API - Retrieve accessToken:
:param ck_config: cloudknox config dict
:return policy: cloudknox api token
"""
assert isinstance(ck_config, dict), 'ck config must be of type dict'
conn = http.client.HTTPSConnection(ck_config['url'], ck_endpoint_port)
headers = {
'X-CloudKnox-Service-Account-Id': ck_config['serviceId'],
'X-CloudKnox-Timestamp-Millis': str(curr_time),
'Content-Type': 'application/json'
}
cloudknox_dict = {
'serviceAccountId': ck_config['serviceId'],
'accessKey': ck_config['accessKey'],
'secretKey': ck_config['secretKey']
}
payload = json.dumps(cloudknox_dict)
conn.request("POST", "/api/v2/service-account/authenticate", payload, headers)
res = conn.getresponse()
data = res.read()
data_response = json.loads(data.decode("utf-8"))
token = data_response['accessToken']
if not token:
raise Exception()
return token