Skip to content

Commit 5e4d9cb

Browse files
authored
Merge pull request #257 from siemens/feature/DecouplingSW360andJfrogConnection
Modify the package identifier to make the JFROG and SW360 connections optional
2 parents 8fa536a + 93cb2ac commit 5e4d9cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1497
-188
lines changed

doc/UsageDoc/CA_UsageDocument.md

+3
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ Currently LTA support is not provided for SBOM, hence until that is implemented
9494

9595
- [NPM/NUGET/MAVEN/PYTHON/CONAN](../usagedocimg/packageIdentifiernpmnuget.PNG)
9696
- [Debian/Alpine](../usagedocimg/packageIdentifierdebianalpine.PNG)
97+
- [BasicSBOM](../usagedocimg/PackageidentifierBasicSBOMflowdiagram.png)
9798
- SW360 Package Creator
9899
- [NPM/NUGET/MAVEN/PYTHON/CONAN](../usagedocimg/packageCreatirnpmnuget.PNG)
99100
- [Debian](../usagedocimg/packagecreatordebian.PNG)
@@ -162,6 +163,8 @@ Currently LTA support is not provided for SBOM, hence until that is implemented
162163
> **1. Package Identifier**
163164
- Processes the input file and generates CycloneDX BOM file. The input file can be package file or a cycloneDx BOM file generated using the standard tool. If there are multiple input files, it can be processed by just passing the path to the directory in the argument
164165

166+
**Functionality Without Connections:**
167+
Provide users the flexibility to generate a basic SBOM even when connections to SW360, JFrog, or both are unavailable. The tool would support limited capabilities in such scenarios, ensuring essential SBOM generation functionality is maintained.
165168

166169
>**2. SW360 Package Creator**
167170
- Process the SBOM file(i.e., output of the first dll) and creates the missing components/releases in SW360 and links all the components to the project in the SW360 portal. This exe also triggers the upload of the components to Fossology and automatically updates the clearing state in SW360.
Loading

src/LCT.APICommunications.UTest/MavenJFrogApiCommunicationUTest.cs

+12
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,17 @@ public void MavenJfrogApiCommunication_GetApiKey_ReturnsInvalidOperationExceptio
6262
//Assert
6363
Assert.ThrowsAsync<InvalidOperationException>(async () => await jfrogApicommunication.GetApiKey());
6464
}
65+
[Test]
66+
public void MavenJfrogApiCommunication_MoveFromRepo_ReturnsInvalidOperationException()
67+
{
68+
//Arrange
69+
ArtifactoryCredentials repoCredentials = new ArtifactoryCredentials();
70+
71+
//Act
72+
JfrogApicommunication jfrogApicommunication = new MavenJfrogApiCommunication("", "", repoCredentials, 100);
73+
74+
//Assert
75+
Assert.ThrowsAsync<InvalidOperationException>(async () => await jfrogApicommunication.MoveFromRepo(new ComponentsToArtifactory()));
76+
}
6577
}
6678
}

src/LCT.APICommunications.UTest/SW360ApicommunicationUTest.cs

