Exemplo n.º 1
0
        internal static void SendAppSettings()
        {
            var tasks = new List <Task <bool> >();

            foreach (var key in ConfigurationManager.AppSettings.AllKeys)
            {
                tasks.Add(Task.Run(async() => await KeyVaultProvider.CreateOrUpdateAppSettingAsync(key, ConfigurationManager.AppSettings[key])));
            }

            var results = Task.WhenAll(tasks).Result;

            if (results.Any(x => !x))
            {
                throw new KeyMasterException("Key master couldn't send app secrets to azure");
            }

            var xml = XDocument.Load(SecretsProvider.WebconfigFile);
            var doc = xml.Element("configuration");

            var appSettings = doc.Element("appSettings");

            if (appSettings != null)
            {
                appSettings.Remove();
            }

            xml.Save(SecretsProvider.WebconfigFile);
        }
Exemplo n.º 2
0
        internal static bool CreateOrUpdateAppSetting(string key, string value, Secrets secrets)
        {
            var appsettings = new AppSettings
            {
                ClientId     = secrets.ClientId,
                ClientSecret = secrets.ClientSecret,
                DirectoryId  = secrets.DirectoryId,
                SecretName   = secrets.SecretName,
                KeyVaultUrl  = secrets.KeyVaultUrl
            };

            return(KeyVaultProvider.CreateOrUpdateAppSettingAsync(key, value, appsettings).Result);
        }