|
3 | 3 |
|
4 | 4 | from cloudshell.api.cloudshell_api import ResourceInfo |
5 | 5 |
|
6 | | -from cloudshell.iac.terraform.constants import AZURE2G_MODEL, ATTRIBUTE_NAMES, AWS2G_MODEL, CLP_PROVIDER_MODELS |
| 6 | +from cloudshell.iac.terraform.constants import AZURE2G_MODEL, ATTRIBUTE_NAMES, AWS2G_MODEL, CLP_PROVIDER_MODELS, \ |
| 7 | + AWS1G_MODEL, AZURE1G_MODEL |
7 | 8 | from cloudshell.iac.terraform.models.shell_helper import ShellHelperObject |
| 9 | +from cloudshell.iac.terraform.services.clp_envvar_handler import BaseCloudProviderEnvVarHandler, \ |
| 10 | + AWSCloudProviderEnvVarHandler, AzureCloudProviderEnvVarHandler |
8 | 11 |
|
9 | 12 |
|
10 | 13 | class ProviderHandler(object): |
@@ -48,49 +51,14 @@ def _set_cloud_env_vars( |
48 | 51 | shell_helper.sandbox_messages.write_message("initializing provider...") |
49 | 52 | shell_helper.logger.info("Initializing Environment variables with CloudProvider details") |
50 | 53 | clp_resource_attributes = clp_details.ResourceAttributes |
| 54 | + clp_handler = None |
51 | 55 |
|
52 | | - cloud_attr_name_prefix = "" |
53 | | - if clp_res_model in [AZURE2G_MODEL, AWS2G_MODEL]: |
54 | | - cloud_attr_name_prefix = clp_res_model + "." |
| 56 | + if clp_res_model in [AWS1G_MODEL, AWS2G_MODEL]: |
| 57 | + clp_handler = AWSCloudProviderEnvVarHandler(clp_res_model, clp_resource_attributes, shell_helper) |
55 | 58 |
|
56 | | - if clp_res_model in ['AWS EC2', AWS2G_MODEL]: |
57 | | - ProviderHandler._set_aws_env_vars_based_on_clp( |
58 | | - cloud_attr_name_prefix, clp_resource_attributes, shell_helper) |
59 | | - elif clp_res_model in ['Microsoft Azure', AZURE2G_MODEL]: |
60 | | - ProviderHandler._set_azure_env_vars_based_on_clp( |
61 | | - cloud_attr_name_prefix, clp_resource_attributes, shell_helper) |
| 59 | + elif clp_res_model in [AZURE1G_MODEL, AZURE2G_MODEL]: |
| 60 | + clp_handler = AzureCloudProviderEnvVarHandler(clp_res_model, clp_resource_attributes, shell_helper) |
62 | 61 |
|
63 | | - @staticmethod |
64 | | - def _set_azure_env_vars_based_on_clp(azure_attr_name_prefix, clp_resource_attributes, shell_helper): |
65 | | - for attr in clp_resource_attributes: |
66 | | - if attr.Name == azure_attr_name_prefix + "Azure Subscription ID": |
67 | | - os.environ["ARM_SUBSCRIPTION_ID"] = attr.Value |
68 | | - if attr.Name == azure_attr_name_prefix + "Azure Tenant ID": |
69 | | - os.environ["ARM_TENANT_ID"] = attr.Value |
70 | | - if attr.Name == azure_attr_name_prefix + "Azure Application ID": |
71 | | - os.environ["ARM_CLIENT_ID"] = attr.Value |
72 | | - if attr.Name == azure_attr_name_prefix + "Azure Application Key": |
73 | | - dec_client_secret = shell_helper.api.DecryptPassword(attr.Value).Value |
74 | | - os.environ["ARM_CLIENT_SECRET"] = dec_client_secret |
75 | | - |
76 | | - @staticmethod |
77 | | - def _set_aws_env_vars_based_on_clp(aws_attr_name_prefix, clp_resource_attributes, shell_helper): |
78 | | - dec_access_key = "" |
79 | | - dec_secret_key = "" |
80 | | - region_flag = False |
81 | | - |
82 | | - for attr in clp_resource_attributes: |
83 | | - if attr.Name == aws_attr_name_prefix + "AWS Access Key ID": |
84 | | - dec_access_key = shell_helper.api.DecryptPassword(attr.Value).Value |
85 | | - if attr.Name == aws_attr_name_prefix + "AWS Secret Access Key": |
86 | | - dec_secret_key = shell_helper.api.DecryptPassword(attr.Value).Value |
87 | | - if attr.Name == aws_attr_name_prefix + "Region": |
88 | | - os.environ["AWS_DEFAULT_REGION"] = attr.Value |
89 | | - region_flag = True |
90 | | - if not region_flag: |
91 | | - raise ValueError("Region was not found on AWS Cloud Provider") |
| 62 | + if clp_handler: |
| 63 | + clp_handler.set_env_vars_based_on_clp() |
92 | 64 |
|
93 | | - # We must check both keys exist...if not then the EC2 Execution Server profile would be used (Role) |
94 | | - if dec_access_key and dec_secret_key: |
95 | | - os.environ["AWS_ACCESS_KEY_ID"] = dec_access_key |
96 | | - os.environ["AWS_SECRET_ACCESS_KEY"] = dec_secret_key |
0 commit comments