Azure-cli: Azure CLI "cors add" creates multiple entries of the same origin.

Created on 24 Jun 2019  路  5Comments  路  Source: Azure/azure-cli

az feedback auto-generates most of the information requested below, as of CLI version 2.0.62

Describe the bug
Calling "az functionapp cors add" from the CI/CD pipeline creates a new cors entry every time, instead of checking if the entry already exists.
This is important since I use it in the pipelines which are called every time the git repo is updated.

To Reproduce

az functionapp cors add --resource-group  $(ResourceGroupName) --name $(AppName)  --allowed-origins $(allowedOrigins)

Expected behavior
If I call az functionapp cors add multiple time, it should just create a single entry of the origin and not multiple.

Environment summary
Azure pipeline

Additional context
Image from the azure dashboard
Screenshot 2019-06-24 at 14 06 06

Functions Functions-cli Service Attention customer-reported

Most helpful comment

Thanks for reporting that, we will take a look and fix it in a future release

All 5 comments

Thanks for reporting that, we will take a look and fix it in a future release

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @ ahmedelnably, @fabiocav

Also had this issue. Only an issue after updating to latest version (can't say which version introduced the issue as I was previously 4 versions out of date).

Uggly workaround to check if origin is already set in PowerShell.
If not set, add it otherwise skip.

$FunctionAppName = "foo"
$ResourceGroupName = "bar"

# Configure CORS for Function App
Write-Host "Set CORS in function app"
$allowedOrigins = "https://dev.azure.com","https://localhost:3000"

foreach ($item in $allowedOrigins) {
    Write-Host "Check if allowedorigin '$item' is already set"
    $missesOrigin = az functionapp cors show --name "$FunctionAppName" --resource-group $ResourceGroupName --query "contains(to_string(length(allowedOrigins[?contains(@, '$item')])),'0')"
    if ($missesOrigin -eq "true") {
        Write-Host "Add allowedorigin '$item'"
        az functionapp cors add -n "$FunctionAppName" --allowed-origins $item
    }
    else {
        Write-Host "Allowedorigin '$item' already set"
    }
}

Still an issue. I'm using a different workaround where I remove before adding. Seems to work fine since removing non-existing origins does not throw error or warning.
ex:
az functionapp cors remove --allowed-origins http://www.example.com
az functionapp cors add --allowed-origins http://www.example.com

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PrHar picture PrHar  路  3Comments

Kannaj picture Kannaj  路  3Comments

derekbekoe picture derekbekoe  路  3Comments

amarzavery picture amarzavery  路  3Comments

dhermans picture dhermans  路  3Comments