Exemplo n.º 1
0
        public override async Task RunAsync(CancellationToken cancellationToken)
        {
            bool foundError = !await _settingsFileValidator.ValidateFileAsync(_envSettingsFile, _baseSettingsFile, _manifestFile, cancellationToken);

            if (foundError)
            {
                throw new FailWithExitCodeException(76);
            }
        }
Exemplo n.º 2
0
        public override async Task RunAsync(CancellationToken cancellationToken)
        {
            bool haveErrors    = false;
            var  manifestFiles = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            foreach (string manifestFile in _manifestFiles)
            {
                SecretManifest      manifest    = SecretManifest.Read(manifestFile);
                StorageLocationType storageType = _storageLocationTypeRegistry.Get(manifest.StorageLocation.Type);
                if (!(storageType is AzureKeyVault azureKeyVaultStorageType))
                {
                    _console.WriteImportant($"Skipping non-azure-key-vault manifest {manifestFile}", ConsoleColor.Yellow);
                    continue;
                }

                string vaultUri = azureKeyVaultStorageType.GetAzureKeyVaultUri(ParameterConverter.ConvertParameters <AzureKeyVaultParameters>(manifest.StorageLocation.Parameters));

                manifestFiles.Add(vaultUri, manifestFile);
            }


            var settingsFiles = new List <(FileInfo environmentFile, FileInfo baseFile)>();

            foreach (string jsonFile in Directory.EnumerateFiles(_basePath, "settings.json", SearchOption.AllDirectories))
            {
                var baseFile = new FileInfo(jsonFile);
                foreach (string envFile in Directory.EnumerateFiles(baseFile.DirectoryName, "settings.*.json"))
                {
                    settingsFiles.Add((new FileInfo(envFile), baseFile));
                }
            }

            foreach (var(envFile, baseFile) in settingsFiles)
            {
                string specifiedVaultUri =
                    await ReadVaultUriFromSettingsFile(envFile.FullName) ??
                    await ReadVaultUriFromSettingsFile(baseFile.FullName);

                if (string.IsNullOrEmpty(specifiedVaultUri))
                {
                    _console.LogError($"Settings file pair ({envFile}, {baseFile}) has no vault uri.", envFile.FullName, 0, 0);
                    haveErrors = true;
                    continue;
                }

                _console.WriteLine($"Settings file pair ({envFile}, {baseFile}) has vault uri {specifiedVaultUri}");

                if (!manifestFiles.TryGetValue(specifiedVaultUri, out string manifestFile))
                {
                    _console.LogError($"Vault Uri {specifiedVaultUri} does not have a matching manifest.", envFile.FullName, 0, 0);
                    haveErrors = true;
                    continue;
                }

                haveErrors |= !await _settingsFileValidator.ValidateFileAsync(envFile.FullName, baseFile.FullName, manifestFile, cancellationToken);
            }

            if (haveErrors)
            {
                throw new FailWithExitCodeException(77);
            }
        }