From 6b0d33186a6fa6c969cd79c791397a849907cf74 Mon Sep 17 00:00:00 2001 From: Bree Stryker Date: Mon, 26 Apr 2021 11:32:13 -0400 Subject: [PATCH 1/6] Auto Scroll Text, Fix Variable Mismatches in local output. --- src/front/main.py | 1 + src/scripts/setup_ezdeploy_local.sh | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/front/main.py b/src/front/main.py index f7b6d9f16..cea99d142 100644 --- a/src/front/main.py +++ b/src/front/main.py @@ -160,6 +160,7 @@ async def home(request: Request): url: "/poll", success: function(msg){ $("#terminal").text(msg); + $("#terminal").scrollTop($("#terminal")[0].scrollHeight); } }); } diff --git a/src/scripts/setup_ezdeploy_local.sh b/src/scripts/setup_ezdeploy_local.sh index 3af3daa52..7bbfa0158 100755 --- a/src/scripts/setup_ezdeploy_local.sh +++ b/src/scripts/setup_ezdeploy_local.sh @@ -87,8 +87,8 @@ echo "export MLZCLIENTID=$mlz_client_id" echo "export MLZCLIENTSECRET=$mlz_client_secret" echo "for PowerShell:" -echo "\$env:CLIENT_ID='$client_id'" -echo "\$env:CLIENT_SECRET='$client_password'" +echo "\$env:CLIENT_ID='$auth_client_id'" +echo "\$env:CLIENT_SECRET='$auth_client_secret'" echo "\$env:TENANT_ID='$mlz_tenantid'" echo "\$env:MLZ_CLOUDNAME='$mlz_cloudname'" echo "\$env:MLZ_METADATAHOST='$mlz_metadatahost'" From d6b619f9074e11dd4bfe249ba71540207be9efbd Mon Sep 17 00:00:00 2001 From: Bree Stryker Date: Mon, 26 Apr 2021 12:20:59 -0400 Subject: [PATCH 2/6] Add code for more complex environmental substitutes, update templates. --- src/core/globals.front.json | 10 +++++----- src/core/saca-hub/saca-hub.front.json | 2 +- src/core/tier-0/tier-0.front.json | 2 +- src/core/tier-1/tier-1.front.json | 2 +- src/core/tier-2/tier-2.front.json | 2 +- src/front/lib/utils.py | 19 +++++++++++++++++-- 6 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/core/globals.front.json b/src/core/globals.front.json index fdcb56f3d..00e7ff79f 100644 --- a/src/core/globals.front.json +++ b/src/core/globals.front.json @@ -4,35 +4,35 @@ { "varname": "tf_environment", "type": "text", - "default_val": "env:TF_ENV", + "default_val": "${env:TF_ENV}", "description": "Terraform azurerm environment (e.g. 'public') see: https://www.terraform.io/docs/language/settings/backends/azurerm.html#environment", "options": [] }, { "varname": "mlz_cloud", "type": "text", - "default_val": "env:MLZ_CLOUDNAME", + "default_val": "${env:MLZ_CLOUDNAME}", "description": "Azure cloud being deployed to, # e.g. 'AzureCloud' or 'AzureUSGovernment', etc", "options": [] }, { "varname": "mlz_tenantid", "type": "text", - "default_val": "env:TENANT_ID", + "default_val": "${env:TENANT_ID}", "description": "Tenant ID where your subscriptions live", "options": [] }, { "varname": "mlz_metadatahost", "type": "text", - "default_val": "env:MLZ_METADATAHOST", + "default_val": "${env:MLZ_METADATAHOST}", "description": "Azure Metadata Service endpoint. (e.g 'management.azure.com' or 'management.usgovcloudapi.net')", "options": [] }, { "varname": "mlz_location", "type": "text", - "default_val": "env:MLZ_LOCATION", + "default_val": "${env:MLZ_LOCATION}", "description": "The location that you're deploying to (e.g. 'eastus')", "options": [] } diff --git a/src/core/saca-hub/saca-hub.front.json b/src/core/saca-hub/saca-hub.front.json index a7f1e4534..3a1463bfa 100644 --- a/src/core/saca-hub/saca-hub.front.json +++ b/src/core/saca-hub/saca-hub.front.json @@ -11,7 +11,7 @@ { "varname": "saca_subid", "type": "text", - "default_val": "env:HUB_SUBSCRIPTION_ID", + "default_val": "${env:HUB_SUBSCRIPTION_ID}", "description": "The subscription id where the SACA hub lives", "options": [] }, diff --git a/src/core/tier-0/tier-0.front.json b/src/core/tier-0/tier-0.front.json index 24ed0b7af..2d6713e5d 100644 --- a/src/core/tier-0/tier-0.front.json +++ b/src/core/tier-0/tier-0.front.json @@ -7,7 +7,7 @@ { "varname": "saca_subid", "type": "text", - "default_val": "env:HUB_SUBSCRIPTION_ID", + "default_val": "${env:HUB_SUBSCRIPTION_ID}", "description": "Saca Hub Subscription ID", "options": [] }, diff --git a/src/core/tier-1/tier-1.front.json b/src/core/tier-1/tier-1.front.json index 61ef150db..fb48423ce 100644 --- a/src/core/tier-1/tier-1.front.json +++ b/src/core/tier-1/tier-1.front.json @@ -7,7 +7,7 @@ { "varname": "saca_subid", "type": "text", - "default_val": "env:HUB_SUBSCRIPTION_ID", + "default_val": "${env:HUB_SUBSCRIPTION_ID}", "description": "Saca Hub Subscription ID", "options": [] }, diff --git a/src/core/tier-2/tier-2.front.json b/src/core/tier-2/tier-2.front.json index be8fd4ed1..3e75a9ed7 100644 --- a/src/core/tier-2/tier-2.front.json +++ b/src/core/tier-2/tier-2.front.json @@ -7,7 +7,7 @@ { "varname": "saca_subid", "type": "text", - "default_val": "env:HUB_SUBSCRIPTION_ID", + "default_val": "${env:HUB_SUBSCRIPTION_ID}", "description": "Saca Hub Subscription ID", "options": [] }, diff --git a/src/front/lib/utils.py b/src/front/lib/utils.py index e6e8fb3c3..6d4da12f5 100644 --- a/src/front/lib/utils.py +++ b/src/front/lib/utils.py @@ -3,9 +3,13 @@ # Provides a set of utility functions to be called from the primary API import os import json +import re from dominate.tags import * from typing import Union +# Re-usable variable sets +env_match = re.compile("\${env:([0-9a-zA-Z_]+)}") + def dotted_write(prop_name: str, val: Union[int, str], target_dict: dict): """ Purpose: Function takes in a property value to be mapped that contains .'s in a string. @@ -84,7 +88,7 @@ def build_form(form_doc: dict): # Process environment options if type(el_item["default_val"]) != bool: if "env:" in el_item["default_val"]: - el_item["default_val"] = os.getenv(el_item["default_val"].replace("env:", ""), "") + el_item["default_val"] = env_match.sub(environ_replace, el_item["default_val"]) span(el_item["varname"], cls="input-group-text") if el_item["type"] == "text": input_(id=el_item["varname"], cls="form-control", value=el_item["default_val"], name=el_item["varname"]) @@ -105,4 +109,15 @@ def build_form(form_doc: dict): with doc_form: input_(value="Execute Terraform", type="submit") - return doc_form \ No newline at end of file + return doc_form + + +def environ_replace(match_obj): + """ + Purpose: Iterate over the resulting match groups from a regex and return the matching environment variable + form to be appended to the front end UI + + :form_doc: a dictionary derived from a loaded json + """ + for x in match_obj.groups(): + return os.getenv(x) From e600a72d1c88af7908fb3cfc267d37c4de3145fd Mon Sep 17 00:00:00 2001 From: Breanna-Stryker <74314422+Breanna-Stryker@users.noreply.github.com> Date: Mon, 26 Apr 2021 12:46:09 -0400 Subject: [PATCH 3/6] Update tier-0.front.json --- src/core/tier-0/tier-0.front.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/tier-0/tier-0.front.json b/src/core/tier-0/tier-0.front.json index 2d6713e5d..960bab829 100644 --- a/src/core/tier-0/tier-0.front.json +++ b/src/core/tier-0/tier-0.front.json @@ -42,7 +42,7 @@ { "varname": "tier0_subid", "type": "text", - "default_val": "env:TIER0_SUBSCRIPTION_ID", + "default_val": "${env:TIER0_SUBSCRIPTION_ID}", "description": "Tier0 Subscription Id", "options": [] }, @@ -131,4 +131,4 @@ } ] } -} \ No newline at end of file +} From 485081ca44e318db7c5cbb39374e293db71b3372 Mon Sep 17 00:00:00 2001 From: Breanna-Stryker <74314422+Breanna-Stryker@users.noreply.github.com> Date: Mon, 26 Apr 2021 12:46:31 -0400 Subject: [PATCH 4/6] Update tier-1.front.json --- src/core/tier-1/tier-1.front.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/tier-1/tier-1.front.json b/src/core/tier-1/tier-1.front.json index fb48423ce..754fac85b 100644 --- a/src/core/tier-1/tier-1.front.json +++ b/src/core/tier-1/tier-1.front.json @@ -42,7 +42,7 @@ { "varname": "tier1_subid", "type": "text", - "default_val": "env:TIER1_SUBSCRIPTION_ID", + "default_val": "${env:TIER1_SUBSCRIPTION_ID}", "description": "Tier0 Subscription Id", "options": [] }, @@ -131,4 +131,4 @@ } ] } -} \ No newline at end of file +} From 4f0c28d4c1e9299e6e31142374ea151ddd7f0a72 Mon Sep 17 00:00:00 2001 From: Breanna-Stryker <74314422+Breanna-Stryker@users.noreply.github.com> Date: Mon, 26 Apr 2021 12:46:56 -0400 Subject: [PATCH 5/6] Update tier-2.front.json --- src/core/tier-2/tier-2.front.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/tier-2/tier-2.front.json b/src/core/tier-2/tier-2.front.json index 3e75a9ed7..006e49916 100644 --- a/src/core/tier-2/tier-2.front.json +++ b/src/core/tier-2/tier-2.front.json @@ -42,7 +42,7 @@ { "varname": "tier2_subid", "type": "text", - "default_val": "env:TIER2_SUBSCRIPTION_ID", + "default_val": "${env:TIER2_SUBSCRIPTION_ID}", "description": "Tier0 Subscription Id", "options": [] }, @@ -131,4 +131,4 @@ } ] } -} \ No newline at end of file +} From baf99a176fe614b14f03ebae2c9921fbcb7bb2e5 Mon Sep 17 00:00:00 2001 From: Bree Stryker Date: Mon, 26 Apr 2021 14:23:53 -0400 Subject: [PATCH 6/6] Replace the Location with the appropriate env variable --- src/core/saca-hub/saca-hub.front.json | 18 +++++++++--------- src/core/tier-0/tier-0.front.json | 10 +++++----- src/core/tier-1/tier-1.front.json | 10 +++++----- src/core/tier-2/tier-2.front.json | 10 +++++----- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/core/saca-hub/saca-hub.front.json b/src/core/saca-hub/saca-hub.front.json index 3a1463bfa..d9eb8a33b 100644 --- a/src/core/saca-hub/saca-hub.front.json +++ b/src/core/saca-hub/saca-hub.front.json @@ -18,21 +18,21 @@ { "varname": "saca_rgname", "type": "text", - "default_val": "rg-eastus-mlz-saca", + "default_val": "rg-${env:MLZ_LOCATION}-mlz-saca", "description": "Resource group name", "options": [] }, { "varname": "saca_vnetname", "type": "text", - "default_val": "vn-eastus-mlz-saca", + "default_val": "vn-${env:MLZ_LOCATION}-mlz-saca", "description": "Virtual Network Name", "options": [] }, { "varname": "saca_lawsname", "type": "text", - "default_val": "laws-eastus-mlz-saca", + "default_val": "laws-${env:MLZ_LOCATION}-mlz-saca", "description": "Name for log analytic workspace", "options": [] }, @@ -48,42 +48,42 @@ { "varname": "tier0_rgname", "type": "text", - "default_val": "rg-eastus-mlz-t0", + "default_val": "rg-${env:MLZ_LOCATION}-mlz-t0", "description": "Tier 0 resource group name", "options": [] }, { "varname": "tier0_vnetname", "type": "text", - "default_val": "vn-eastus-mlz-t0", + "default_val": "vn-${env:MLZ_LOCATION}-mlz-t0", "description": "Tier 0 virtual network name", "options": [] }, { "varname": "tier1_rgname", "type": "text", - "default_val": "rg-eastus-mlz-t1", + "default_val": "rg-${env:MLZ_LOCATION}-mlz-t1", "description": "Tier 1 resource group name", "options": [] }, { "varname": "tier1_vnetname", "type": "text", - "default_val": "vn-eastus-mlz-t1", + "default_val": "vn-${env:MLZ_LOCATION}-mlz-t1", "description": "Tier one virtual network name", "options": [] }, { "varname": "tier2_rgname", "type": "text", - "default_val": "rg-eastus-mlz-t2", + "default_val": "rg-${env:MLZ_LOCATION}-mlz-t2", "description": "Tier 2 resource group name", "options": [] }, { "varname": "tier2_vnetname", "type": "text", - "default_val": "vn-eastus-mlz-t2", + "default_val": "vn-${env:MLZ_LOCATION}-mlz-t2", "description": "Tier 2 virtual network name", "options": [] }, diff --git a/src/core/tier-0/tier-0.front.json b/src/core/tier-0/tier-0.front.json index 2d6713e5d..1f37ac741 100644 --- a/src/core/tier-0/tier-0.front.json +++ b/src/core/tier-0/tier-0.front.json @@ -14,14 +14,14 @@ { "varname": "saca_rgname", "type": "text", - "default_val": "rg-eastus-mlz-saca", + "default_val": "rg-${env:MLZ_LOCATION}-mlz-saca", "description": "Saca Hub Resource Group Name", "options": [] }, { "varname": "saca_vnetname", "type": "text", - "default_val": "vn-eastus-mlz-saca", + "default_val": "vn-${env:MLZ_LOCATION}-mlz-saca", "description": "Saca Virtual Network Name", "options": [] }, @@ -35,7 +35,7 @@ { "varname": "saca_lawsname", "type": "text", - "default_val": "laws-eastus-mlz-saca", + "default_val": "laws-${env:MLZ_LOCATION}-mlz-saca", "description": "Saca Log Analytic Workspace Name", "options": [] }, @@ -49,14 +49,14 @@ { "varname": "tier0_rgname", "type": "text", - "default_val": "rg-eastus-mlz-t0", + "default_val": "rg-${env:MLZ_LOCATION}-mlz-t0", "description": "Tier0 Resource Group Name", "options": [] }, { "varname": "tier0_vnetname", "type": "text", - "default_val": "vn-eastus-mlz-t0", + "default_val": "vn-${env:MLZ_LOCATION}-mlz-t0", "description": "Tier0 Virtual Network Name", "options": [] }, diff --git a/src/core/tier-1/tier-1.front.json b/src/core/tier-1/tier-1.front.json index fb48423ce..0b9ceb4ff 100644 --- a/src/core/tier-1/tier-1.front.json +++ b/src/core/tier-1/tier-1.front.json @@ -14,14 +14,14 @@ { "varname": "saca_rgname", "type": "text", - "default_val": "rg-eastus-mlz-saca", + "default_val": "rg-${env:MLZ_LOCATION}-mlz-saca", "description": "Saca Hub Resource Group Name", "options": [] }, { "varname": "saca_vnetname", "type": "text", - "default_val": "vn-eastus-mlz-saca", + "default_val": "vn-${env:MLZ_LOCATION}-mlz-saca", "description": "Saca Virtual Network Name", "options": [] }, @@ -35,7 +35,7 @@ { "varname": "saca_lawsname", "type": "text", - "default_val": "laws-eastus-mlz-saca", + "default_val": "laws-${env:MLZ_LOCATION}-mlz-saca", "description": "Saca Log Analytic Workspace Name", "options": [] }, @@ -49,14 +49,14 @@ { "varname": "tier1_rgname", "type": "text", - "default_val": "rg-eastus-mlz-t1", + "default_val": "rg-${env:MLZ_LOCATION}-mlz-t1", "description": "Tier0 Resource Group Name", "options": [] }, { "varname": "tier1_vnetname", "type": "text", - "default_val": "vn-eastus-mlz-t1", + "default_val": "vn-${env:MLZ_LOCATION}-mlz-t1", "description": "Tier0 Virtual Network Name", "options": [] }, diff --git a/src/core/tier-2/tier-2.front.json b/src/core/tier-2/tier-2.front.json index 3e75a9ed7..8b2a72a1f 100644 --- a/src/core/tier-2/tier-2.front.json +++ b/src/core/tier-2/tier-2.front.json @@ -14,14 +14,14 @@ { "varname": "saca_rgname", "type": "text", - "default_val": "rg-eastus-mlz-saca", + "default_val": "rg-${env:MLZ_LOCATION}-mlz-saca", "description": "Saca Hub Resource Group Name", "options": [] }, { "varname": "saca_vnetname", "type": "text", - "default_val": "vn-eastus-mlz-saca", + "default_val": "vn-${env:MLZ_LOCATION}-mlz-saca", "description": "Saca Virtual Network Name", "options": [] }, @@ -35,7 +35,7 @@ { "varname": "saca_lawsname", "type": "text", - "default_val": "laws-eastus-mlz-saca", + "default_val": "laws-${env:MLZ_LOCATION}-mlz-saca", "description": "Saca Log Analytic Workspace Name", "options": [] }, @@ -49,14 +49,14 @@ { "varname": "tier2_rgname", "type": "text", - "default_val": "rg-eastus-mlz-t2", + "default_val": "rg-${env:MLZ_LOCATION}-mlz-t2", "description": "Tier2 Resource Group Name", "options": [] }, { "varname": "tier2_vnetname", "type": "text", - "default_val": "vn-eastus-mlz-t2", + "default_val": "vn-${env:MLZ_LOCATION}-mlz-t2", "description": "Tier2 Virtual Network Name", "options": [] },