From 52c88b3e83c9ff65de03aa08178344e338710b6a Mon Sep 17 00:00:00 2001 From: kushal9897 Date: Wed, 16 Oct 2024 03:42:57 +0530 Subject: [PATCH 1/4] adding Type Annotations --- src/tirith/providers/infracost/handler.py | 6 +++--- src/tirith/providers/json/handler.py | 13 +++++++------ src/tirith/providers/sg_workflow/handler.py | 7 ++++--- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/tirith/providers/infracost/handler.py b/src/tirith/providers/infracost/handler.py index 956cc5f1..9ced0969 100644 --- a/src/tirith/providers/infracost/handler.py +++ b/src/tirith/providers/infracost/handler.py @@ -3,7 +3,7 @@ logger = logging.getLogger(__name__) -def __get_all_costs(operation_type, input_data): +def __get_all_costs(operation_type: str, input_data: dict) -> float: logger.debug(f"costType : {operation_type}") pointer = { "total_monthly_cost": ["totalMonthlyCost", "monthlyCost"], @@ -38,7 +38,7 @@ def __get_all_costs(operation_type, input_data): raise KeyError("projects not found in input_data") -def __get_resources_costs(resource_type, operation_type, input_data): +def __get_resources_costs(resource_type: str, operation_type: str, input_data: dict) -> float: logger.debug(f"costType : {operation_type}") pointer = {"total_monthly_cost": "totalMonthlyCost", "total_hourly_cost": "totalHourlyCost"} pointer = { @@ -77,7 +77,7 @@ def __get_resources_costs(resource_type, operation_type, input_data): raise KeyError("projects not found in input_data") -def provide(provider_args, input_data): +def provide(provider_args: dict, input_data: dict) -> List[Dict[str, Any]]: logger.debug("infracost provider") logger.debug(f"infracost provider inputs : {provider_args}") try: diff --git a/src/tirith/providers/json/handler.py b/src/tirith/providers/json/handler.py index ce4ced5b..1f6a25f0 100644 --- a/src/tirith/providers/json/handler.py +++ b/src/tirith/providers/json/handler.py @@ -1,6 +1,6 @@ import pydash -from typing import Callable, Dict, List +from typing import Callable, Dict, List, Any from ..common import create_result_dict, ProviderError, get_path_value_from_dict @@ -8,8 +8,8 @@ class PydashPathNotFound: pass -def _get_path_value_from_dict(splitted_paths, input_dict): - final_data = [] +def _get_path_value_from_dict(splitted_paths: List[str], input_dict: Dict[str, Any]) -> List[Any]: + final_data: List[Any] = [] for i, expression in enumerate(splitted_paths): intermediate_val = pydash.get(input_dict, expression, default=PydashPathNotFound) if isinstance(intermediate_val, list) and i < len(splitted_paths) - 1: @@ -28,7 +28,7 @@ def _get_path_value_from_dict(splitted_paths, input_dict): return final_data -def get_value(provider_args: Dict, input_data: Dict) -> List[dict]: +def get_value(provider_args: Dict[str, Any], input_data: Dict[str, Any]) -> List[Dict[str, Any]]: # Must be validated first whether the provider args are valid for this op type key_path: str = provider_args["key_path"] @@ -48,10 +48,11 @@ def get_value(provider_args: Dict, input_data: Dict) -> List[dict]: return outputs -SUPPORTED_OPS: Dict[str, Callable] = {"get_value": get_value} +SUPPORTED_OPS: Dict[str, Callable[[Dict[str, Any], Dict[str, Any]], List[Dict[str, Any]]]] -def provide(provider_args: Dict, input_data: Dict) -> List[Dict]: +def provide(provider_args: Dict[str, Any], input_data: Dict[str, Any]) -> List[Dict[str, Any]]: + operation_type = provider_args["operation_type"] op_handler = SUPPORTED_OPS.get(operation_type) diff --git a/src/tirith/providers/sg_workflow/handler.py b/src/tirith/providers/sg_workflow/handler.py index 29c1d9d0..266756ca 100644 --- a/src/tirith/providers/sg_workflow/handler.py +++ b/src/tirith/providers/sg_workflow/handler.py @@ -1,12 +1,13 @@ import logging +from typing import Any, Dict, List, Union logger = logging.getLogger(__name__) -def __getValue(key, data): +def __getValue(key: str, data: Dict[str, any]) -> Union[str, List[str]]: logger.debug(f"Searching {key} in input data") - result = "" + result: Union[str, List[str]] = "" if key == "integrationId": temp = [] if "DeploymentPlatformConfig" in data: @@ -70,7 +71,7 @@ def __getValue(key, data): return result -def provide(provider_args, input_data): +def provide(provider_args: Dict[str, Any], input_data: Dict[st, Any]) -> List[Dict[str, Any]]: logger.debug("sg_workflow provider") logger.debug(f"sg_workflow provider inputs : {provider_args}") try: From 68bb54964be724846043fada958d518fd7d52250 Mon Sep 17 00:00:00 2001 From: kushal9897 Date: Wed, 23 Oct 2024 05:15:15 +0530 Subject: [PATCH 2/4] fix typo --- src/tirith/providers/sg_workflow/handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tirith/providers/sg_workflow/handler.py b/src/tirith/providers/sg_workflow/handler.py index 266756ca..2dc5b946 100644 --- a/src/tirith/providers/sg_workflow/handler.py +++ b/src/tirith/providers/sg_workflow/handler.py @@ -71,7 +71,7 @@ def __getValue(key: str, data: Dict[str, any]) -> Union[str, List[str]]: return result -def provide(provider_args: Dict[str, Any], input_data: Dict[st, Any]) -> List[Dict[str, Any]]: +def provide(provider_args: Dict[str, Any], input_data: Dict[str, Any]) -> List[Dict[str, Any]]: logger.debug("sg_workflow provider") logger.debug(f"sg_workflow provider inputs : {provider_args}") try: From a43af60da0536ab971750ac6c3c0c28986729344 Mon Sep 17 00:00:00 2001 From: kushal9897 Date: Thu, 24 Oct 2024 15:26:09 +0530 Subject: [PATCH 3/4] import missing data --- src/tirith/providers/infracost/handler.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tirith/providers/infracost/handler.py b/src/tirith/providers/infracost/handler.py index 9ced0969..2f33c567 100644 --- a/src/tirith/providers/infracost/handler.py +++ b/src/tirith/providers/infracost/handler.py @@ -1,4 +1,5 @@ import logging +from typing import List, Dict, Any logger = logging.getLogger(__name__) From 6e4cc03a9352ec237be6c462294759d56f64e26e Mon Sep 17 00:00:00 2001 From: kushal9897 Date: Wed, 6 Nov 2024 15:56:14 +0530 Subject: [PATCH 4/4] adding values --- src/tirith/providers/json/handler.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tirith/providers/json/handler.py b/src/tirith/providers/json/handler.py index 1f6a25f0..7fe172ff 100644 --- a/src/tirith/providers/json/handler.py +++ b/src/tirith/providers/json/handler.py @@ -47,9 +47,9 @@ def get_value(provider_args: Dict[str, Any], input_data: Dict[str, Any]) -> List return outputs - -SUPPORTED_OPS: Dict[str, Callable[[Dict[str, Any], Dict[str, Any]], List[Dict[str, Any]]]] - +SUPPORTED_OPS: Dict[str, OperationHandlerType] = { + "get_value": get_value +} def provide(provider_args: Dict[str, Any], input_data: Dict[str, Any]) -> List[Dict[str, Any]]: