public static IOrchestrationConfiguration MapCommand <T>(this IOrchestrationConfiguration configuration, string orchestrationName, Func <ICommand, TimeSpan> orchestrationTimeout = null) where T : IProviderCommand { if (configuration is null) { throw new ArgumentNullException(nameof(configuration)); } if (string.IsNullOrEmpty(orchestrationName)) { throw new ArgumentException("Cannot be null or empty.", nameof(orchestrationName)); } if (!FunctionsEnvironment.FunctionExists(orchestrationName)) { throw new ArgumentOutOfRangeException(nameof(orchestrationName), $"Could not find orchstration by name '{orchestrationName}'"); } configuration.Orchestrations[typeof(T)] = new OrchestrationSettings() { OrchestrationName = orchestrationName, OrchstrationTimeout = orchestrationTimeout ?? OrchestrationSettings.DefaultOrchestrationTimeout }; return(configuration); }
public static async Task RunActivity( [ActivityTrigger] IDurableActivityContext functionContext) { if (functionContext is null) { throw new ArgumentNullException(nameof(functionContext)); } var(key, value) = functionContext.GetInput <(string, string)>(); var appSettings = await FunctionsEnvironment .GetAppSettingsAsync() .ConfigureAwait(false); if (value is null) { appSettings.Remove(key); } else if (!appSettings.TryGetValue(key, out var existingValue) || existingValue != value) { appSettings[key] = value; } else { return; // app settings unmodified - no need to send an update } _ = await FunctionsEnvironment .SetAppSettingsAsync(appSettings) .ConfigureAwait(false); }
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" }); }
public bool CanHandle(IOrchestratorCommand orchestratorCommand) { if (orchestratorCommand is null) { throw new ArgumentNullException(nameof(orchestratorCommand)); } var orchestrationName = GetCommandOrchestrationName(orchestratorCommand); return(FunctionsEnvironment.FunctionExists(orchestrationName)); }
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()); }
private static Task <string> GetCallbackUrl() => FunctionsEnvironment.GetFunctionUrlAsync(nameof(AuthorizationHandler) + nameof(Callback));
private static Task <string> GetAuthorizeUrl() => FunctionsEnvironment.GetFunctionUrlAsync(nameof(AuthorizationHandler));