Ejemplo 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);
            }
        }
Ejemplo 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);
                }
            }
        }