oktaawscli/aws_auth.py
def check_sts_token(self, profile):
        """ Verifies that STS credentials are valid """
        # Don't check for creds if profile is blank
        if not self.profile:
            return False

        parser = RawConfigParser()
        parser.read(self.creds_file)

        if not os.path.exists(self.creds_dir):
            self.logger.info("AWS credentials path does not exist. Not checking.")
            return False

        elif not os.path.isfile(self.creds_file):
            self.logger.info("AWS credentials file does not exist. Not checking.")
            return False

        elif not parser.has_section(self.profile):
            self.logger.info("No existing credentials found. Requesting new credentials.")
            return False

        self.logger.debug("Checking STS token against ARN partition: %s" % self.aws_partition)
        if self.aws_partition == AwsPartition.AWS_US_GOV:
            session = boto3.Session(profile_name=profile, region_name='us-gov-west-1')
        else:
            session = boto3.Session(profile_name=profile)

        sts = session.client('sts')
        try:
            sts.get_caller_identity()

        except ClientError as ex:
            if ex.response['Error']['Code'] == 'ExpiredToken':
                self.logger.info("Temporary credentials have expired. Requesting new credentials.")
            elif ex.response['Error']['Code'] == 'InvalidClientTokenId':
                self.logger.info("Credential is invalid. Requesting new credentials.")
            else:
                # See https://docs.aws.amazon.com/STS/latest/APIReference/CommonErrors.html
                self.logger.info("An unhandled error occurred. Requesting new credentials.")

            return False

        self.logger.info("STS credentials are valid. Nothing to do.")
        return True
 Verifies that STS credentials are valid 
Verifies that STS credentials are valid
Verifies that STS credentials are valid
def check_sts_token(self, profile):
        if not self.profile:
            return False
        parser = RawConfigParser()
        parser.read(self.creds_file)
        if not os.path.exists(self.creds_dir):
            self.logger.info("AWS credentials path does not exist. Not checking.")
            return False
        elif not os.path.isfile(self.creds_file):
            self.logger.info("AWS credentials file does not exist. Not checking.")
            return False
        elif not parser.has_section(self.profile):
            self.logger.info("No existing credentials found. Requesting new credentials.")
            return False
        self.logger.debug("Checking STS token against ARN partition: %s" % self.aws_partition)
        if self.aws_partition == AwsPartition.AWS_US_GOV:
            session = boto3.Session(profile_name=profile, region_name='us-gov-west-1')
        else:
            session = boto3.Session(profile_name=profile)
        sts = session.client('sts')
        try:
            sts.get_caller_identity()
        except ClientError as ex:
            if ex.response['Error']['Code'] == 'ExpiredToken':
                self.logger.info("Temporary credentials have expired. Requesting new credentials.")
            elif ex.response['Error']['Code'] == 'InvalidClientTokenId':
                self.logger.info("Credential is invalid. Requesting new credentials.")
            else:
                self.logger.info("An unhandled error occurred. Requesting new credentials.")
            return False
        self.logger.info("STS credentials are valid. Nothing to do.")
        return True
def check_sts_token ( self , profile ) : if not self . profile : return False parser = RawConfigParser ( ) parser . read ( self . creds_file ) if not os . path . exists ( self . creds_dir ) : self . logger . info ( "AWS credentials path does not exist. Not checking." ) return False elif not os . path . isfile ( self . creds_file ) : self . logger . info ( "AWS credentials file does not exist. Not checking." ) return False elif not parser . has_section ( self . profile ) : self . logger . info ( "No existing credentials found. Requesting new credentials." ) return False self . logger . debug ( "Checking STS token against ARN partition: %s" % self . aws_partition ) if self . aws_partition == AwsPartition . AWS_US_GOV : session = boto3 . Session ( profile_name = profile , region_name = 'us-gov-west-1' ) else : session = boto3 . Session ( profile_name = profile ) sts = session . client ( 'sts' ) try : sts . get_caller_identity ( ) except ClientError as ex : if ex . response [ 'Error' ] [ 'Code' ] == 'ExpiredToken' : self . logger . info ( "Temporary credentials have expired. Requesting new credentials." ) elif ex . response [ 'Error' ] [ 'Code' ] == 'InvalidClientTokenId' : self . logger . info ( "Credential is invalid. Requesting new credentials." ) else : self . logger . info ( "An unhandled error occurred. Requesting new credentials." ) return False self . logger . info ( "STS credentials are valid. Nothing to do." ) return True
Verifies that STS credentials are valid
Verifies that STS credentials are valid
""" Verifies that STS credentials are valid """ # Don't check for creds if profile is blank # See https://docs.aws.amazon.com/STS/latest/APIReference/CommonErrors.html
self
profile