Skip to content

Commit

Permalink
remove URI components from metadata host service endpoint when genera…
Browse files Browse the repository at this point in the history
…ting .mlzconfig (#243)
  • Loading branch information
glennmusa authored Jun 4, 2021
1 parent 54f2f7b commit e74b5ac
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions src/scripts/config/append_prereq_endpoints.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,38 @@ 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 character / as a field separator"
#
# '{print $3}' is "print me the third field"
#
# 2) for example on 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 "$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
Expand All @@ -42,7 +72,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
}

Expand Down

0 comments on commit e74b5ac

Please sign in to comment.