internal static async Task <string> GetUrlAsync(string instanceId, ICommand command) { string functionKey = null; if (FunctionsEnvironment.IsAzureEnvironment) { functionKey = await GetTokenAsync().ConfigureAwait(false); if (string.IsNullOrEmpty(functionKey)) { throw new NotSupportedException($"Function '{nameof(CallbackTrigger)}' must have a 'default' APIKey."); } } var hostUrl = await FunctionsEnvironment .GetHostUrlAsync() .ConfigureAwait(false); return(hostUrl .AppendPathSegment("api/callback") .AppendPathSegment(instanceId, true) .AppendPathSegment(command.CommandId) .SetQueryParam("code", functionKey) .ToString()); }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "start")] HttpRequestMessage httpRequest, ILogger log) { if (httpRequest is null) { throw new ArgumentNullException(nameof(httpRequest)); } var isConfigured = await github .IsConfigured() .ConfigureAwait(false); if (isConfigured) { return new ContentResult { Content = CompleteHtml, ContentType = "text/html" } } ; var host = await FunctionsEnvironment .GetHostUrlAsync() .ConfigureAwait(false); log.LogWarning(host); return(new ContentResult { Content = Html(host), ContentType = "text/html" }); }
internal static async Task <string> GetUrlAsync() { var masterKey = await FunctionsEnvironment .GetAdminKeyAsync() .ConfigureAwait(false); var hostUrl = await FunctionsEnvironment .GetHostUrlAsync() .ConfigureAwait(false); var json = await hostUrl .AppendPathSegment("admin/host/systemkeys/eventgrid_extension") .SetQueryParam("code", masterKey, isEncoded: true) .GetJObjectAsync() .ConfigureAwait(false); return(hostUrl .AppendPathSegment("runtime/webhooks/eventgrid") .SetQueryParam("functionName", nameof(EventTrigger)) .SetQueryParam("code", json.SelectToken("value")?.ToString()) .ToString()); }
private static async Task <string> GetTokenAsync() { var masterKey = await FunctionsEnvironment .GetAdminKeyAsync() .ConfigureAwait(false); var hostUrl = await FunctionsEnvironment .GetHostUrlAsync() .ConfigureAwait(false); var json = await hostUrl .AppendPathSegment("admin/functions") .AppendPathSegment(nameof(CallbackTrigger)) .AppendPathSegment("keys") .SetQueryParam("code", masterKey) .GetJObjectAsync() .ConfigureAwait(false); var tokens = json .SelectTokens($"$.keys[?(@.name != 'default')].value") .Select(token => token.ToString()) .ToArray(); if (tokens.Length == 1) { return(tokens[0]); } else if (tokens.Length > 1) { return(tokens[new Random().Next(0, tokens.Length - 1)]); } return(json .SelectToken($"$.keys[?(@.name == 'default')].value")? .ToString()); }