-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
az functionapp config appsettings set Munges values into first setting when no spaces are used in PowerShell with multiple settings #23920
Comments
route to CXP team |
I can confirm that the following workaround does indeed work: $appSettingsToUpdate2 = [System.Collections.Generic.Dictionary[string, string]]::new()
$appSettingsToUpdate2.Add("Setting1", "SetValueWithNoSpaces")
$appSettingsToUpdate2.Add("Setting2", "SetValueWithNoSpaces2")
$appSettingsToUpdate = foreach ($appSettingToUpdate in $appSettingsToUpdate2.GetEnumerator()) {
[PSCustomObject]@{
name = $appSettingToUpdate.Key
slotSetting = $false
value = $appSettingToUpdate.Value
}
}
# Due to this issue we're going to work around this by creating a
# throw-away JSON file to pass to the command:
# https://github.com/Azure/azure-cli/issues/23920
# https://docs.microsoft.com/en-us/cli/azure/functionapp/config/appsettings?view=azure-cli-latest#az-functionapp-config-appsettings-set
$appSettingsJsonFile = New-TemporaryFile
try {
$appSettingsToUpdate | ConvertTo-Json | Out-File -FilePath $appSettingsJsonFile.FullName
# Set the new settings; This will restart the function app
# Note that as of 2022/09/16 taking a JSON file is undocumented but
# does work.
az functionapp config appsettings set --name {REDACTED} --resource-group {REDACTED} --settings "@$($appSettingsJsonFile.FullName)"
}
finally {
# Cleanup after ourselves
Remove-Item $appSettingsJsonFile
} Properly updates the settings like so: {
"name": "Setting1",
"slotSetting": false,
"value": "SetValueWithNoSpaces"
},
{
"name": "Setting2",
"slotSetting": false,
"value": "SetValueWithNoSpaces2"
} |
@aolszowka Thank you for reaching out, glad to know that the work around helped. We are investigating the original issue |
Duplicate of #23797 |
@jiasli Again the linked issue looks to be an end user passing an Array, this passes a constructed space delimited string. Can you explain what I'm missing here? Is this some PowerShell Functionality that I don't quite understand? |
This should work: $appSettingsToUpdate = [System.Collections.Generic.Dictionary[string, string]]::new()
$appSettingsToUpdate.Add("Setting1", "SetValueWithNoSpaces")
$appSettingsToUpdate.Add("Setting2", "SetValueWithNoSpaces2")
$settings = [System.Collections.ArrayList]@()
foreach ($appSettingToUpdate in $appSettingsToUpdate.GetEnumerator()) {
$settings.Add("$($appSettingToUpdate.Key)=$($appSettingToUpdate.Value)")
}
# Set the new settings; This will restart the function app
az functionapp config appsettings set --name REDACTED --resource-group REDACTED --settings @settings --debug Output:
|
Correct, because you've changed the behavior of the script to instead pass a PowerShell Array instead of using the string. As you mentioned in the sister issue the root cause of the problem is PowerShell/PowerShell#1995 which supposedly is fixed in PowerShell 7.3. I will use the work around of passing the JSON object as this will subvert both issues entirely. I appreciate you digging further into this. |
Related to #23919 but different behavior.
I have been trying to troubleshoot why I am unable to use the documented --settings switch with multiple space separated
Key=Value
pairs Documentation in a PowerShell script I have for provisioning. In my production script I end up having all of the secrets roll into the first secret.I am able to reproduce this behavior with this new script.
I suspect that there is an issue with the way that these values are parsed after the argument and a combination of sending this from PowerShell.
Describe the bug
Command Name
az functionapp config appsettings set
Errors:
This does not error but produces undesired behavior that is detailed below.
To Reproduce:
Steps to reproduce the behavior. Note that argument values have been redacted, as they may contain sensitive information.
az functionapp config appsettings set --name {} --resource-group {} --settings {}
This command is being generated from this PowerShell Script (I have redacted any private information):
This ends up generating this for a setting:
As you can see
Setting1
has been munged together withSetting2
Expected Behavior
This should have generated something equivalent to the following:
az functionapp config appsettings set --name {REDACTED} --resource-group {REDACTED} --settings "Setting1=SetValueWithNoSpaces" "Setting2=SetValueWithNoSpaces2"
Which does work when manually ran through the command line.
Workaround
Again I suspect there is probably some weird behavior with PowerShell and the way this command is passed to
az
combined with the way thataz
parses commands. From the error report you can see thataz
thinks it only got one setting rather than the space separated values that the script expected to send.Again I am going to try working around this by passing a JSON file that contains the settings to avoid this, but for
functionapp
this is not documented behavior.Environment Summary
Additional Context
The text was updated successfully, but these errors were encountered: