Esempio n. 1
0
        /// <summary>
        /// Creates the secret appsettings.json file.
        /// </summary>
        public static void CreateSecretAppSettingsFile()
        {
            if (!DeploymentEnvironmentHelper.IsDogfood() && !DeploymentEnvironmentHelper.IsPublicOrNationalCloud())
            {
                return;
            }

            var appSettingsDictionary = new Dictionary <string, string>();

            var fileEntries = Directory.GetFiles(WebHostStartupHelper.SecretsDirectoryPath);

            foreach (var fullyQualifiedFileName in fileEntries)
            {
                using (var streamReader = new StreamReader(fullyQualifiedFileName))
                {
                    #pragma warning disable CA1307 // Specify StringComparison
                    var secretKey = Path
                                    .GetFileName(fullyQualifiedFileName)
                                    .Replace("-", ".");

                    var secretValue = streamReader.ReadToEnd();
                    appSettingsDictionary.Add(secretKey, secretValue);
                }
            }

            var appsettingsJson = JsonConvert.SerializeObject(appSettingsDictionary);

            // Write the json string to app setings file.
            using (var streamWriter = new StreamWriter(Path.Combine(WebHostStartupHelper.SecretAppSettingsDirectoryPath, WebHostStartupHelper.SecretAppSettingsFileName)))
            {
                streamWriter.WriteLine(appsettingsJson);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates the PFX certificates.
        /// </summary>
        /// <param name="pfxCertificates"> The dictionary of PFX certificates names as key and PEM files from which PFX would be creates as value. </param>
        public static void CreatePFXCertificates(Dictionary <string, string> pfxCertificates)
        {
            if (!DeploymentEnvironmentHelper.IsDogfood() && !DeploymentEnvironmentHelper.IsPublicOrNationalCloud())
            {
                return;
            }

            if (pfxCertificates != null)
            {
                foreach (KeyValuePair <string, string> keyValuePair in pfxCertificates)
                {
                    var pfxCertificateName    = keyValuePair.Key;
                    var publicCertificateName = keyValuePair.Value.Split(":")[0];
                    var privateKeyName        = keyValuePair.Value.Split(":")[1];

                    var pfxCertPath        = Path.Combine(WebHostStartupHelper.CertificatesDirectoryPath, pfxCertificateName);
                    var publicCertPath     = Path.Combine(WebHostStartupHelper.CertificatesDirectoryPath, publicCertificateName);
                    var privateCertkeyPath = Path.Combine(WebHostStartupHelper.CertificatesDirectoryPath, privateKeyName);

                    CreatePFXCertificate(pfxCertPath, publicCertPath, privateCertkeyPath);
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Tells if the current environment is public
 /// </summary>
 public static bool IsPublic()
 {
     return(DeploymentEnvironmentHelper.GetEnvironment()
            .Equals(DeploymentEnvironmentName.Production.ToString(), StringComparison.OrdinalIgnoreCase));
 }
Esempio n. 4
0
 /// <summary>
 /// Tells if the current environment is mooncake
 /// </summary>
 public static bool IsMooncake()
 {
     return(DeploymentEnvironmentHelper.GetEnvironment()
            .Equals(DeploymentEnvironmentName.Mooncake.ToString(), StringComparison.OrdinalIgnoreCase));
 }
Esempio n. 5
0
 /// <summary>
 /// Tells if the current environment is public
 /// </summary>
 public static bool IsPublicOrNationalCloud()
 {
     return(DeploymentEnvironmentHelper.IsPublic() || DeploymentEnvironmentHelper.IsMooncake());
 }