private async Task ResolveConfigurationValuesToContext(IEnumerable <IHaveInfrastructure> elementsWithInfrastructure, AzureConfigurationValueResolverContext configContext) { var valuesAndResolvers = elementsWithInfrastructure.SelectMany(c => { var renderer = Ioc.GetRendererFor(c); return(renderer != null ? renderer.GetConfigurationValues(c) : Enumerable.Empty <IConfigurationValue>()); }) .Where(v => !v.IsResolved) .Distinct() .ToDictionary(v => v, v => Ioc.GetResolverFor(v)); var value = FindFirstValueToBeResolved(valuesAndResolvers); while (value != null) { var resolver = valuesAndResolvers[value]; valuesAndResolvers.Remove(value); var resolvedValue = await resolver.Resolve(value); configContext.Values.Add(value, resolvedValue); value = FindFirstValueToBeResolved(valuesAndResolvers); } }
private void SetContextToConfigurationResolvers(IAzure azure, IGraphRbacManagementClient graph, string resourceGroupName) { var configContext = new AzureConfigurationValueResolverContext(azure, graph, resourceGroupName); Ioc.Register(configContext); }
protected override async Task Configure(IHaveInfrastructure <WebAppService> elementWithInfrastructure, AzureConfigurationValueResolverContext context) { var webapp = await context.Azure.WebApps.GetByResourceGroupAsync(context.ResourceGroupName, elementWithInfrastructure.Infrastructure.Name); var appSettings = new Dictionary <string, string>(); foreach (var setting in elementWithInfrastructure.Infrastructure.Settings) { object value; if (context.Values.TryGetValue(setting.Value, out value)) { appSettings.Add(setting.Name, value.ToString()); } } IUpdate <IWebApp> update = null; if (appSettings.Any()) { update = webapp.Update().WithAppSettings(appSettings); } foreach (var connectionString in elementWithInfrastructure.Infrastructure.ConnectionStrings) { object value; if (context.Values.TryGetValue(connectionString.Value, out value)) { update = (update ?? webapp.Update()).WithConnectionString( connectionString.Name, value.ToString(), (ConnectionStringType)Enum.Parse(typeof(ConnectionStringType), connectionString.Type)); } } if (update != null) { await update.ApplyAsync(); } }
protected virtual Task Configure(IHaveInfrastructure <TInfrastructure> elementWithInfrastructure, AzureConfigurationValueResolverContext context) { return(Task.FromResult(0)); }
public Task Configure(IHaveInfrastructure elementWithInfrastructure, AzureConfigurationValueResolverContext context) { return(Configure((IHaveInfrastructure <TInfrastructure>)elementWithInfrastructure, context)); }
protected override Task Configure(IHaveInfrastructure <KeyVault> elementWithInfrastructure, AzureConfigurationValueResolverContext context) { foreach (var secret in elementWithInfrastructure.Infrastructure.Secrets) { object value; if (context.Values.TryGetValue(secret.Value, out value)) { // TODO: add secret to key vault using the context.Client } } return(Task.FromResult(1)); }