Skip to content

Commit 5519fe2

Browse files
commit
1 parent a528887 commit 5519fe2

7 files changed

Lines changed: 95 additions & 23 deletions

File tree

docs/CustomizeSchemaData.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ A new JSON Schema document needs to be created that defines the schema as a decl
7777
7878
**Sample Schemas:** The accelerator ships with 4 sample schemas — use any as a starting template:
7979

80-
| Schema | File | Class Name | Auto-registered |
80+
| Schema | File | Class Name | Included sample |
8181
| ------------------------- | --------------------------------------------------------------------------------- | ------------------------------- | --------------- |
8282
| Auto Insurance Claim Form | [autoclaim.json](../src/ContentProcessorAPI/samples/schemas/autoclaim.json) | `AutoInsuranceClaimForm` ||
8383
| Police Report | [policereport.json](../src/ContentProcessorAPI/samples/schemas/policereport.json) | `PoliceReportDocument` ||
8484
| Repair Estimate | [repairestimate.json](../src/ContentProcessorAPI/samples/schemas/repairestimate.json) | `RepairEstimateDocument` ||
8585
| Damaged Vehicle Image | [damagedcarimage.json](../src/ContentProcessorAPI/samples/schemas/damagedcarimage.json) | `DamagedVehicleImageAssessment` ||
8686

87-
> **Note:** All 4 schemas are automatically registered during deployment (via `azd up` or the `register_schema.py` script) and grouped into the **"Auto Claim"** schema set.
87+
> **Note:** These 4 schemas are included in the repository and are registered when you run the manual post-deployment schema registration step (for example, `register_schemas.ps1` / `register_schemas.sh`, or `run_post_deployment.ps1` / `run_post_deployment.sh`). They are then grouped into the **"Auto Claim"** schema set.
8888
8989
Duplicate one of these files and update with fields that represent your document type.
9090

docs/DeploymentGuide.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,11 @@ Run schema registration first to:
323323
**macOS/Linux:**
324324

325325
```bash
326-
sed -i 's/\r$//' ./infra/scripts/register_schemas.sh
326+
if [ "$(uname)" = "Darwin" ]; then
327+
sed -i '' 's/\r$//' ./infra/scripts/register_schemas.sh
328+
else
329+
sed -i 's/\r$//' ./infra/scripts/register_schemas.sh
330+
fi
327331
bash ./infra/scripts/register_schemas.sh
328332
```
329333

@@ -347,7 +351,11 @@ After schema registration completes, upload the sample bundles as a separate exp
347351
**macOS/Linux:**
348352

349353
```bash
350-
sed -i 's/\r$//' ./infra/scripts/upload_sample_data.sh
354+
if [ "$(uname)" = "Darwin" ]; then
355+
sed -i '' 's/\r$//' ./infra/scripts/upload_sample_data.sh
356+
else
357+
sed -i 's/\r$//' ./infra/scripts/upload_sample_data.sh
358+
fi
351359
bash ./infra/scripts/upload_sample_data.sh
352360
```
353361

@@ -364,7 +372,11 @@ Run authentication setup as an explicit step after post-deployment data setup:
364372
**macOS/Linux:**
365373

366374
```bash
367-
sed -i 's/\r$//' ./infra/scripts/setup_auth.sh
375+
if [ "$(uname)" = "Darwin" ]; then
376+
sed -i '' 's/\r$//' ./infra/scripts/setup_auth.sh
377+
else
378+
sed -i 's/\r$//' ./infra/scripts/setup_auth.sh
379+
fi
368380
bash ./infra/scripts/setup_auth.sh
369381
```
370382

infra/scripts/configure_auth.ps1

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ if ($env:AZURE_SKIP_AUTH_SETUP -eq "true") {
1313
return
1414
}
1515

