Change authlevel through env variables
We want to be able to switch authlevels of all functions using env variable.
Background: When running azure function in container, it uses authlevel:function even if developing locally if authlevel is set to function in function.json. Instead of changing authlevel:function to authlevel:anonymous one by one for every function, we want to be able to switch the authlevel for all function with env vars.
According to the azure functions documentation, this seems possible by using the %xxx% expressions: https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-expressions-patterns#binding-expressions---app-settings
Hi @priyaananthasankar,
It this issue Python worker specific, or is this a feature request to the host? Just want to get more context before we decide to make the change.
@Hazhzeng For me this is python as I use Azure Functions with python specifically but I guess it is for the host? It would make it much easier for doing end-2-end testing if this was possible. Then you could easily define a docker-compose file with your function (without changes), azurite (if needed) and a container orchestrating tests.
I would be nice to do it with an extra option to AzureWebJobsSecretStorageType https://docs.microsoft.com/en-us/azure/azure-functions/functions-app-settings#azurewebjobssecretstoragetype
In future, with new programming model work we are doing, this could be handled by the an easy approach. How it'll look like soon:
import azure.functions as func
app = func.FunctionApp(auth_level=func.AuthLevel.ANONYMOUS)
@app.function_name(name="HttpTrigger1")
@app.route(route="hello") # HTTP Trigger
def test_function(req: func.HttpRequest) -> func.HttpResponse:
return func.HttpResponse("HttpTrigger1 function processed a request!!!")
So you can convert this to be an environment variable.
import azure.functions as func
app = func.FunctionApp(auth_level=ENV_VARIABLE)
@app.function_name(name="HttpTrigger1")
@app.route(route="hello") # HTTP Trigger
def test_function(req: func.HttpRequest) -> func.HttpResponse:
return func.HttpResponse("HttpTrigger1 function processed a request!!!")
Assigning this to @YunchuWang for taking this forward and adding more context to the answer above, whenever the new PyStein work is public.
@vrdmr that looks promising :-)