Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complex Environmental Name Replacements #178

Merged
merged 8 commits into from
Apr 26, 2021
10 changes: 5 additions & 5 deletions src/core/globals.front.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/saca-hub/saca-hub.front.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
},
Expand Down
6 changes: 3 additions & 3 deletions src/core/tier-0/tier-0.front.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
},
Expand Down Expand Up @@ -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": []
},
Expand Down Expand Up @@ -131,4 +131,4 @@
}
]
}
}
}
6 changes: 3 additions & 3 deletions src/core/tier-1/tier-1.front.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
},
Expand Down Expand Up @@ -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": []
},
Expand Down Expand Up @@ -131,4 +131,4 @@
}
]
}
}
}
6 changes: 3 additions & 3 deletions src/core/tier-2/tier-2.front.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
},
Expand Down Expand Up @@ -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": []
},
Expand Down Expand Up @@ -131,4 +131,4 @@
}
]
}
}
}
19 changes: 17 additions & 2 deletions src/front/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"])
Expand All @@ -105,4 +109,15 @@ def build_form(form_doc: dict):
with doc_form:
input_(value="Execute Terraform", type="submit")

return doc_form
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)
1 change: 1 addition & 0 deletions src/front/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ async def home(request: Request):
url: "/poll",
success: function(msg){
$("#terminal").text(msg);
$("#terminal").scrollTop($("#terminal")[0].scrollHeight);
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/setup_ezdeploy_local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
Expand Down