+8
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,15 @@ public void SW360Apicommunication_GetComponentDetailsByUrl_ReturnsInvalidOperati
263263
//Assert
264264
Assert.ThrowsAsync<InvalidOperationException>(async () => await sW360Apicommunication.GetComponentDetailsByUrl(""));
265265
}
266+
[Test]
267+
public void SW360Apicommunication_GetComponentByName_ReturnsInvalidOperationException()
268+
{
269+
//Arrange & Act
270+
SW360Apicommunication sW360Apicommunication = new SW360Apicommunication(connectionSettings);
266271

272+
//Assert
273+
Assert.ThrowsAsync<InvalidOperationException>(async () => await sW360Apicommunication.GetComponentByName(""));
274+
}
267275
[Test]
268276
public void SW360Apicommunication_UpdateComponent_ReturnsInvalidOperationException()
269277
{

src/LCT.Common.UTests/PipelineArtifactUploaderTest.cs

+20-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// SPDX-License-Identifier: MIT
55
// --------------------------------------------------------------------------------------------------------------------
66

7+
using log4net.Appender;
8+
using log4net.Config;
79
using NUnit.Framework;
810
using System;
911
using System.IO;
@@ -14,6 +16,7 @@ namespace LCT.Common.UTest
1416
public class PipelineArtifactUploaderTests
1517
{
1618
private StringWriter consoleOutput;
19+
private MemoryAppender memoryAppender;
1720

1821
[SetUp]
1922
public void SetUp()
@@ -58,13 +61,19 @@ public void UploadLogs_ShouldNotUpload_WhenInUnknownEnvironment()
5861
{
5962
// Arrange
6063
Environment.SetEnvironmentVariable("Build_BuildId", null); // No pipeline detected
61-
64+
memoryAppender = new MemoryAppender();
65+
BasicConfigurator.Configure(memoryAppender);
6266
// Act
6367
PipelineArtifactUploader.UploadLogs();
64-
string output = consoleOutput.ToString().Trim();
68+
69+
string expectedlogmessage = "Uploading of logs is not supported.";
70+
71+
var logEvents = memoryAppender.GetEvents();
6572

6673
// Assert
67-
Assert.AreNotEqual(output, "Uploading of SBOM is not supported.");
74+
Assert.IsNotEmpty(logEvents);
75+
var actualLogMessage = logEvents[0].RenderedMessage;
76+
Assert.AreEqual(expectedlogmessage, actualLogMessage);
6877
}
6978

7079
[Test]
@@ -91,13 +100,18 @@ public void UploadBom_ShouldNotUpload_WhenInUnknownEnvironment()
91100
{
92101
// Arrange
93102
Environment.SetEnvironmentVariable("Build_BuildId", null); // No pipeline detected
94-
103+
memoryAppender = new MemoryAppender();
104+
BasicConfigurator.Configure(memoryAppender);
95105
// Act
96106
PipelineArtifactUploader.UploadBom();
97-
string output = consoleOutput.ToString().Trim();
107+
string expectedlogmessage = "Uploading of SBOM is not supported.";
108+
109+
var logEvents = memoryAppender.GetEvents();
98110

99111
// Assert
100-
Assert.AreEqual(output, "Uploading of SBOM is not supported.");
112+
Assert.IsNotEmpty(logEvents);
113+
var actualLogMessage = logEvents[0].RenderedMessage;
114+
Assert.AreEqual(expectedlogmessage, actualLogMessage);
101115
}
102116
}
103117
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using Microsoft.VisualStudio.TestPlatform.Utilities;
2+
using NUnit.Framework;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.IO;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace LCT.Common.UTest
11+
{
12+
[TestFixture]
13+
public class TelemetryHelperTests
14+
{
15+
private TelemetryHelper telemetryHelper;
16+
private CommonAppSettings appSettings;
17+
private readonly StringWriter consoleOutput;
18+
[SetUp]
19+
public void Setup()
20+
{
21+
// Initialize real instances of your services
22+
appSettings = new CommonAppSettings
23+
{
24+
Telemetry=new Telemetry { ApplicationInsightInstrumentKey= "R1WvRUkY0I6Z" },
25+
SW360 = new SW360
26+
{
27+
ProjectName = "ProjectName",
28+
ProjectID = "ProjectID"
29+
},
30+
ProjectType = "ProjectType"
31+
};
32+
33+
// Initialize your telemetry service (this will be the class under test)
34+
telemetryHelper = new TelemetryHelper(appSettings);
35+
}
36+
[Test]
37+
public void StartTelemetry_ShouldInitializeAndTrackEvent_WhenTelemetryIsEnabled()
38+
{
39+
// Arrange
40+
string catoolVersion = "1.0.0";
41+
var kpiData = new { Metric1 = 100, Metric2 = 200 }; // Example KPI data
42+
string telemetryFor = "TestEvent";
43+
var consoleOutput = new System.IO.StringWriter();
44+
Console.SetOut(consoleOutput);
45+
// Act
46+
// This would normally start telemetry tracking in your system
47+
telemetryHelper.StartTelemetry(catoolVersion, kpiData, telemetryFor);
48+
49+
string output = consoleOutput.ToString();
50+
Assert.AreEqual(output, "");
51+
}
52+
}
53+
}

src/LCT.Common/CommonAppSettings.cs

+2-9
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,7 @@ public string URL
115115
}
116116
set
117117
{
118-
if (string.IsNullOrEmpty(value))
119-
{
120-
throw new ArgumentNullException($"Provide a sw360 url - {value}");
121-
}
122-
else
118+
if (!string.IsNullOrEmpty(value))
123119
{
124120
m_URL = value.TrimEnd(Dataconstant.ForwardSlash);
125121
}
@@ -133,7 +129,6 @@ public string ProjectName
133129
}
134130
set
135131
{
136-
CommonHelper.CheckNullOrEmpty(nameof(ProjectName), value);
137132
m_ProjectName = value;
138133
}
139134
}
@@ -145,7 +140,6 @@ public string ProjectID
145140
}
146141
set
147142
{
148-
CommonHelper.CheckNullOrEmpty(nameof(ProjectID), value);
149143
m_ProjectID = value;
150144
}
151145
}
@@ -157,8 +151,7 @@ public string Token
157151
return m_Token;
158152
}
159153
set
160-
{
161-
CommonHelper.CheckNullOrEmpty(nameof(Token), value);
154+
{
162155
m_Token = value;
163156
}
164157
}

