From 1cd40dceacd12044e98393020cc9427e51b928be Mon Sep 17 00:00:00 2001 From: Luis Henrique Date: Wed, 17 Apr 2024 11:35:43 -0300 Subject: [PATCH 1/2] refactor: update eval function --- faster_sam/cloudformation.py | 53 ++++++++++-------------------------- 1 file changed, 15 insertions(+), 38 deletions(-) diff --git a/faster_sam/cloudformation.py b/faster_sam/cloudformation.py index fa8e7cef..edb9bb61 100644 --- a/faster_sam/cloudformation.py +++ b/faster_sam/cloudformation.py @@ -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 @staticmethod - def base64(value: str) -> str: + def base64(value: str, template: Dict[str, Any]) -> str: """ Encode a string to base64. From 16295260ee1c70c7c13426c16b2a30bdca228b1c Mon Sep 17 00:00:00 2001 From: Luis Henrique Date: Mon, 22 Apr 2024 11:31:15 -0300 Subject: [PATCH 2/2] refactor: update eval function --- faster_sam/cloudformation.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/faster_sam/cloudformation.py b/faster_sam/cloudformation.py index 1e8997a6..936fe267 100644 --- a/faster_sam/cloudformation.py +++ b/faster_sam/cloudformation.py @@ -599,14 +599,14 @@ def eval(function: Dict[str, Any], template: Dict[str, Any]) -> Any: fun, val = list(function.items())[0] - if fun in functions.keys(): - return functions[fun](val, template) - else: + if fun not in functions: logging.warning(f"{fun} intrinsic function not implemented") return None + return functions[fun](val, template) + @staticmethod - def base64(value: str, template: Dict[str, Any]) -> str: + def base64(value: str, _: Dict[str, Any]) -> str: """ Encode a string to base64.