Exemplo n.º 1
0
        def wrapper(args: Namespace, session: Session):
            exp: Exception
            code = ERROR_NONE
            sig = None

            try:
                configConsoleLogger(args.verbose)
                if not skip_args:
                    profile = Profile(session, args, validate)
                else:
                    profile = Profile(session, None, validate)

                f(profile, session)
            except AWSCLILogin as e:
                code = e.code
                exp = e
            except SIGINT as e:
                sig = 'SIGINT'
            except SIGABRT as e:
                sig = 'SIGABRT'
            except SIGTERM as e:
                sig = 'SIGTERM'
            except Exception as e:
                code = ERROR_UNKNOWN
                exp = e
            finally:
                if code:
                    logger.error(str(exp), exc_info=False)
                    logger.debug(traceback.format_exc())

                if sig:
                    logger.info('Received signal: %s. Shutting down...' % sig)

                exit(code)
Exemplo n.º 2
0
    def Profile(self, profile: str = 'default', no_args: bool = False,
                **kwargs):
        args = None if no_args else login_cli_args(**kwargs)
        session = MockSession(profile)

        self.profile = Profile(session, args)
        return self.profile
Exemplo n.º 3
0
def main(profile: Profile, session: Session):
    is_parent = True

    try:
        client = boto3.client('sts')

        # TODO force-refresh should kill refresh!
        if not profile.force_refresh:
            profile.raise_if_logged_in()

        # Must know username to lookup cookies
        profile.get_username()

        try:
            saml, roles = refresh(
                profile.ecp_endpoint_url,
                profile.cookies,
            )
        except Exception:
            creds = profile.get_credentials()
            saml, roles = authenticate(
                profile.ecp_endpoint_url,
                profile.cookies,
                *creds,
            )

        role = get_selection(roles)
        expires = save_sts_token(session, client, saml, role)

        if not profile.force_refresh:
            is_parent = daemonize(profile, session, client, role, expires)
    except Exception as e:
        raise
    finally:
        if not is_parent:
            logger.info('Exiting refresh process')
Exemplo n.º 4
0
 def Profile(self):
     self.profile = Profile(self._session, None)
     return self.profile
Exemplo n.º 5
0
 def Profile(self):
     self.profile = Profile(self._session, self._args)
     return self.profile
Exemplo n.º 6
0
def configure(profile: Profile, session: Session):
    """ Interactive login profile configuration. """
    profile.update()