11import os
22from abc import ABCMeta
33
4- # from cloudshell.api.cloudshell_api import ResourceAttribute
5-
64from cloudshell .iac .terraform .models .shell_helper import ShellHelperObject
75
86
@@ -14,13 +12,10 @@ def set_env_vars_based_on_clp(self):
1412 raise NotImplementedError ()
1513
1614 @staticmethod
17- def get_attribute_value (clp_res_model , clp_attribute , attr_name_to_check , shell_helper , decrypt = False ) -> str :
15+ def does_attribute_match (clp_res_model , clp_attribute , attr_name_to_check ) -> bool :
1816 if f"{ clp_res_model } .{ clp_attribute .Name } " == attr_name_to_check or clp_attribute .Name == attr_name_to_check :
19- if decrypt :
20- return shell_helper .api .DecryptPassword (clp_attribute .Value ).Value
21- else :
22- return clp_attribute .Value
23- return ""
17+ return True
18+ return False
2419
2520
2621class AWSCloudProviderEnvVarHandler (BaseCloudProviderEnvVarHandler ):
@@ -31,17 +26,17 @@ def __init__(self, clp_res_model: str, clp_resource_attributes: list,
3126 self ._clp_resource_attributes = clp_resource_attributes
3227 self ._shell_helper = shell_helper
3328
34- def set_aws_env_vars_based_on_clp (self ):
29+ def set_env_vars_based_on_clp (self ):
3530 dec_access_key = ""
3631 dec_secret_key = ""
3732 region_flag = False
3833
3934 for attr in self ._clp_resource_attributes :
40- dec_access_key = self .get_attribute_value (
41- self . _clp_res_model , attr , "AWS Access Key ID" , self ._shell_helper , True )
42- dec_secret_key = self .get_attribute_value (
43- self . _clp_res_model , attr , "AWS Secret Access Key" , self ._shell_helper , True )
44- if self .get_attribute_value (self ._clp_res_model , attr , self . _shell_helper , "Region" ):
35+ if self .does_attribute_match ( self . _clp_res_model , attr , "AWS Access Key ID" ):
36+ dec_access_key = self ._shell_helper . api . DecryptPassword ( attr . Value ). Value
37+ if self .does_attribute_match ( self . _clp_res_model , attr , "AWS Secret Access Key" ):
38+ dec_secret_key = self ._shell_helper . api . DecryptPassword ( attr . Value ). Value
39+ if self .does_attribute_match (self ._clp_res_model , attr , "Region" ):
4540 os .environ ["AWS_DEFAULT_REGION" ] = attr .Value
4641 region_flag = True
4742 if not region_flag :
@@ -60,17 +55,17 @@ def __init__(self, clp_res_model, clp_resource_attributes, shell_helper):
6055 self ._clp_resource_attributes = clp_resource_attributes
6156 self ._shell_helper = shell_helper
6257
63- def _set_azure_env_vars_based_on_clp (self ):
58+ def set_env_vars_based_on_clp (self ):
6459 for attr in self ._clp_resource_attributes :
65- attr_val = self .get_attribute_value (self ._clp_res_model , attr , self ._shell_helper , "Azure Subscription ID" )
60+ attr_val = self .does_attribute_match (self ._clp_res_model , attr , self ._shell_helper , "Azure Subscription ID" )
6661 if attr_val :
6762 os .environ ["ARM_SUBSCRIPTION_ID" ] = attr_val
68- attr_val = self .get_attribute_value (self ._clp_res_model , attr , self ._shell_helper , "Azure Tenant ID" )
63+ attr_val = self .does_attribute_match (self ._clp_res_model , attr , self ._shell_helper , "Azure Tenant ID" )
6964 if attr_val :
7065 os .environ ["Azure Tenant ID" ] = attr_val
71- attr_val = self .get_attribute_value (self ._clp_res_model , attr , self ._shell_helper , "Azure Application ID" )
66+ attr_val = self .does_attribute_match (self ._clp_res_model , attr , self ._shell_helper , "Azure Application ID" )
7267 if attr_val :
7368 os .environ ["ARM_CLIENT_ID" ] = attr_val
74- attr_val = self .get_attribute_value (self ._clp_res_model , attr , self ._shell_helper , "Azure Application Key" , True )
69+ attr_val = self .does_attribute_match (self ._clp_res_model , attr , self ._shell_helper , "Azure Application Key" , True )
7570 if attr_val :
7671 os .environ ["ARM_CLIENT_SECRET" ] = attr_val
0 commit comments