From 793e54db4d9a9e9d047767ffcde4640ac819c5af Mon Sep 17 00:00:00 2001 From: Fernando Rojo Date: Fri, 25 Oct 2024 17:28:48 -0700 Subject: [PATCH] remove variable and build arg paths --- .../ComponentDetectionConfigFileService.cs | 38 ------------------- .../Commands/BaseSettings.cs | 4 -- .../Commands/ScanCommand.cs | 2 +- 3 files changed, 1 insertion(+), 43 deletions(-) diff --git a/src/Microsoft.ComponentDetection.Common/ComponentDetectionConfigFileService.cs b/src/Microsoft.ComponentDetection.Common/ComponentDetectionConfigFileService.cs index ed9632dde..0c4551207 100644 --- a/src/Microsoft.ComponentDetection.Common/ComponentDetectionConfigFileService.cs +++ b/src/Microsoft.ComponentDetection.Common/ComponentDetectionConfigFileService.cs @@ -10,9 +10,7 @@ namespace Microsoft.ComponentDetection.Common; /// public class ComponentDetectionConfigFileService : IComponentDetectionConfigFileService { - private const string ComponentDetectionConfigFileEnvVar = "ComponentDetection.ComponentDetectionConfigFile"; private readonly IFileUtilityService fileUtilityService; - private readonly IEnvironmentVariableService environmentVariableService; private readonly IPathUtilityService pathUtilityService; private readonly ComponentDetectionConfigFile componentDetectionConfig; private readonly ILogger logger; @@ -20,13 +18,11 @@ public class ComponentDetectionConfigFileService : IComponentDetectionConfigFile public ComponentDetectionConfigFileService( IFileUtilityService fileUtilityService, - IEnvironmentVariableService environmentVariableService, IPathUtilityService pathUtilityService, ILogger logger) { this.fileUtilityService = fileUtilityService; this.pathUtilityService = pathUtilityService; - this.environmentVariableService = environmentVariableService; this.logger = logger; this.componentDetectionConfig = new ComponentDetectionConfigFile(); this.serviceInitComplete = false; @@ -40,12 +36,6 @@ public ComponentDetectionConfigFile GetComponentDetectionConfig() public async Task InitAsync(string explicitConfigPath, string rootDirectoryPath = null) { - await this.LoadFromEnvironmentVariableAsync(); - if (!string.IsNullOrEmpty(explicitConfigPath)) - { - await this.LoadComponentDetectionConfigAsync(explicitConfigPath); - } - if (!string.IsNullOrEmpty(rootDirectoryPath)) { await this.LoadComponentDetectionConfigFilesFromRootDirectoryAsync(rootDirectoryPath); @@ -65,18 +55,6 @@ private async Task LoadComponentDetectionConfigFilesFromRootDirectoryAsync(strin } } - private async Task LoadFromEnvironmentVariableAsync() - { - if (this.environmentVariableService.DoesEnvironmentVariableExist(ComponentDetectionConfigFileEnvVar)) - { - var possibleConfigFilePath = this.environmentVariableService.GetEnvironmentVariable(ComponentDetectionConfigFileEnvVar); - if (this.fileUtilityService.Exists(possibleConfigFilePath)) - { - await this.LoadComponentDetectionConfigAsync(possibleConfigFilePath); - } - } - } - private async Task LoadComponentDetectionConfigAsync(string configFile) { if (!this.fileUtilityService.Exists(configFile)) @@ -87,25 +65,9 @@ private async Task LoadComponentDetectionConfigAsync(string configFile) var configFileInfo = new FileInfo(configFile); var fileContents = await this.fileUtilityService.ReadAllTextAsync(configFileInfo); var newConfig = this.ParseComponentDetectionConfig(fileContents); - this.MergeComponentDetectionConfig(newConfig); this.logger.LogInformation("Loaded component detection config file from {ConfigFile}", configFile); } - /// - /// Merges two component detection configs, giving precedence to values already set in the first file. - /// - /// The new config file to be merged into the existing config set. - private void MergeComponentDetectionConfig(ComponentDetectionConfigFile newConfig) - { - foreach ((var name, var value) in newConfig.Variables) - { - if (!this.componentDetectionConfig.Variables.ContainsKey(name)) - { - this.componentDetectionConfig.Variables[name] = value; - } - } - } - /// /// Reads the component detection config from a file path. /// diff --git a/src/Microsoft.ComponentDetection.Orchestrator/Commands/BaseSettings.cs b/src/Microsoft.ComponentDetection.Orchestrator/Commands/BaseSettings.cs index 3b22fc207..eec348e92 100644 --- a/src/Microsoft.ComponentDetection.Orchestrator/Commands/BaseSettings.cs +++ b/src/Microsoft.ComponentDetection.Orchestrator/Commands/BaseSettings.cs @@ -37,10 +37,6 @@ public abstract class BaseSettings : CommandSettings [CommandOption("--Output")] public string Output { get; set; } - [Description("File path for a ComponentDetection.yml config file with more instructions for detection")] - [CommandOption("--ComponentDetectionConfigFile")] - public string ComponentDetectionConfigFile { get; set; } - /// public override ValidationResult Validate() { diff --git a/src/Microsoft.ComponentDetection.Orchestrator/Commands/ScanCommand.cs b/src/Microsoft.ComponentDetection.Orchestrator/Commands/ScanCommand.cs index 6b42c03bc..6fc2a35f7 100644 --- a/src/Microsoft.ComponentDetection.Orchestrator/Commands/ScanCommand.cs +++ b/src/Microsoft.ComponentDetection.Orchestrator/Commands/ScanCommand.cs @@ -44,7 +44,7 @@ public ScanCommand( public override async Task ExecuteAsync(CommandContext context, ScanSettings settings) { this.fileWritingService.Init(settings.Output); - await this.componentDetectionConfigFileService.InitAsync(settings.ComponentDetectionConfigFile, settings.SourceDirectory.FullName); + await this.componentDetectionConfigFileService.InitAsync(settings.SourceDirectory.FullName); var result = await this.scanExecutionService.ExecuteScanAsync(settings); this.WriteComponentManifest(settings, result); return 0;