Skip to content

Commit

Permalink
Added Python version validation before update kms decrypt output
Browse files Browse the repository at this point in the history
  • Loading branch information
cfpipeline committed Oct 29, 2020
1 parent eda3a52 commit 6bdcd55
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion stacker/lookups/handlers/kms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import division
from __future__ import absolute_import
import codecs
import sys
from stacker.session_cache import get_session

from . import LookupHandler
Expand Down Expand Up @@ -63,5 +64,12 @@ def handle(cls, value, **kwargs):
# get raw but still encrypted value from base64 version.
decoded = codecs.decode(value, 'base64')

# check python version in your system
python3_or_later = sys.version_info[0] >= 3

# decrypt and return the plain text raw value.
return kms.decrypt(CiphertextBlob=decoded)["Plaintext"]
if python3_or_later:
return kms.decrypt(CiphertextBlob=decoded)["Plaintext"]\
.decode('utf-8')
else:
return kms.decrypt(CiphertextBlob=decoded)["Plaintext"]

0 comments on commit 6bdcd55

Please sign in to comment.