aws_auth.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:okta-awscli 作者: jmhale 项目源码 文件源码
def check_sts_token(self, profile):
        """ Verifies that STS credentials are valid """
        # Don't check for creds if profile is blank
        if not profile:
            return False

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

        if not os.path.exists(self.creds_dir):
            if self.verbose:
                print("AWS credentials path does not exit. Not checking.")
            return False

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

        elif not parser.has_section(profile):
            if self.verbose:
                print("No existing credentials found. Requesting new credentials.")
            return False

        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':
                print("Temporary credentials have expired. Requesting new credentials.")
                return False

        if self.verbose:
            print("STS credentials are valid. Nothing to do.")
        return True
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号