Skip to content

Instantly share code, notes, and snippets.

@famousgarkin
Created June 12, 2020 05:04
Show Gist options
  • Save famousgarkin/81ec2dd6b2de35b5e653d4724d3dbff4 to your computer and use it in GitHub Desktop.
Save famousgarkin/81ec2dd6b2de35b5e653d4724d3dbff4 to your computer and use it in GitHub Desktop.
# https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/filter/core.py
# https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/kms.html
import boto3
import base64
kms = boto3.client('kms', region_name='eu-central-1')
def aws_kms_decrypt(ciphertext):
'''
:param ciphertext: Base64 encoded ciphertext from AWS KMS encrypt
:return plaintext decrypted from given ciphertext
'''
return kms.decrypt(CiphertextBlob=base64.b64decode(ciphertext)).get('Plaintext')
class FilterModule(object):
def filters(self):
return {
'aws_kms_decrypt': aws_kms_decrypt,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment