Ejemplo n.º 1
0
        private async Task ApplySecrets(string slotName, List <RegeneratedSecret> secrets)
        {
            if (secrets.Count > 1 && secrets.Select(s => s.UserHint).Distinct().Count() != secrets.Count)
            {
                throw new Exception("Multiple secrets sent to Provider but without distinct UserHints!");
            }

            IUpdate <IDeploymentSlot> updateBase = (await GetDeploymentSlot(slotName)).Update();

            foreach (RegeneratedSecret secret in secrets)
            {
                var appSettingName = string.IsNullOrEmpty(secret.UserHint) ? Configuration.SettingName : $"{Configuration.SettingName}-{secret.UserHint}";
                _logger.LogInformation("Updating AppSetting '{AppSettingName}' in slot '{SlotName}' (as {AppSettingType})", appSettingName, slotName,
                                       Configuration.CommitAsConnectionString ? "connection string" : "secret");

                updateBase = updateBase.WithAppSetting(appSettingName,
                                                       Configuration.CommitAsConnectionString ? secret.NewConnectionStringOrKey : secret.NewSecretValue);
            }

            _logger.LogInformation("Applying changes.");
            await updateBase.ApplyAsync();

            _logger.LogInformation("Swapping to '{SlotName}'", slotName);
            await(await GetWebApp()).SwapAsync(slotName);
        }
Ejemplo n.º 2
0
        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();
            }
        }
Ejemplo n.º 3
0
        private async Task ApplySecrets(string slotName, List <RegeneratedSecret> secrets)
        {
            if (secrets.Count > 1 && secrets.Select(s => s.UserHint).Distinct().Count() != secrets.Count)
            {
                throw new Exception("Multiple secrets sent to Provider but without distinct UserHints!");
            }

            IUpdate <IFunctionDeploymentSlot> updateBase = (await GetDeploymentSlot(TemporarySlotName)).Update();

            foreach (RegeneratedSecret secret in secrets)
            {
                var connectionStringName = string.IsNullOrEmpty(secret.UserHint) ? Configuration.ConnectionStringName : $"{Configuration.ConnectionStringName}-{secret.UserHint}";
                Logger.LogInformation("Updating Connection String '{0}' in slot '{1}'", connectionStringName, TemporarySlotName);
                updateBase = updateBase.WithoutConnectionString(connectionStringName);
                updateBase = updateBase.WithConnectionString(connectionStringName, secret.NewConnectionStringOrKey, Configuration.ConnectionStringType);
            }

            Logger.LogInformation("Applying changes.");
            await updateBase.ApplyAsync();

            Logger.LogInformation("Swapping to '{0}'", TemporarySlotName);
            await(await GetFunctionsApp()).SwapAsync(TemporarySlotName);
        }