Skip to content

Commit

Permalink
Identifer Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sumanth K B committed Nov 2, 2023
1 parent cd5a560 commit 0020eb2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
6 changes: 6 additions & 0 deletions src/LCT.Common/CommonHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public static bool IsAzureDevOpsDebugEnabled()
public static List<Component> RemoveExcludedComponents(List<Component> ComponentList, List<string> ExcludedComponents, ref int noOfExcludedComponents)
{
List<Component> ExcludedList = new List<Component>();

Logger.Debug($"RemoveExcludedComponents:<----Start---->:");

foreach (string excludedComponent in ExcludedComponents)
{
string[] excludedcomponent = excludedComponent.ToLower().Split(':');
Expand All @@ -49,12 +52,15 @@ public static List<Component> RemoveExcludedComponents(List<Component> 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;
}

Expand Down
31 changes: 22 additions & 9 deletions src/LCT.PackageIdentifier/DockerImageProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public Bom ParsePackageFile(CommonAppSettings appSettings)
List<Component> listComponentForBOM;
string componentsIdentifiedFromDockerImage = string.Empty;
string componentsTakenForProcessing = string.Empty;
List<DockerPackage> excludedComponents = new List<DockerPackage>();

configFiles = FolderScanner.FileScanner(appSettings.PackageFilePath, appSettings.Docker);

Expand All @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -117,14 +129,14 @@ public async Task<ComponentIdentification> IdentificationOfInternalComponents(Co

#region private methods

public List<DockerPackage> ParseCycloneDX(string filePath, ref Bom bom, string packageType, ref string componentsIdentifiedFromDockerImage)
public List<DockerPackage> ParseCycloneDX(string filePath, ref Bom bom, string packageType, ref string componentsIdentifiedFromDockerImage, List<DockerPackage> excludedComponents)
{
List<DockerPackage> dockerPackages = new List<DockerPackage>();
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<DockerPackage> dockerPackages, string packageType, ref string componentsIdentifiedFromDockerImage)
private Bom ExtractDetailsForJson(string filePath, ref List<DockerPackage> dockerPackages, string packageType, ref string componentsIdentifiedFromDockerImage, List<DockerPackage> excludedComponents)
{
Bom bom = cycloneDXBomParser.ParseCycloneDXBom(filePath);
List<string> differentComponents = new List<string>();
Expand All @@ -146,9 +158,9 @@ private Bom ExtractDetailsForJson(string filePath, ref List<DockerPackage> 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++;
Expand All @@ -159,6 +171,7 @@ private Bom ExtractDetailsForJson(string filePath, ref List<DockerPackage> docke
{
BomCreator.bomKpiData.ComponentsExcluded++;
Logger.Debug($"ExtractDetailsForJson():InvalidComponent : Component Details : {package.Name} @ {package.Version} @ {package.PurlID}");
excludedComponents.Add(package);
}
differentComponents.Add(GetProjectTypeFromPurlId(package.PurlID));
}
Expand Down

0 comments on commit 0020eb2

Please sign in to comment.