(iam_client, creds, blessconfig, bless_cache)
return role_creds
Args:
        iam_client: boto3 iam client
        creds: User credentials with rights to assume the use-bless role, or None for boto to
            use its default search
        blessconfig: BlessConfig object
        bless_cache: BlessCache object
Args:
        iam_client: boto3 iam client
        creds: User credentials with rights to assume the use-bless role, or None for boto to
            use its default search
        blessconfig: BlessConfig object
        bless_cache: BlessCache object
Args : iam_client : boto3 iam client creds : User credentials with rights to assume the use - bless role or None for boto to use its default search blessconfig : BlessConfig object bless_cache : BlessCache object
def get_blessrole_credentials(iam_client, creds, blessconfig, bless_cache):
    """
    Args:
        iam_client: boto3 iam client
        creds: User credentials with rights to assume the use-bless role, or None for boto to
            use its default search
        blessconfig: BlessConfig object
        bless_cache: BlessCache object
    """
    role_creds = uncache_creds(bless_cache.get('blessrole_creds'))
    if role_creds and role_creds['Expiration'] > time.gmtime():
        return role_creds

    lambda_config = blessconfig.get_lambda_config()
    if creds is not None:
        mfa_sts_client = boto3.client(
            'sts',
            aws_access_key_id=creds['AccessKeyId'],
            aws_secret_access_key=creds['SecretAccessKey'],
            aws_session_token=creds['SessionToken']
        )
    else:
        mfa_sts_client = boto3.client('sts')

    user_arn = bless_cache.get('userarn')
    if not user_arn:
        user = iam_client.get_user()['User']
        user_arn = user['Arn']
        bless_cache.set('username', user['UserName'])
        bless_cache.set('userarn', user_arn)
        bless_cache.save()

    role_arn = awsmfautils.get_role_arn(
        user_arn,
        lambda_config['userrole'],
        lambda_config['accountid']
    )

    logging.debug("Role Arn: {}".format(role_arn))

    role_creds = mfa_sts_client.assume_role(
        RoleArn=role_arn,
        RoleSessionName='mfaassume',
        DurationSeconds=blessconfig.get_client_config()['usebless_role_session_length'],
    )['Credentials']

    logging.debug("Role Credentials: {}".format(role_creds))
    bless_cache.set('blessrole_creds', make_cachable_creds(role_creds))
    bless_cache.save()

    return role_creds
def get_blessrole_credentials ( iam_client , creds , blessconfig , bless_cache ) : role_creds = uncache_creds ( bless_cache . get ( 'blessrole_creds' ) ) if role_creds and role_creds [ 'Expiration' ] > time . gmtime ( ) : return role_creds lambda_config = blessconfig . get_lambda_config ( ) if creds is not None : mfa_sts_client = boto3 . client ( 'sts' , aws_access_key_id = creds [ 'AccessKeyId' ] , aws_secret_access_key = creds [ 'SecretAccessKey' ] , aws_session_token = creds [ 'SessionToken' ] ) else : mfa_sts_client = boto3 . client ( 'sts' ) user_arn = bless_cache . get ( 'userarn' ) if not user_arn : user = iam_client . get_user ( ) [ 'User' ] user_arn = user [ 'Arn' ] bless_cache . set ( 'username' , user [ 'UserName' ] ) bless_cache . set ( 'userarn' , user_arn ) bless_cache . save ( ) role_arn = awsmfautils . get_role_arn ( user_arn , lambda_config [ 'userrole' ] , lambda_config [ 'accountid' ] ) logging . debug ( "Role Arn: {}" . format ( role_arn ) ) role_creds = mfa_sts_client . assume_role ( RoleArn = role_arn , RoleSessionName = 'mfaassume' , DurationSeconds = blessconfig . get_client_config ( ) [ 'usebless_role_session_length' ] , ) [ 'Credentials' ] logging . debug ( "Role Credentials: {}" . format ( role_creds ) ) bless_cache . set ( 'blessrole_creds' , make_cachable_creds ( role_creds ) ) bless_cache . save ( ) return role_creds