From 846e54306909bae145c8f918caa87bf7481c588e Mon Sep 17 00:00:00 2001 From: Glenn Musa <4622125+glennmusa@users.noreply.github.com> Date: Thu, 3 Jun 2021 12:56:28 -0400 Subject: [PATCH 1/3] remove URI components from metadatahost --- src/scripts/config/append_prereq_endpoints.sh | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/scripts/config/append_prereq_endpoints.sh b/src/scripts/config/append_prereq_endpoints.sh index b89d946b3..4b15883ba 100755 --- a/src/scripts/config/append_prereq_endpoints.sh +++ b/src/scripts/config/append_prereq_endpoints.sh @@ -31,8 +31,40 @@ mlz_az_cloud_keys['mlz_keyvaultDns']='suffixes.keyvaultDns' mlz_az_cloud_keys['mlz_cloudname']='name' mlz_az_cloud_keys['mlz_activeDirectory']='endpoints.activeDirectory' -# since we cannot guarantee the results of `az cloud show` for each value we want, -# we query for them individually when printing to the file to accommodate for empty results +# if it's the metadatahost, strip it of URI components +# in some clouds, Terraform allows only the domain name +format_if_metadatahost() { + local mlz_key_name=$1 + local cloud_key_value=$2 + + if [[ $mlz_key_name != "mlz_metadatahost" ]]; then + echo $cloud_key_value + else + + # 1) awk -F/ '{print $3}' + # + # -F/ is "using the charactrer / as a field separator" + # + # '{print $3}' is "print me the third field" + # + # 2) for example + # + # https://management.azure.com/ + # + # $1 $2 $3 $4 + # https: / / management.azure.com / + # + # $1 is https: + # $2 is + # $3 is management.azure.com + # $4 is + + echo $(echo "$cloud_key_value" | awk -F/ '{print $3}') + fi +} + +# since we cannot guarantee the results of `az cloud show` for each value we require, +# query for values individually and skip printing any empty results append_cloud_value() { local mlz_key_name=$1 local cloud_key_name=$2 @@ -42,7 +74,11 @@ append_cloud_value() { cloud_key_value=$(az cloud show --query "${cloud_key_name}" --output tsv) if [[ $cloud_key_value ]]; then + cloud_key_value=$(format_if_metadatahost "$mlz_key_name" "$cloud_key_value") printf "%s=%s\n" "${mlz_key_name}" "${cloud_key_value}" >> "${file}" + else + echo "INFO: Oops! Did not find a value for 'az cloud show --query ${cloud_key_name}'..." + echo "INFO: There will not be a value for ${mlz_key_name} on the MLZ config file at ${file}..." fi } From 8fb36b14ecc26836c11b49ba72182bfa69b87bee Mon Sep 17 00:00:00 2001 From: Glenn Musa <4622125+glennmusa@users.noreply.github.com> Date: Thu, 3 Jun 2021 13:02:37 -0400 Subject: [PATCH 2/3] better comments --- src/scripts/config/append_prereq_endpoints.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripts/config/append_prereq_endpoints.sh b/src/scripts/config/append_prereq_endpoints.sh index 4b15883ba..323ca1a2a 100755 --- a/src/scripts/config/append_prereq_endpoints.sh +++ b/src/scripts/config/append_prereq_endpoints.sh @@ -43,7 +43,7 @@ format_if_metadatahost() { # 1) awk -F/ '{print $3}' # - # -F/ is "using the charactrer / as a field separator" + # -F/ is "using the character / as a field separator" # # '{print $3}' is "print me the third field" # From a7bd57fef391fb31bc2ea07489c036649a6315c7 Mon Sep 17 00:00:00 2001 From: Glenn Musa <4622125+glennmusa@users.noreply.github.com> Date: Thu, 3 Jun 2021 19:07:26 +0000 Subject: [PATCH 3/3] fix shellcheck warnings --- src/scripts/config/append_prereq_endpoints.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/scripts/config/append_prereq_endpoints.sh b/src/scripts/config/append_prereq_endpoints.sh index 323ca1a2a..7a5dd062a 100755 --- a/src/scripts/config/append_prereq_endpoints.sh +++ b/src/scripts/config/append_prereq_endpoints.sh @@ -38,7 +38,7 @@ format_if_metadatahost() { local cloud_key_value=$2 if [[ $mlz_key_name != "mlz_metadatahost" ]]; then - echo $cloud_key_value + echo "$cloud_key_value" else # 1) awk -F/ '{print $3}' @@ -47,9 +47,7 @@ format_if_metadatahost() { # # '{print $3}' is "print me the third field" # - # 2) for example - # - # https://management.azure.com/ + # 2) for example on https://management.azure.com/ # # $1 $2 $3 $4 # https: / / management.azure.com / @@ -59,7 +57,7 @@ format_if_metadatahost() { # $3 is management.azure.com # $4 is - echo $(echo "$cloud_key_value" | awk -F/ '{print $3}') + echo "$cloud_key_value" | awk -F/ '{print $3}' fi }