Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update eval function #172

Open
wants to merge 3 commits into
base: feat/add-sub-function
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 15 additions & 38 deletions faster_sam/cloudformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,50 +586,27 @@ def eval(function: Dict[str, Any], template: Dict[str, Any]) -> Any:
NotImplementedError
If the intrinsic function is not implemented.
"""
implemented = (
"Fn::Base64",
"Fn::FindInMap",
"Fn::GetAtt",
"Fn::Join",
"Fn::Select",
"Fn::Split",
"Fn::Sub",
"Ref",
)
functions = {
"Fn::Base64": IntrinsicFunctions.base64,
"Fn::FindInMap": IntrinsicFunctions.find_in_map,
"Fn::GetAtt": IntrinsicFunctions.get_att,
"Fn::Join": IntrinsicFunctions.join,
"Fn::Select": IntrinsicFunctions.select,
"Fn::Split": IntrinsicFunctions.split,
"Fn::Sub": IntrinsicFunctions.sub,
"Ref": IntrinsicFunctions.ref,
}

fun, val = list(function.items())[0]

if fun not in implemented:
if fun in functions.keys():
return functions[fun](val, template)
else:
logging.warning(f"{fun} intrinsic function not implemented")

if "Fn::Base64" == fun:
return IntrinsicFunctions.base64(val)

if "Fn::FindInMap" == fun:
return IntrinsicFunctions.find_in_map(val, template)

if "Fn::GetAtt" == fun:
return IntrinsicFunctions.get_att(val, template)

if "Fn::Join" == fun:
return IntrinsicFunctions.join(val, template)

if "Fn::Select" == fun:
return IntrinsicFunctions.select(val, template)

if "Fn::Split" == fun:
return IntrinsicFunctions.split(val, template)

if "Fn::Sub" == fun:
return IntrinsicFunctions.sub(val, template)

if "Ref" == fun:
return IntrinsicFunctions.ref(val, template)

return None
return None
Luis-Henrique marked this conversation as resolved.
Show resolved Hide resolved

@staticmethod
def base64(value: str) -> str:
def base64(value: str, template: Dict[str, Any]) -> str:
Luis-Henrique marked this conversation as resolved.
Show resolved Hide resolved
"""
Encode a string to base64.

Expand Down