Skip to content

Commit

Permalink
Merge pull request #8 from Azure-Samples/windows
Browse files Browse the repository at this point in the history
Add powershell scripts for Windows hooks
  • Loading branch information
pamelafox authored Mar 12, 2024
2 parents 069c29f + 8502ec2 commit f799342
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
10 changes: 10 additions & 0 deletions azure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,19 @@ hooks:
run: ./scripts/auth_init.sh
interactive: true
continueOnError: false
windows:
shell: pwsh
run: ./scripts/auth_init.ps1
interactive: true
continueOnError: false
postprovision:
posix:
shell: sh
run: ./scripts/auth_update.sh
interactive: true
continueOnError: false
windows:
shell: pwsh
run: ./scripts/auth_update.ps1
interactive: true
continueOnError: false
16 changes: 16 additions & 0 deletions scripts/auth_init.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Write-Host "Checking if authentication should be setup..."

. ./scripts/load_env.ps1

if (-not $env:AZURE_USE_AUTHENTICATION) {
Write-Host "AZURE_USE_AUTHENTICATION is not set, skipping authentication setup."
Exit 0
}

$pythonCmd = Get-Command python -ErrorAction SilentlyContinue
if (-not $pythonCmd) {
# fallback to python3 if python not found
$pythonCmd = Get-Command python3 -ErrorAction SilentlyContinue
}

Start-Process -FilePath ($pythonCmd).Source -ArgumentList "./scripts/auth_init.py" -Wait -NoNewWindow
16 changes: 16 additions & 0 deletions scripts/auth_update.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
. ./scripts/load_env.ps1

Write-Host "Container app deployed at: $env:SERVICE_APP_URI"

if (-not $env:AZURE_USE_AUTHENTICATION) {
Exit 0
}


$pythonCmd = Get-Command python -ErrorAction SilentlyContinue
if (-not $pythonCmd) {
# fallback to python3 if python not found
$pythonCmd = Get-Command python3 -ErrorAction SilentlyContinue
}

Start-Process -FilePath ($pythonCmd).Source -ArgumentList "./scripts/auth_update.py" -Wait -NoNewWindow
7 changes: 7 additions & 0 deletions scripts/load_env.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
foreach ($line in (& azd env get-values)) {
if ($line -match "([^=]+)=(.*)") {
$key = $matches[1]
$value = $matches[2] -replace '^"|"$'
[Environment]::SetEnvironmentVariable($key, $value)
}
}

0 comments on commit f799342

Please sign in to comment.