Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""Create a properly formatted json string of the given session. Return the session and the region to use."""
if session.get('AccessKeyId') and session.get('SecretAccessKey') and session.get('SessionToken'):
aws_region = 'us-east-1'
temp_credentials = {
'sessionId': session['AccessKeyId'],
'sessionKey': session['SecretAccessKey'],
}
if 'SessionToken' in session:
temp_credentials['sessionToken'] = session['SessionToken']
if session.get('region'):
aws_region = session['region']
#format the credentials into a json formatted string
json_temp_credentials = json.dumps(temp_credentials)
return json_temp_credentials, aws_region
awsumepy.safe_print('Cannot use these credentials to open the AWS Console.')
exit(0)
'sessionId': auto_profile['aws_access_key_id'],
'sessionKey': auto_profile['aws_secret_access_key'],
'sessionToken': auto_profile['aws_session_token']
}
if auto_profile.get('aws_region'):
aws_region = auto_profile.get('aws_region')
elif os.environ.get('AWS_ACCESS_KEY_ID') and os.environ.get('AWS_SECRET_ACCESS_KEY') and os.environ.get('AWS_SESSION_TOKEN'):
temp_credentials = {
'sessionId': os.environ['AWS_ACCESS_KEY_ID'],
'sessionKey': os.environ['AWS_SECRET_ACCESS_KEY'],
'sessionToken': os.environ['AWS_SESSION_TOKEN']
}
if os.environ.get('AWS_REGION'):
aws_region = os.environ['AWS_REGION']
else:
awsumepy.safe_print('Cannot use these credentials to open the AWS Console.')
exit(0)
json_temp_credentials = json.dumps(temp_credentials)
return json_temp_credentials, aws_region
def open_browser_to_url(self, url, args):
"""Open the default browser to the given url. If that fails, display the url."""
if args.open_console_link:
awsumepy.safe_print(url)
else:
try:
webbrowser.open(url)
except Exception:
awsumepy.safe_print('Cannot open browser, here is the link:')
awsumepy.safe_print(url)
def open_browser_to_url(self, url, args):
"""Open the default browser to the given url. If that fails, display the url."""
if args.open_console_link:
awsumepy.safe_print(url)
else:
try:
webbrowser.open(url)
except Exception:
awsumepy.safe_print('Cannot open browser, here is the link:')
awsumepy.safe_print(url)
def open_browser_to_url(self, url, args):
"""Open the default browser to the given url. If that fails, display the url."""
if args.open_console_link:
awsumepy.safe_print(url)
else:
try:
webbrowser.open(url)
except Exception:
awsumepy.safe_print('Cannot open browser, here is the link:')
awsumepy.safe_print(url)