This commit is contained in:
Nicolas Ontiveros 2024-07-22 17:04:00 -07:00
Родитель f00f0655dd
Коммит b364f27ae1
1 изменённых файлов: 55 добавлений и 1 удалений

Просмотреть файл

@ -39,7 +39,58 @@ ask_to_create_default_env_config() {
fi fi
} }
# We use a service principal and certificate as the mock MSI object
create_mock_msi() {
appName="mock-msi-$(openssl rand -base64 9 | tr -dc 'a-zA-Z0-9' | head -c 6)"
az ad sp create-for-rbac --name $appName --create-cert --output json
}
get_mock_msi_clientID() {
echo "$1" | jq -r .appId
}
get_mock_msi_tenantID() {
echo "$1" | jq -r .tenant
}
get_mock_msi_cert() {
certFilePath=$(echo "$1" | jq -r '.fileWithCertAndPrivateKey')
base64EncodedCert=$(base64 -w 0 $certFilePath)
rm $certFilePath
echo $base64EncodedCert
}
create_env_file() { create_env_file() {
local answer
read -p "Do you want to create an env file for Managed/Workload identity development? " answer
if [[ "$answer" == "y" || "$answer" == "Y" ]]; then
create_miwi_env_file
else
create_regular_env_file
fi
}
create_miwi_env_file() {
echo "INFO: Creating default env config file for managed/workload identity development..."
mockMSI=$(create_mock_msi)
mockClientID=$(get_mock_msi_clientID "$mockMSI")
mockTenantID=$(get_mock_msi_tenantID "$mockMSI")
mockCert=$(get_mock_msi_cert "$mockMSI")
cat >env <<EOF
export LOCATION=eastus
export ARO_IMAGE=arointsvc.azurecr.io/aro:latest
export RP_MODE=development # to use a development RP running at https://localhost:8443/
export MOCK_MSI_CLIENT_ID="$mockClientID"
export MOCK_MSI_TENANT_ID="$mockTenantID"
export MOCK_MSI_CERT="$mockCert"
source secrets/env
EOF
}
create_regular_env_file() {
echo "INFO: Creating default env config file..." echo "INFO: Creating default env config file..."
cat >env <<EOF cat >env <<EOF
@ -51,6 +102,7 @@ source secrets/env
EOF EOF
} }
ask_to_create_Azure_deployment() { ask_to_create_Azure_deployment() {
local answer local answer
read -p "Create Azure deployment in the current subscription ($AZURE_SUBSCRIPTION_ID)? (y / n / l (list existing deployments)) " answer read -p "Create Azure deployment in the current subscription ($AZURE_SUBSCRIPTION_ID)? (y / n / l (list existing deployments)) " answer
@ -107,4 +159,6 @@ main() {
run_the_RP run_the_RP
} }
main if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main
fi