src/LCT.Common/CommonHelper.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public static void WriteToConsoleTable(Dictionary<string, int> printData, Dictio
117117
Logger.Info("Summary :\n");
118118
if (!string.IsNullOrWhiteSpace(ProjectSummaryLink)) { Logger.Info($"{ProjectSummaryLink}"); }
119119
Logger.Info($"{"=",5}{string.Join("", Enumerable.Repeat("=", 88)),5}");
120-
Logger.Info($"{"|",5}{Feature,70} {"|",5} {Count,5} {"|",5}");
120+
Logger.Info($"{"|",5}{Feature,-70} {"|",5} {Count,5} {"|",5}");
121121
Logger.Info($"{"=",5}{string.Join("", Enumerable.Repeat("=", 88)),5}");
122122
foreach (var item in printData)
123123
{
@@ -253,8 +253,6 @@ public static string AddSpecificValuesToBOMFormat(Bom listOfComponentsToBom)
253253

254254
return formattedString;
255255
}
256-
257-
258256
public static string[] GetRepoList(CommonAppSettings appSettings)
259257
{
260258
var projectTypeMappings = new Dictionary<string, Func<Artifactory>>

src/LCT.Common/Constants/FileConstant.cs

+1
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,6 @@ public static class FileConstant
5353
public const string NugetAssetFile = "project.assets.json";
5454
public const string multipleversionsFileName = "Multipleversions.json";
5555
public const string artifactoryReportNotApproved = "ReportNotApproved.json";
56+
public const string basicSBOMName = "ContinuousClearing";
5657
}
5758
}

src/LCT.Common/SettingsManager.cs

