Source code for stacker.tokenize_userdata

from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
import re

from troposphere import Ref, GetAtt

    "Ref": Ref,
    "Fn::GetAtt": GetAtt

split_string = "(" + "|".join([r"%s\([^)]+\)" % h for h in HELPERS]) + ")"
replace_string = \
    r"(?P<helper>%s)\((?P<args>['\"]?[^)]+['\"]?)+\)" % '|'.join(HELPERS)

split_re = re.compile(split_string)
replace_re = re.compile(replace_string)

[docs]def cf_tokenize(s): """ Parses UserData for Cloudformation helper functions. It breaks apart the given string at each recognized function (see HELPERS) and instantiates the helper function objects in place of those. Returns a list of parts as a result. Useful when used with Join() and Base64() CloudFormation functions to produce user data. ie: Base64(Join('', cf_tokenize(userdata_string))) """ t = [] parts = split_re.split(s) for part in parts: cf_func = if cf_func: args = [a.strip("'\" ") for a in"args").split(",")] t.append(HELPERS["helper")](*args).data) else: t.append(part) return t