def getSecret(name, version='', region='us-east-1', table='credential-store', context=None):
    '\n    fetch and decrypt the secret called `name`\n    '
    if (not context):
        context = {}
    dynamodb = boto3.resource('dynamodb', region_name=region)
    secrets = dynamodb.Table(table)
    if (version == ''):
        response = secrets.query(Limit=1, ScanIndexForward=False, ConsistentRead=True, KeyConditionExpression=boto3.dynamodb.conditions.Key('name').eq(name))
        if (response['Count'] == 0):
            raise ItemNotFound(("Item {'name': '%s'} couldn't be found." % name))
        material = response['Items'][0]
    else:
        response = secrets.get_item(Key={'name': name, 'version': version})
        if ('Item' not in response):
            raise ItemNotFound(("Item {'name': '%s', 'version': '%s'} couldn't be found." % (name, version)))
        material = response['Item']
    kms = boto3.client('kms', region_name=region)
    try:
        kms_response = kms.decrypt(CiphertextBlob=b64decode(material['key']), EncryptionContext=context)
    except botocore.exceptions.ClientError as e:
        if (e.response['Error']['Code'] == 'InvalidCiphertextException'):
            if (context is None):
                msg = 'Could not decrypt hmac key with KMS. The credential may require that an encryption context be provided to decrypt it.'
            else:
                msg = 'Could not decrypt hmac key with KMS. The encryption context provided may not match the one used when the credential was stored.'
        else:
            msg = ('Decryption error %s' % e)
        raise KmsError(msg)
    except Exception as e:
        raise KmsError(('Decryption error %s' % e))
    key = kms_response['Plaintext'][:32]
    hmac_key = kms_response['Plaintext'][32:]
    hmac = HMAC(hmac_key, msg=b64decode(material['contents']), digestmod=SHA256)
    if (hmac.hexdigest() != material['hmac']):
        raise IntegrityError(('Computed HMAC on %s does not match stored HMAC' % name))
    dec_ctr = Counter.new(128)
    decryptor = AES.new(key, AES.MODE_CTR, counter=dec_ctr)
    plaintext = decryptor.decrypt(b64decode(material['contents'])).decode('utf-8')
    return plaintext
fetch and decrypt the secret called `name`
def getSecret(name, version=, region='us-east-1', table='credential-store', context=None):
    '\n    \n    '
    if (not context):
        context = {}
    dynamodb = boto3.resource('dynamodb', region_name=region)
    secrets = dynamodb.Table(table)
    if (version == ):
        response = secrets.query(Limit=1, ScanIndexForward=False, ConsistentRead=True, KeyConditionExpression=boto3.dynamodb.conditions.Key('name').eq(name))
        if (response['Count'] == 0):
            raise ItemNotFound(("Item {'name': '%s'} couldn't be found." % name))
        material = response['Items'][0]
    else:
        response = secrets.get_item(Key={'name': name, 'version': version})
        if ('Item' not in response):
            raise ItemNotFound(("Item {'name': '%s', 'version': '%s'} couldn't be found." % (name, version)))
        material = response['Item']
    kms = boto3.client('kms', region_name=region)
    try:
        kms_response = kms.decrypt(CiphertextBlob=b64decode(material['key']), EncryptionContext=context)
    except botocore.exceptions.ClientError as e:
        if (e.response['Error']['Code'] == 'InvalidCiphertextException'):
            if (context is None):
                msg = 'Could not decrypt hmac key with KMS. The credential may require that an encryption context be provided to decrypt it.'
            else:
                msg = 'Could not decrypt hmac key with KMS. The encryption context provided may not match the one used when the credential was stored.'
        else:
            msg = ('Decryption error %s' % e)
        raise KmsError(msg)
    except Exception as e:
        raise KmsError(('Decryption error %s' % e))
    key = kms_response['Plaintext'][:32]
    hmac_key = kms_response['Plaintext'][32:]
    hmac = HMAC(hmac_key, msg=b64decode(material['contents']), digestmod=SHA256)
    if (hmac.hexdigest() != material['hmac']):
        raise IntegrityError(('Computed HMAC on %s does not match stored HMAC' % name))
    dec_ctr = Counter.new(128)
    decryptor = AES.new(key, AES.MODE_CTR, counter=dec_ctr)
    plaintext = decryptor.decrypt(b64decode(material['contents'])).decode('utf-8')
    return plaintext