Skip to content

Commit

Permalink
fixed console command when no creds are set
Browse files Browse the repository at this point in the history
  • Loading branch information
SpenGietz committed May 6, 2020
1 parent 222c8de commit c01ad1d
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions pacu.py
Original file line number Diff line number Diff line change
Expand Up @@ -1060,10 +1060,17 @@ def import_module_by_name(self, module_name, include=()):
def print_web_console_url(self):
active_session = self.get_active_session()

if not active_session.access_key_id:
print(' No access key has been set. Not generating the URL.')
return
if not active_session.secret_access_key:
print(' No secret key has been set. Not generating the URL.')
return

sts = self.get_boto3_client('sts')

res = sts.get_federation_token(
Name=active_session.name,
Name=active_session.key_alias,
Policy=json.dumps({
'Version': '2012-10-17',
'Statement': [
Expand Down Expand Up @@ -1091,7 +1098,7 @@ def print_web_console_url(self):

params = {
'Action': 'login',
'Issuer': active_session.name,
'Issuer': active_session.key_alias,
'Destination': 'https://console.aws.amazon.com/console/home',
'SigninToken': signin_token
}
Expand Down Expand Up @@ -1539,6 +1546,13 @@ def get_boto3_client(self, service, region=None, user_agent=None, socks_port=800
session = self.get_active_session()
proxy_settings = self.get_proxy_settings()

if not session.access_key_id:
print(' No access key has been set. Failed to generate boto3 Client.')
return
if not session.secret_access_key:
print(' No secret key has been set. Failed to generate boto3 Client.')
return

# If there is not a custom user_agent passed into this function
# and session.boto_user_agent is set, use that as the user agent
# for this client. If both are set, the incoming user_agent will
Expand Down Expand Up @@ -1567,6 +1581,13 @@ def get_boto3_resource(self, service, region=None, user_agent=None, socks_port=8
session = self.get_active_session()
proxy_settings = self.get_proxy_settings()

if not session.access_key_id:
print(' No access key has been set. Failed to generate boto3 Resource.')
return
if not session.secret_access_key:
print(' No secret key has been set. Failed to generate boto3 Resource.')
return

if user_agent is None and session.boto_user_agent is not None:
user_agent = session.boto_user_agent

Expand Down

0 comments on commit c01ad1d

Please sign in to comment.