-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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 Errors When Used in PowerShell with Multiple Settings #23919
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", "Set at $(Get-Date)")
$appSettingsToUpdate2.Add("Setting2", "Set at $(Get-Date)")
$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": "Set at 09/16/2022 10:45:02"
},
{
"name": "Setting2",
"slotSetting": false,
"value": "Set at 09/16/2022 10:45:02"
} |
Duplicate of #23797 |
@jiasli I'm confused, the linked issue seemed to be a problem with using a PowerShell Array if you look at the example and code provided I am passing a space separated string. As far as I understood the linked issue they were not passing in a space delimited string. Can you show the above example working? |
@aolszowka, here is the result of your > $expandedSettingsString
"Setting1=Set at 09/19/2022 11:19:10" "Setting2=Set at 09/19/2022 11:19:10"
# Set the new settings; This will restart the function app
> az functionapp config appsettings set --name REDACTED --resource-group REDACTED --settings $expandedSettingsString --debug
cli.knack.cli: Command arguments: ['functionapp', 'config', 'appsettings', 'set', '--name', 'REDACTED', '--resource-group', 'REDACTED', '--settings', 'Setting1=Set', 'at', '09/19/2022', '11:19:10 Setting2=Set', 'at', '09/19/2022', '11:19:10 ', '--debug']
This should work: $appSettingsToUpdate = [System.Collections.Generic.Dictionary[string, string]]::new()
$appSettingsToUpdate.Add("Setting1", "Set at $(Get-Date)")
$appSettingsToUpdate.Add("Setting2", "Set at $(Get-Date)")
$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:
|
The fact that > $expandedSettingsString = """a=b c"" ""d=e f"""
> $expandedSettingsString
"a=b c" "d=e f"
> python -c "import sys; print(sys.argv)" $expandedSettingsString
['-c', 'a=b', 'c d=e', 'f']
> python -c "import sys; print(sys.argv)" '"a=b c" "d=e f"'
['-c', 'a=b', 'c d=e', 'f'] I guess it's because when calling native exe, PowerShell passes
This is fixed in PowerShell 7.3: > python -c "import sys; print(sys.argv)" $expandedSettingsString
['-c', '"a=b c" "d=e f"']
> python -c "import sys; print(sys.argv)" '"a=b c" "d=e f"'
['-c', '"a=b c" "d=e f"'] The correct way to pass multiple arguments is to use > $expandedSettingsString="a=b c", "d=e f"
> python -c "import sys; print(sys.argv)" @expandedSettingsString
['-c', 'a=b c', 'd=e f']
> python -c "import sys; print(sys.argv)" "a=b c" "d=e f"
['-c', 'a=b c', 'd=e f'] |
@jiasli BINGO! Thank you for linking the PowerShell issue that is what I was looking for as I felt the original code met the requirements of a space separated "Key=Value" pair. It is PowerShell's mishandling of the double quotes (in versions prior to 7.3) that was the root cause of this issue. The intent of this line: $settingsString.Append("""$($appSettingToUpdate.Key)=$($appSettingToUpdate.Value)"" ") | Out-Null Was to produce a string that looked like
|
Describe the bug
I have been trying to troubleshoot why I am unable to use the documented
--settings
switch with multiple space separatedKey=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 which I am trying to reproduce.I have created a small test script to try to troubleshoot the issue and was able to get a slightly different error message.
Command Name
az functionapp config appsettings set
Errors:
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 {} {} {} {} {} {} {}
The command is being generated from this PowerShell Script (I have redacted any private information):
Expected Behavior
I would expect this to work. This should be equivalent to:
az functionapp config appsettings set --name {REDACTED} --resource-group {REDACTED} --settings "Setting1=Set at 09/16/2022 09:21:42" "Setting2=Set at 09/16/2022 09:21:42"
Which does work when manually run through the command line
Workaround
I suspect that there is probably some weird behavior with PowerShell and the way that this parses commands. I am going to attempt a work around by just providing the settings as a JSON file. However this is not documented to work this way for
functionapp
but is documented to work this way forwebapp
(See Documentation) I suspect that this will work even if not documented to do so (that should be fixed).Environment Summary
Additional Context
The text was updated successfully, but these errors were encountered: