microsoft / vscode-azurefunctions

Azure Functions extension for VS Code
https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurefunctions
MIT License
290 stars 134 forks source link

Pass Azurite configuration settings to function host #3876

Open danielniccoli opened 1 year ago

danielniccoli commented 1 year ago

When working with Azure Durable Functions, Azurite is usually involved. If for some reason you have to change the ports that Azurite is listening on in settings.json as shown here ...

}
    "azurite.location": ".azurite",
    "azurite.blobPort": 10010,
    "azurite.queuePort": 10011,
    "azurite.tablePort": 10012,
    // ...
}

... one also must modify local.settings.json to inform the locally running azure functions host to connect to the new Azurite ports. This includes having to know the exact connection string details, including a public predefined password.

So the simple JSON key-value pair

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "AzureWebJobsStorage": "UseDevelopmentStorage=True"
    "AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
    // ...    
  },
  "Host": {
    "LocalHttpPort": 7072
  }
}

must be replaced by this very verbose line

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10010/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10011/devstoreaccount1;TableEndpoint=http://127.0.0.1:10012/devstoreaccount1;",
    "AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
    // ...    
  },
  "Host": {
    "LocalHttpPort": 7072
  }
}

My suggestion is that the azurite listening configuration (e.g., azurite.blobPort) is passed to the functions host when set.

Implementation approach

The setting UseDevelopmentStorage=True is the short-hand for DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;. (The AccountKey is pre-defined as well and taken from the Microsoft docs!)

  1. Check if local.settings.json contains UseDevelopmentStorage=True
  2. Check if settings.json contains azurite listenening settings.
  3. If 1) and 2) are true, pass a modified connection string directly to the process when it is started, that overrides the local.settings.json value

I don't know the function host enough to know if that would work, so I'll just leave it here.

alexweininger commented 1 year ago

Related to https://github.com/microsoft/vscode-azurefunctions/issues/3862

paulyuk commented 1 year ago

Hey @danielniccoli - thank you for this report. Could you do me a favor and ping me offline on my twitter @paulyuki99? I have a follow up question. Paul - from Azure team

danielniccoli commented 1 year ago

Hi @paulyuk, I don't have a Twitter account. I could contact you through the email address on your profile, if you like.