+17-8
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public T ReadConfiguration<T>(string[] args, string jsonSettingsFileName)
4242
if (args?.Length == 0)
4343
{
4444
Logger.Debug($"Argument Count : {args.Length}");
45-
DisplayHelp();
45+
DisplayHelp();
4646
environmentHelper.CallEnvironmentExit(0);
4747
}
4848
string settingsFilePath = GetConfigFilePathFromArgs(args, jsonSettingsFileName);
@@ -122,19 +122,28 @@ public void CheckRequiredArgsToRun(CommonAppSettings appSettings, string current
122122
//Required parameters to run Package Identifier
123123
List<string> identifierReqParameters = new List<string>()
124124
{
125-
"SW360.ProjectID",
126-
"SW360.Token",
127-
"Jfrog.Token",
128-
"SW360.URL",
129-
"Jfrog.URL",
130125
"Directory.InputFolder",
131126
"Directory.OutputFolder",
132127
"ProjectType"
133128
};
129+
130+
if (appSettings.SW360 != null)
131+
{
132+
identifierReqParameters.Add($"SW360.ProjectID");
133+
identifierReqParameters.Add($"SW360.Token");
134+
identifierReqParameters.Add($"SW360.URL");
135+
}
136+
if (appSettings.Jfrog != null)
137+
{
138+
identifierReqParameters.Add($"Jfrog.Token");
139+
identifierReqParameters.Add($"Jfrog.URL");
140+
}
141+
142+
134143
//Check if ProjectType contains a value and add InternalRepos key accordingly
135144
if (!string.IsNullOrWhiteSpace(appSettings.ProjectType))
136145
{
137-
if (!appSettings.ProjectType.Equals("ALPINE", StringComparison.InvariantCultureIgnoreCase))
146+
if (appSettings.Jfrog != null && !appSettings.ProjectType.Equals("ALPINE", StringComparison.InvariantCultureIgnoreCase))
138147
{
139148
identifierReqParameters.Add($"{appSettings.ProjectType}.Artifactory.InternalRepos");
140149
}
@@ -212,7 +221,7 @@ private static void CheckForMissingParameter(CommonAppSettings appSettings, Prop
212221
}
213222

214223
if (!string.IsNullOrWhiteSpace(missingParameters.ToString()))
215-
{
224+
{
216225
ExceptionHandling.ArgumentException(missingParameters.ToString());
217226
environmentHelper.CallEnvironmentExit(-1);
218227
}

src/LCT.Common/appSettings.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
// --------------------------------------------------------------------------------------------------------------------
66

77
{
8-
"TimeOut": 400,
8+
"TimeOut": 400,
99
"ProjectType": "<Insert ProjectType>",
1010
"MultipleProjectType": false,
1111
"Telemetry": {
12-
"Enable": true,
12+
"Enable": false,
1313
"ApplicationInsightInstrumentKey": "" //From Application Insight to enable Telemetry
1414
},
1515
"SW360": {

src/LCT.PackageIdentifier.UTest/CommonIdentiferHelperTests.cs

+64
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
using LCT.APICommunications.Model.AQL;
99
using System.Collections.Generic;
1010
using LCT.PackageIdentifier;
11+
using LCT.Common.Constants;
12+
using LCT.Common;
1113

1214
namespace LCT.PackageIdentifier.UTest
1315
{
@@ -66,5 +68,67 @@ public void GetRepodetailsFromPerticularOrder_NoSpecificRepo_ReturnsFirstRepo()
6668
var result = CommonIdentiferHelper.GetRepodetailsFromPerticularOrder(aqlResults);
6769
Assert.AreEqual("generic-repo", result);
6870
}
71+
[Test]
72+
public void GetBomFileName_WhenBasicSBOMIsFalse_ReturnsProjectNameBomFileName()
73+
{
74+
// Arrange
75+
var appSettings = new CommonAppSettings
76+
{
77+
SW360=new SW360() { ProjectName= "TestProject" }
78+
};
79+
80+
// Act
81+
string result = CommonIdentiferHelper.GetBomFileName(appSettings);
82+
83+
// Assert
84+
Assert.AreEqual("TestProject_Bom.cdx.json", result);
85+
}
86+
87+
[Test]
88+
public void GetBomFileName_WhenBasicSBOMIsTrue_ReturnsBasicSBOMNameBomFileName()
89+
{
90+
// Arrange
91+
var appSettings = new CommonAppSettings
92+
{
93+
94+
};
95+
96+
// Act
97+
string result = CommonIdentiferHelper.GetBomFileName(appSettings);
98+
99+
// Assert
100+
Assert.AreEqual(FileConstant.basicSBOMName, result);
101+
}
102+
103+
[Test]
104+
public void GetDefaultProjectName_WhenBasicSBOMIsFalse_ReturnsProjectName()
105+
{
106+
// Arrange
107+
var appSettings = new CommonAppSettings
108+
{
109+
SW360 = new SW360() { ProjectName = "TestProject" }
110+
};
111+
112+
// Act
113+
string result = CommonIdentiferHelper.GetDefaultProjectName(appSettings);
114+
115+
// Assert
116+
Assert.AreEqual("TestProject", result);
117+
}
118+
119+
[Test]
120+
public void GetDefaultProjectName_WhenBasicSBOMIsTrue_ReturnsBasicSBOMName()
121+
{
122+
// Arrange
123+
var appSettings = new CommonAppSettings
124+
{
125+
};
126+
127+
// Act
128+
string result = CommonIdentiferHelper.GetDefaultProjectName(appSettings);
129+
130+
// Assert
131+
Assert.AreEqual(FileConstant.basicSBOMName, result);
132+
}
69133
}
70134
}

0 commit comments

Comments
 (0)