Skip to content

Commit d401063

Browse files
committed
fix: add backfill setting
1 parent f418312 commit d401063

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Modules/CIPPCore/Public/GraphHelper/Update-CIPPAzFunctionAppSetting.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ function Update-CIPPAzFunctionAppSetting {
6262
$currentProps[$prop.Name] = [string]$prop.Value
6363
}
6464
}
65+
} else {
66+
# Could not retrieve current settings - backfill from EnvVarBackup to avoid overwriting required properties with empty values
67+
Write-Warning "Could not retrieve current Function App settings for $Name - attempting to backfill from environment variable backup."
68+
$EnvBackupTable = Get-CIPPTable -tablename 'EnvVarBackups'
69+
$BackupEntity = Get-CIPPAzDataTableEntity @EnvBackupTable -Filter "PartitionKey eq 'EnvVarBackup' and RowKey eq '$Name'"
70+
if ($BackupEntity -and $BackupEntity.Values) {
71+
($BackupEntity.Values | ConvertFrom-Json).PSObject.Properties | ForEach-Object {
72+
if ($_.Value) { $currentProps[$_.Name] = [string]$_.Value }
73+
}
74+
Write-Information "Backfilled $($currentProps.Count) properties from environment variable backup for $Name"
75+
} else {
76+
throw "Failed to retrieve current settings for Function App $Name and no backup found - aborting update to avoid potential misconfiguration."
77+
}
6578
}
6679

6780
# Merge requested settings

0 commit comments

Comments
 (0)