Esempio n. 1
0
        static GalleryConfiguration()
        {
            try
            {
                // This test suite hits the gallery which requires TLS 1.2 (at least in some environments).
                ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;

                // Load the configuration without injection. This allows us to read KeyVault configuration.
                var uninjectedBuilder = new ConfigurationBuilder()
                                        .AddJsonFile(EnvironmentSettings.ConfigurationFilePath, optional: false);
                var uninjectedConfiguration = uninjectedBuilder.Build();

                // Initialize KeyVault integration.
                var secretReaderFactory = new ConfigurationRootSecretReaderFactory(uninjectedConfiguration);
                var secretInjector      = secretReaderFactory.CreateSecretInjector(secretReaderFactory.CreateSecretReader());

                // Initialize the configuration with KeyVault secrets injected.
                var builder = new ConfigurationBuilder()
                              .SetBasePath(Environment.CurrentDirectory)
                              .AddInjectedJsonFile(EnvironmentSettings.ConfigurationFilePath, secretInjector);
                var instance = new GalleryConfiguration();
                builder.Build().Bind(instance);

                Instance = instance;
            }
            catch (ArgumentException ae)
            {
                throw new ArgumentException(
                          $"No configuration file was specified! Set the '{EnvironmentSettings.ConfigurationFilePathVariableName}' environment variable to the path to a JSON configuration file.",
                          ae);
            }
            catch (Exception e)
            {
                throw new ArgumentException(
                          $"Unable to load the JSON configuration file. " +
                          $"Make sure the JSON configuration file exists at the path specified by the '{EnvironmentSettings.ConfigurationFilePathVariableName}' " +
                          $"and that it is a valid JSON file containing all required configuration.",
                          e);
            }
        }
Esempio n. 2
0
 static GalleryConfiguration()
 {
     try
     {
         var configurationFilePath = EnvironmentSettings.ConfigurationFilePath;
         var configurationString   = File.ReadAllText(configurationFilePath);
         Instance = JsonConvert.DeserializeObject <GalleryConfiguration>(configurationString);
     }
     catch (ArgumentException ae)
     {
         throw new ArgumentException(
                   $"No configuration file was specified! Set the '{EnvironmentSettings.ConfigurationFilePathVariableName}' environment variable to the path to a JSON configuration file.",
                   ae);
     }
     catch (Exception e)
     {
         throw new ArgumentException(
                   $"Unable to load the JSON configuration file. " +
                   $"Make sure the JSON configuration file exists at the path specified by the '{EnvironmentSettings.ConfigurationFilePathVariableName}' " +
                   $"and that it is a valid JSON file containing all required configuration.",
                   e);
     }
 }