// Compute the site ID, for both the top level function API case and the regular nested case private FunctionEnvelope AddFunctionAppIdToEnvelope(FunctionEnvelope function) { Uri referrer = Request.Headers.Referrer; if (referrer == null) { return(function); } string armId = referrer.AbsolutePath; const string msWeb = "Microsoft.Web"; const string functionResource = msWeb + "/functions"; const string sitesResource = msWeb + "/sites"; // Input: /subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Web/functions/{funcname} int index = armId.IndexOf(functionResource, StringComparison.OrdinalIgnoreCase); if (index > 0) { // Produce: /subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Web/sites/{sitename} function.FunctionAppId = $"{armId.Substring(0, index)}{sitesResource}/{Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME")}"; return(function); } // Input: /subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Web/sites/{sitename}/functions/{funcname} index = armId.IndexOf(sitesResource, StringComparison.OrdinalIgnoreCase); if (index > 0) { // Produce: /subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Web/sites/{sitename} index = armId.IndexOf("/", index + sitesResource.Length + 1, StringComparison.OrdinalIgnoreCase); function.FunctionAppId = armId.Substring(0, index); return(function); } return(function); }
public void GetTriggers_ReturnsExpectedResults() { FunctionEnvelope excludedFunction = new FunctionEnvelope { Name = "TestExcludedFunction", Config = new JObject { { "excluded", true } } }; FunctionEnvelope disabledFunction = new FunctionEnvelope { Name = "TestDisabledFunction", Config = new JObject { { "disabled", true } } }; FunctionEnvelope invalidFunction = new FunctionEnvelope { Name = "TestInvalidFunction", Config = new JObject { { "bindings", "invalid" } } }; var queueTriggerFunction = new FunctionEnvelope { Name = "TestQueueFunction", Config = new JObject { { "bindings", new JArray { new JObject { { "type", "queueTrigger" }, { "direction", "in" }, { "queueName", "test" } }, new JObject { { "type", "blob" }, { "direction", "out" }, { "path", "test" } } } } } }; List <FunctionEnvelope> functions = new List <FunctionEnvelope> { excludedFunction, disabledFunction, invalidFunction, queueTriggerFunction }; var triggers = FunctionManager.GetTriggers(functions, NullTracer.Instance); Assert.Equal(1, triggers.Count); var trigger = triggers[0]; Assert.Equal(queueTriggerFunction.Name, (string)trigger["functionName"]); Assert.Equal(queueTriggerFunction.Config["bindings"][0], trigger); }