16-
$PrefightOnly = $args -contains "--preflight-only"
17-
if ($PrefightOnly) {
16+
$PreflightOnly = $args -contains "--preflight-only"
17+
if ($PreflightOnly) {
1818
Write-Host ""
1919
Write-Host "============================================================"
2020
Write-Host "🔍 Preflight permission check (read-only — no changes made)"
@@ -26,6 +26,24 @@ if ($PrefightOnly) {
2626
Write-Host "============================================================"
2727
}
2828

29+
if (-not (Get-Command az -ErrorAction SilentlyContinue)) {
30+
Write-Error "Azure CLI (az) is not installed or not on PATH. Install from https://aka.ms/installazurecli and re-run."
31+
exit 1
32+
}
33+
34+
if (-not (Get-Command azd -ErrorAction SilentlyContinue)) {
35+
Write-Error "Azure Developer CLI (azd) is not installed or not on PATH. Install from https://aka.ms/install-azd and re-run."
36+
exit 1
37+
}
38+
39+
try {
40+
azd env get-values *> $null
41+
if ($LASTEXITCODE -ne 0) { throw }
42+
} catch {
43+
Write-Error "No active azd environment found. Run 'azd env list' and 'azd env select <name>', then re-run."
44+
exit 1
45+
}
46+
2947
function Azd-Get($key, $default = "") {
3048
try { return (azd env get-value $key 2>$null) } catch { return $default }
3149
}
@@ -240,7 +258,7 @@ function Validate-PrerequisitesAndPermissions {
240258

241259
Validate-PrerequisitesAndPermissions
242260

243-
if ($PrefightOnly) {
261+
if ($PreflightOnly) {
244262
Write-Host ""
245263
Write-Host "✅ Preflight-only mode: all permission checks passed. No changes were made."
246264
exit 0
@@ -420,7 +438,6 @@ Ensure-CaSecret $WebClientId $WebName
420438
# --- Step 5: Enable EasyAuth ------------------------------------------------
421439
Write-Host ""
422440
Write-Host "➡️ Step 5/6: Enabling EasyAuth on Web + API container apps"
423-
$Issuer = "https://login.microsoftonline.com/$TenantId/v2.0"
424441

425442
function Configure-EasyAuth($CaName, $ClientId) {
426443
# Note: --tenant-id and --issuer are mutually exclusive. Do not override

infra/scripts/configure_auth.sh

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,24 @@ else
2929
echo "============================================================"
3030
fi
3131

32+
if ! command -v az >/dev/null 2>&1; then
33+
echo "❌ Azure CLI (az) is not installed or not on PATH." >&2
34+
echo " Install it from https://aka.ms/installazurecli, then re-run." >&2
35+
exit 1
36+
fi
37+
38+
if ! command -v azd >/dev/null 2>&1; then
39+
echo "❌ Azure Developer CLI (azd) is not installed or not on PATH." >&2
40+
echo " Install it from https://aka.ms/install-azd, then re-run." >&2
41+
exit 1
42+
fi
43+
44+
if ! azd env get-values >/dev/null 2>&1; then
45+
echo "❌ No active azd environment found." >&2
46+
echo " Run 'azd env list' and 'azd env select <name>', then re-run." >&2
47+
exit 1
48+
fi
49+
3250
# --- Load values from azd env -------------------------------------------------
3351
ENV_NAME="$(azd env get-value AZURE_ENV_NAME 2>/dev/null || echo "")"
3452
RESOURCE_GROUP="$(azd env get-value AZURE_RESOURCE_GROUP 2>/dev/null || true)"
@@ -97,6 +115,20 @@ retry() {
97115
done
98116
}
99117

118+
# Generate a UUID in a macOS/Linux portable way.
119+
generate_uuid() {
120+
if command -v uuidgen >/dev/null 2>&1; then
121+
uuidgen
122+
elif command -v python3 >/dev/null 2>&1; then
123+
python3 -c 'import uuid; print(uuid.uuid4())'
124+
elif [[ -r /proc/sys/kernel/random/uuid ]]; then
125+
cat /proc/sys/kernel/random/uuid
126+
else
127+
echo "❌ Unable to generate UUID. Install uuidgen or python3." >&2
128+
exit 1
129+
fi
130+
}
131+
100132
# Print a preflight check result line
101133
_check() {
102134
local status="$1" # PASS | WARN | FAIL
@@ -164,6 +196,15 @@ validate_prerequisites_and_permissions() {
164196
fatal=true
165197
fi
166198

199+
# ── 3b. Python 3 available (used for authConfig JSON patching) ───
200+
if command -v python3 >/dev/null 2>&1; then
201+
_check PASS "python3 available (required for authConfig patching)"
202+
else
203+
_check FAIL "python3 available (required for authConfig patching)" \
204+
"Install Python 3 and ensure 'python3' is on PATH, then re-run."
205+
fatal=true
206+
fi
207+
167208
# ── 4. Contributor (or Owner) on the resource group ──────────────
168209
local current_principal
169210
current_principal="$(az ad signed-in-user show --query id -o tsv 2>/dev/null || true)"
@@ -301,7 +342,7 @@ API_IDENTIFIER_URI="api://${API_CLIENT_ID}"
301342
API_SCOPE_ID="$(az ad app show --id "$API_CLIENT_ID" \
302343
--query "api.oauth2PermissionScopes[?value=='user_impersonation'].id | [0]" -o tsv)"
303344
if [[ -z "$API_SCOPE_ID" || "$API_SCOPE_ID" == "null" ]]; then
304-
API_SCOPE_ID="$(cat /proc/sys/kernel/random/uuid)"
345+
API_SCOPE_ID="$(generate_uuid)"
305346
cat > /tmp/api_scope_patch.json <<EOF
306347
{
307348
"identifierUris": ["$API_IDENTIFIER_URI"],
@@ -365,7 +406,7 @@ WEB_IDENTIFIER_URI="api://${WEB_CLIENT_ID}"
365406
# + add SPA redirect URI + declare required resource access on API scope + Graph User.Read
366407
WEB_SCOPE_ID="$(az ad app show --id "$WEB_CLIENT_ID" \
367408
--query "api.oauth2PermissionScopes[?value=='user_impersonation'].id | [0]" -o tsv)"
368-
[[ -z "$WEB_SCOPE_ID" || "$WEB_SCOPE_ID" == "null" ]] && WEB_SCOPE_ID="$(cat /proc/sys/kernel/random/uuid)"
409+
[[ -z "$WEB_SCOPE_ID" || "$WEB_SCOPE_ID" == "null" ]] && WEB_SCOPE_ID="$(generate_uuid)"
369410

370411
cat > /tmp/web_patch.json <<EOF
371412
{

infra/scripts/post_deployment.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,9 @@ if (-not $ApiReady) {
332332

333333
$schemaId = $Registered[$schemaClass]
334334
if (-not $schemaId) {
335-
Write-Host " - No schema ID found for '$schemaClass'. Skipping '$fileName'."
336-
continue
335+
Write-Host " - No schema ID found for '$schemaClass'. Marking bundle upload as failed and skipping submission."
336+
$uploadSuccess = $false
337+
break
337338
}
338339

339340
Write-Host " - Uploading '$fileName' (schema: $schemaClass)..."

infra/scripts/post_deployment.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,9 @@ else
341341
done
342342

343343
if [ -z "$SCHEMA_ID" ]; then
344-
echo " - No schema ID found for '$SCHEMA_CLASS'. Skipping '$FILE_NAME'."
345-
continue
344+
echo " ❌ No schema ID found for '$SCHEMA_CLASS'. Marking bundle upload as failed and skipping submission."
345+
UPLOAD_SUCCESS=false
346+
break
346347
fi
347348

348349
echo " - Uploading '$FILE_NAME' (schema: $SCHEMA_CLASS)..."

infra/scripts/run_post_deployment.ps1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ if ($env:SKIP_SCHEMA_REGISTRATION -eq "true") {
8989
Write-StepOk 1
9090
} catch {
9191
Write-StepFail 1
92-
Write-Host " To retry : .\$Step1Script"
93-
Write-Host " To skip : `$env:SKIP_SCHEMA_REGISTRATION = 'true'; .\$ScriptDir\run_post_deployment.ps1"
92+
Write-Host " To retry : & \"$Step1Script\""
93+
Write-Host " To skip : `$env:SKIP_SCHEMA_REGISTRATION = 'true'; & \"$(Join-Path $ScriptDir 'run_post_deployment.ps1')\""
9494
exit 1
9595
}
9696
}
@@ -115,8 +115,8 @@ if ($env:SKIP_SAMPLE_DATA_UPLOAD -eq "true") {
115115
Write-StepOk 2
116116
} catch {
117117
Write-StepFail 2
118-
Write-Host " To retry : .\$Step2Script"
119-
Write-Host " To skip : `$env:SKIP_SAMPLE_DATA_UPLOAD = 'true'; .\$ScriptDir\run_post_deployment.ps1"
118+
Write-Host " To retry : & \"$Step2Script\""
119+
Write-Host " To skip : `$env:SKIP_SAMPLE_DATA_UPLOAD = 'true'; & \"$(Join-Path $ScriptDir 'run_post_deployment.ps1')\""
120120
exit 1
121121
}
122122
}
@@ -134,18 +134,18 @@ Write-Host " * Cloud Application Administrator / Global Administrator — to
134134
Write-Host " * Contributor on resource group — to update Container Apps"
135135
Write-Host ""
136136
Write-Host " To skip this step:"
137-
Write-Host " `$env:SKIP_AUTH_SETUP = 'true'; .\$ScriptDir\run_post_deployment.ps1"
137+
Write-Host " `$env:SKIP_AUTH_SETUP = 'true'; & \"$(Join-Path $ScriptDir 'run_post_deployment.ps1')\""
138138
Write-Host " — or —"
139139
Write-Host " azd env set AZURE_SKIP_AUTH_SETUP true"
140-
Write-Host " then run .\$Step3Script later when permissions are available."
140+
Write-Host " then run & \"$Step3Script\" later when permissions are available."
141141
Write-Host ""
142142

143143
$AzureSkipAuth = Azd-Get "AZURE_SKIP_AUTH_SETUP"
144144

145145
if ($env:SKIP_AUTH_SETUP -eq "true" -or $AzureSkipAuth -eq "true" -or $env:AZURE_SKIP_AUTH_SETUP -eq "true") {
146146
Write-StepSkip 3 "SKIP_AUTH_SETUP=true or AZURE_SKIP_AUTH_SETUP=true"
147147
Write-Host " Run manually when permissions are available:"
148-
Write-Host " .\$Step3Script"
148+
Write-Host " & \"$Step3Script\""
149149
} else {
150150
if (-not (Test-Path $Step3Script)) {
151151
Write-Error "Script not found: $Step3Script"
@@ -157,7 +157,7 @@ if ($env:SKIP_AUTH_SETUP -eq "true" -or $AzureSkipAuth -eq "true" -or $env:AZURE
157157
Write-StepOk 3
158158
} catch {
159159
Write-StepFail 3
160-
Write-Host " To retry auth setup : .\$Step3Script"
160+
Write-Host " To retry auth setup : & \"$Step3Script\""
161161
Write-Host " For manual portal steps: docs/ConfigureAppAuthentication.md"
162162
exit 1
163163
}

0 commit comments

Comments
 (0)