From 0020eb2455571da035cf103c879c522ff980baa0 Mon Sep 17 00:00:00 2001 From: Sumanth K B Date: Thu, 2 Nov 2023 17:04:10 +0530 Subject: [PATCH] Identifer Changes --- src/LCT.Common/CommonHelper.cs | 6 ++++ .../DockerImageProcessor.cs | 31 +++++++++++++------ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/LCT.Common/CommonHelper.cs b/src/LCT.Common/CommonHelper.cs index 55162fe5..874c03c9 100644 --- a/src/LCT.Common/CommonHelper.cs +++ b/src/LCT.Common/CommonHelper.cs @@ -36,6 +36,9 @@ public static bool IsAzureDevOpsDebugEnabled() public static List RemoveExcludedComponents(List ComponentList, List ExcludedComponents, ref int noOfExcludedComponents) { List ExcludedList = new List(); + + Logger.Debug($"RemoveExcludedComponents:<----Start---->:"); + foreach (string excludedComponent in ExcludedComponents) { string[] excludedcomponent = excludedComponent.ToLower().Split(':'); @@ -49,12 +52,15 @@ public static List RemoveExcludedComponents(List Component if (name.ToLowerInvariant() == excludedcomponent[0].ToLowerInvariant() && excludedcomponent.Length > 0 && (component.Version.ToLowerInvariant() == excludedcomponent[1].ToLowerInvariant() || excludedcomponent[1].ToLowerInvariant() == "*")) { + Logger.Debug($"Removed : " + name + " -- " + component.Version); noOfExcludedComponents++; ExcludedList.Add(component); } } } ComponentList.RemoveAll(item => ExcludedList.Contains(item)); + + Logger.Debug($"RemoveExcludedComponents:<----End---->:"); return ComponentList; } diff --git a/src/LCT.PackageIdentifier/DockerImageProcessor.cs b/src/LCT.PackageIdentifier/DockerImageProcessor.cs index 80aaf9e8..99fa4911 100644 --- a/src/LCT.PackageIdentifier/DockerImageProcessor.cs +++ b/src/LCT.PackageIdentifier/DockerImageProcessor.cs @@ -44,6 +44,7 @@ public Bom ParsePackageFile(CommonAppSettings appSettings) List listComponentForBOM; string componentsIdentifiedFromDockerImage = string.Empty; string componentsTakenForProcessing = string.Empty; + List excludedComponents = new List(); configFiles = FolderScanner.FileScanner(appSettings.PackageFilePath, appSettings.Docker); @@ -52,14 +53,11 @@ public Bom ParsePackageFile(CommonAppSettings appSettings) if (!filepath.EndsWith(FileConstant.SBOMTemplateFileExtension)) { Logger.Debug($"ParsePackageFile():FileName: " + filepath); - var list = ParseCycloneDX(filepath, ref bom, appSettings.ProjectType, ref componentsIdentifiedFromDockerImage); + var list = ParseCycloneDX(filepath, ref bom, appSettings.ProjectType, ref componentsIdentifiedFromDockerImage, excludedComponents); listofComponents.AddRange(list); } } - Logger.Logger.Log(null, Level.Notice, "Packages found in docker image.." + componentsIdentifiedFromDockerImage, null); - Logger.Logger.Log(null, Level.Notice, "Packages taken for clearing.." + componentsTakenForProcessing, null); - int initialCount = listofComponents.Count; GetDistinctComponentList(ref listofComponents); listComponentForBOM = FormComponentReleaseExternalID(listofComponents); @@ -75,6 +73,20 @@ public Bom ParsePackageFile(CommonAppSettings appSettings) SbomTemplate.AddComponentDetails(bom.Components, templateDetails); } + Logger.Logger.Log(null, Level.Notice, "Packages found in docker image.." + componentsIdentifiedFromDockerImage, null); + Logger.Logger.Log(null, Level.Notice, "Packages taken for clearing.." + componentsTakenForProcessing, null); + + if(excludedComponents.Count > 0) + { + Logger.Logger.Log(null, Level.Warn + , "Packages excluded from clearing ", null); + } + foreach (var package in excludedComponents) + { + Logger.Logger.Log(null, Level.Warn + , "" + package.Name + "--" + package.Version, null); + } + bom = RemoveExcludedComponents(appSettings, bom); return bom; } @@ -117,14 +129,14 @@ public async Task IdentificationOfInternalComponents(Co #region private methods - public List ParseCycloneDX(string filePath, ref Bom bom, string packageType, ref string componentsIdentifiedFromDockerImage) + public List ParseCycloneDX(string filePath, ref Bom bom, string packageType, ref string componentsIdentifiedFromDockerImage, List excludedComponents) { List dockerPackages = new List(); - bom = ExtractDetailsForJson(filePath, ref dockerPackages, packageType, ref componentsIdentifiedFromDockerImage); + bom = ExtractDetailsForJson(filePath, ref dockerPackages, packageType, ref componentsIdentifiedFromDockerImage, excludedComponents); return dockerPackages; } - private Bom ExtractDetailsForJson(string filePath, ref List dockerPackages, string packageType, ref string componentsIdentifiedFromDockerImage) + private Bom ExtractDetailsForJson(string filePath, ref List dockerPackages, string packageType, ref string componentsIdentifiedFromDockerImage, List excludedComponents) { Bom bom = cycloneDXBomParser.ParseCycloneDXBom(filePath); List differentComponents = new List(); @@ -146,9 +158,9 @@ private Bom ExtractDetailsForJson(string filePath, ref List docke dockerPackages.Add(package); Logger.Debug($"ExtractDetailsForJson():ValidComponent for PackageType : " + packageType + " : Component Details : {package.Name} @ {package.Version} @ {package.PurlID}"); } - else if (!string.IsNullOrEmpty(componentsInfo.Name?.Trim()) && !string.IsNullOrEmpty(componentsInfo.Version?.Trim()) + else if (!string.IsNullOrEmpty(componentsInfo.Name?.Trim()) && !string.IsNullOrEmpty(componentsInfo.Version?.Trim()) && !string.IsNullOrEmpty(componentsInfo.Purl?.Trim()) - && packageType.ToUpper() == "DOCKER" && + && packageType.ToUpper() == "DOCKER" && Dataconstant.PurlCheck()["DOCKER"].Split(',').ToList().Exists(val => componentsInfo.Purl.Contains(val))) { BomCreator.bomKpiData.DockerComponents++; @@ -159,6 +171,7 @@ private Bom ExtractDetailsForJson(string filePath, ref List docke { BomCreator.bomKpiData.ComponentsExcluded++; Logger.Debug($"ExtractDetailsForJson():InvalidComponent : Component Details : {package.Name} @ {package.Version} @ {package.PurlID}"); + excludedComponents.Add(package); } differentComponents.Add(GetProjectTypeFromPurlId(package.PurlID)); }