Skip to content

Commit 6ed2592

Browse files
fix: Refactor app sample enabling logic in auth_init scripts (#103)
* fix: Refactor app sample enabling logic in auth_init scripts * fix: Remove redundant check for false value in auth_init script
1 parent 5009774 commit 6ed2592

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

scripts/auth_init.ps1

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
. ./scripts/loadenv.ps1
22

3-
if (-not $env:AZURE_APP_SAMPLE_ENABLED -or $env:AZURE_APP_SAMPLE_ENABLED -eq "false") {
4-
Write-Host "AZURE_APP_SAMPLE_ENABLED is false. Exiting auth_init script."
3+
$appSampleEnabled = (Get-Content .\.azure\$env:AZURE_ENV_NAME\config.json | ConvertFrom-Json).infra.parameters.appSampleEnabled
4+
5+
# Give preference to AZURE_APP_SAMPLE_ENABLED environment variable
6+
if ($env:AZURE_APP_SAMPLE_ENABLED) {
7+
$effectiveValue = $env:AZURE_APP_SAMPLE_ENABLED
8+
} else {
9+
$effectiveValue = $appSampleEnabled
10+
}
11+
12+
$effectiveValue = $effectiveValue.ToString().ToLower()
13+
14+
if (-not $effectiveValue -or $effectiveValue -eq "false") {
15+
Write-Host "App sample is disabled. Exiting auth_init script."
516
exit
617
}
718

scripts/auth_init.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,19 @@
33
# Load environment variables from a shell script
44
. ./scripts/loadenv.sh
55

6-
# Check if AZURE_APP_SAMPLE_ENABLED is not set or is "false"
7-
if [[ -z "$AZURE_APP_SAMPLE_ENABLED" || "$AZURE_APP_SAMPLE_ENABLED" == "false" ]]; then
8-
echo "AZURE_APP_SAMPLE_ENABLED is false. Exiting auth_init script."
6+
appSampleEnabled=$(./.venv/bin/python -c "import json; print(str(json.load(open('.azure/$AZURE_ENV_NAME/config.json'))['infra']['parameters']['appSampleEnabled']).lower())" 2>/dev/null || echo "false")
7+
8+
# Give preference to AZURE_APP_SAMPLE_ENABLED environment variable
9+
if [[ -n "$AZURE_APP_SAMPLE_ENABLED" ]]; then
10+
effectiveValue="${AZURE_APP_SAMPLE_ENABLED}"
11+
else
12+
effectiveValue="$appSampleEnabled"
13+
fi
14+
15+
effectiveValue=$(echo "$effectiveValue" | tr '[:upper:]' '[:lower:]')
16+
17+
if [[ -z "$effectiveValue" || "$effectiveValue" == "false" ]]; then
18+
echo "App sample is disabled. Exiting auth_init script."
919
exit 0
1020
fi
1121

0 commit comments

Comments
 (0)