Skip to content

Commit

Permalink
Revert "Fossology url validation"
Browse files Browse the repository at this point in the history
This reverts commit 5b7a52f.
  • Loading branch information
ragavareddychalapala committed Feb 3, 2025
1 parent 5b7a52f commit 2b81af8
Show file tree
Hide file tree
Showing 17 changed files with 5 additions and 279 deletions.
63 changes: 2 additions & 61 deletions src/LCT.SW360PackageCreator.UTest/CreatorValidatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,16 @@
using LCT.Common;
using System.Threading.Tasks;
using LCT.APICommunications.Model;
using LCT.APICommunications.Model.Foss;
using Newtonsoft.Json;
using System.Net.Http;
using LCT.Facade.Interfaces;

namespace LCT.SW360PackageCreator.UTest
{
[TestFixture]
public class CreatorValidatorTest
{
public Mock<ISw360ProjectService> mockISw360ProjectService;
public Mock<ISW360ApicommunicationFacade> mockISW360ApicommunicationFacade;
public Mock<ISW360CommonService> mockISW360CommonService;
public Mock<ISw360CreatorService> mockISw360CreatorService;
public Mock<ISW360Service> mockISW360Service;
public Mock<ISw360ProjectService> mockISw360ProjectService;
public CreatorValidatorTest()
{
mockISw360ProjectService = new Mock<ISw360ProjectService>(MockBehavior.Strict);
mockISW360ApicommunicationFacade = new Mock<ISW360ApicommunicationFacade>(MockBehavior.Strict);
mockISW360CommonService = new Mock<ISW360CommonService>(MockBehavior.Strict);
mockISw360CreatorService = new Mock<ISw360CreatorService>(MockBehavior.Strict);
mockISW360Service = new Mock<ISW360Service>(MockBehavior.Strict);
mockISw360ProjectService = new Mock<ISw360ProjectService>(MockBehavior.Strict);

}
[TestCase]
Expand Down Expand Up @@ -105,53 +93,6 @@ public void ValidateAppSettings_TestNegative()
Assert.ThrowsAsync<InvalidDataException>(() => CreatorValidator.ValidateAppSettings(CommonAppSettings, mockISw360ProjectService.Object, projectReleases));

}
[TestCase]
public async Task TriggerFossologyValidation_TestPositive()
{
// Arrange
var appSettings = new CommonAppSettings()
{
SW360 = new SW360()
{
URL = "https://sw360.example.com"
}
};

var responseBody = "{\"_embedded\":{\"sw360:releases\":[{\"_links\":{\"self\":{\"href\":\"https://sw360.example.com/resource/api/releases/123\"}}}]}}";
var releasesInfo = new ReleasesInfo
{
Name = "TestRelease",
Version = "1.0",
ClearingState = "APPROVED"
};
var fossTriggerStatus = new FossTriggerStatus
{
Links = new Links
{
Self = new Self
{
Href = "https://fossology.example.com"
}
}
};
var triggerStatusResponse = JsonConvert.SerializeObject(fossTriggerStatus);

mockISW360ApicommunicationFacade.Setup(x => x.GetReleases()).ReturnsAsync(responseBody);
mockISW360Service.Setup(x => x.GetReleaseDataOfComponent(It.IsAny<string>())).ReturnsAsync(releasesInfo);
mockISw360CreatorService.Setup(x => x.TriggerFossologyProcessForValidation(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(fossTriggerStatus);
mockISW360ApicommunicationFacade.Setup(x => x.GetReleaseById(It.IsAny<string>())).ReturnsAsync(new HttpResponseMessage
{
Content = new StringContent("{\"Name\":\"TestRelease\",\"Version\":\"1.0\",\"ClearingState\":\"APPROVED\"}")
});
mockISW360ApicommunicationFacade.Setup(x => x.TriggerFossologyProcess(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(triggerStatusResponse);

// Act
await CreatorValidator.TriggerFossologyValidation(appSettings, mockISW360ApicommunicationFacade.Object);

// Assert
mockISW360ApicommunicationFacade.Verify(x => x.GetReleases(), Times.Once);
mockISW360ApicommunicationFacade.Verify(x => x.TriggerFossologyProcess(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
}

}
}
89 changes: 0 additions & 89 deletions src/LCT.SW360PackageCreator/CreatorValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@
using LCT.APICommunications.Model;
using log4net;
using System.Reflection;
using LCT.APICommunications.Model.Foss;
using LCT.APICommunications;
using LCT.Facade.Interfaces;
using LCT.Services;
using log4net.Core;
using Newtonsoft.Json;
using System;
using LCT.Common.Interface;


namespace LCT.SW360PackageCreator
Expand All @@ -29,7 +21,6 @@ namespace LCT.SW360PackageCreator
public static class CreatorValidator
{
static readonly ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static IEnvironmentHelper environmentHelper;
public static async Task<int> ValidateAppSettings(CommonAppSettings appSettings, ISw360ProjectService sw360ProjectService, ProjectReleases projectReleases)
{
string sw360ProjectName = await sw360ProjectService.GetProjectNameByProjectIDFromSW360(appSettings.SW360.ProjectID, appSettings.SW360.ProjectName,projectReleases);
Expand All @@ -50,85 +41,5 @@ public static async Task<int> ValidateAppSettings(CommonAppSettings appSettings,
}
return 0;
}

public static async Task TriggerFossologyValidation(CommonAppSettings appSettings, ISW360ApicommunicationFacade sW360ApicommunicationFacade)
{
IEnvironmentHelper environmentHelper = new EnvironmentHelper();
ISW360CommonService sw360CommonService = new SW360CommonService(sW360ApicommunicationFacade);
ISw360CreatorService sw360CreatorService = new Sw360CreatorService(sW360ApicommunicationFacade, sw360CommonService);
ISW360Service sw360Service = new Sw360Service(sW360ApicommunicationFacade, sw360CommonService,environmentHelper);
ReleasesInfo releasesInfo = new ReleasesInfo();

try
{

string responseBody = await sW360ApicommunicationFacade.GetReleases();
var modelMappedObject = JsonConvert.DeserializeObject<ComponentsRelease>(responseBody);
var releaseId = string.Empty;
if (modelMappedObject != null && modelMappedObject.Embedded?.Sw360Releases?.Count > 0)
{
foreach (var ReleaseidList in modelMappedObject.Embedded?.Sw360Releases)
{
var releaseUrl = ReleaseidList.Links?.Self?.Href;

releasesInfo = await CallApiAsync(releaseUrl, sw360Service);
if (releasesInfo != null)
{
releaseId = CommonHelper.GetSubstringOfLastOccurance(releaseUrl, "/");
break;
}
}

}
else
{
Logger.Debug($"TriggerFossologyValidation():Trigger Fossology Process validation failed");
Logger.Error($"Trigger Fossology Process validation failed");
environmentHelper.CallEnvironmentExit(-1);
}
if (releasesInfo != null)
{
string sw360link = $"{releasesInfo.Name}:{releasesInfo.Version}:{appSettings.SW360.URL}{ApiConstant.Sw360ReleaseUrlApiSuffix}" +
$"{releaseId}#/tab-Summary";
FossTriggerStatus fossResult = await sw360CreatorService.TriggerFossologyProcessForValidation(releaseId, sw360link);
if (!string.IsNullOrEmpty(fossResult?.Links?.Self?.Href))
{
Logger.Logger.Log(null, Level.Info, $"SW360 Fossology Process validation successfull!!", null);
}
}

}
catch (AggregateException ex)
{
Logger.Debug($"\tError in TriggerFossologyProcess--{ex}");
Logger.Error($"Trigger Fossology Process failed.Please check fossology configuration in sw360");
environmentHelper.CallEnvironmentExit(-1);
}
}

private static async Task<ReleasesInfo> CallApiAsync(string endpoint, ISW360Service sw360Service)
{
try
{
ReleasesInfo releasesInfo = await sw360Service.GetReleaseDataOfComponent(endpoint);


var clearingState = releasesInfo.ClearingState?.ToString();


if (clearingState == "APPROVED")
{
// Return the result if the clearingState is "approved"
return releasesInfo;
}
}
catch (Exception ex)
{
Logger.Debug($"CallApiAsync():{ex}");
}


return null;
}
}
}
76 changes: 2 additions & 74 deletions src/LCT.SW360PackageCreator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Net.Http;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
Expand Down Expand Up @@ -88,85 +87,14 @@ static async Task Main(string[] args)

if (appSettings.IsTestMode)
Logger.Logger.Log(null, Level.Notice, $"\tMode\t\t\t --> {appSettings.Mode}\n", null);
//Validate Fossology Url
if (appSettings.SW360.Fossology.EnableTrigger)
{
if(await FossologyUrlValidation(appSettings))
await CreatorValidator.TriggerFossologyValidation(appSettings, sW360ApicommunicationFacade);
}

await InitiatePackageCreatorProcess(appSettings, sw360ProjectService, sW360ApicommunicationFacade);

Logger.Logger.Log(null, Level.Notice, $"End of Package Creator execution: {DateTime.Now}\n", null);

// publish logs and bom file to pipeline artifact
PipelineArtifactUploader.UploadArtifacts();
}
public static async Task<bool> FossologyUrlValidation(CommonAppSettings appSettings)
{

string url = appSettings.SW360.Fossology.URL.ToLower();
string prodFossUrl = "automation.fossology".ToLower();
string stageFossUrl = "stage.fossology".ToLower();
environmentHelper = new EnvironmentHelper();

if (string.IsNullOrEmpty(appSettings.SW360.Fossology.URL))
{

Logger.Error($"Fossology URL is not provided ,Please make sure to add Fossologyurl in appsettings..");
Logger.Debug($"Fossologyurlcheck() : Fossology url not provided in appsettings");
environmentHelper.CallEnvironmentExit(-1);

}
else if (Uri.IsWellFormedUriString(appSettings.SW360.Fossology.URL, UriKind.Absolute))
{
if (url.Contains(prodFossUrl) || url.Contains(stageFossUrl))
{
// Send GET request to validate Fossology URL
using (HttpClient client = new HttpClient())
{
try
{
HttpResponseMessage response = await client.GetAsync(new Uri(appSettings.SW360.Fossology.URL));
if (response.IsSuccessStatusCode)
{
// Fossology URL is valid
return true;
}
else
{
// Fossology URL is not valid
Logger.Error($"Fossology URL is not valid ,Please make sure to add valid fossologyurl in appsettings..");
Logger.Debug($"Fossologyurlcheck() : Fossology URL is not valid.");
environmentHelper.CallEnvironmentExit(-1);
}
}
catch (HttpRequestException ex)
{
// Fossology URL is not valid
Logger.Error($"Fossology URL is not working ,Please check once try again....");
Logger.Debug($"Fossologyurlcheck() : Fossology URL is not valid.{ex}");
environmentHelper.CallEnvironmentExit(-1);
}

}
}
else
{
Logger.Debug($"Fossologyurlcheck() : Fossology URL is not valid");
Logger.Error($"Fossology URL is not valid ,Please check once try again....");
environmentHelper.CallEnvironmentExit(-1);
}
}
else
{
Logger.Error($"Fossology URL is not provided ,Please make sure to add fossologyurl in appsettings..");
Logger.Debug($"Fossologyurlcheck() : Fossology url not provided in appsettings");
environmentHelper.CallEnvironmentExit(-1);
}


return false;
}

private static CatoolInfo GetCatoolVersionFromProjectfile()
{
Expand Down Expand Up @@ -245,6 +173,6 @@ private static string InitiateLogger(CommonAppSettings appSettings)
}

return FolderPath;
}
}
}
}
1 change: 0 additions & 1 deletion src/LCT.Services/Interface/ISW360CreatorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Task<ReleaseCreateStatus> CreateReleaseForComponent(
Task<string> GetReleaseIDofComponent(string componentName, string componentVersion, string componentid);

Task<FossTriggerStatus> TriggerFossologyProcess(string releaseId,string sw360link);
Task<FossTriggerStatus> TriggerFossologyProcessForValidation(string releaseId, string sw360link);

Task<CheckFossologyProcess> CheckFossologyProcessStatus(string link);

Expand Down
41 changes: 0 additions & 41 deletions src/LCT.Services/Sw360CreatorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using LCT.APICommunications.Model.Foss;
using LCT.Common;
using LCT.Common.Constants;
using LCT.Common.Interface;
using LCT.Common.Model;
using LCT.Facade.Interfaces;
using LCT.Services.Interface;
Expand Down Expand Up @@ -39,7 +38,6 @@ public class Sw360CreatorService : ISw360CreatorService
static readonly ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
readonly ISW360ApicommunicationFacade m_SW360ApiCommunicationFacade;
readonly ISW360CommonService m_SW360CommonService;
private static IEnvironmentHelper environmentHelper;

public Sw360CreatorService(ISW360ApicommunicationFacade sw360ApiCommunicationFacade)
{
Expand Down Expand Up @@ -145,45 +143,6 @@ public async Task<CheckFossologyProcess> CheckFossologyProcessStatus(string link
}
return fossTriggerStatus;

}
public async Task<FossTriggerStatus> TriggerFossologyProcessForValidation(string releaseId, string sw360link)
{
environmentHelper = new EnvironmentHelper();
FossTriggerStatus fossTriggerStatus = null;
try
{
string triggerStatus = await m_SW360ApiCommunicationFacade.TriggerFossologyProcess(releaseId, sw360link);
fossTriggerStatus = JsonConvert.DeserializeObject<FossTriggerStatus>(triggerStatus);
}
catch (HttpRequestException ex)
{
Logger.Debug($"TriggerFossologyProcessForValidation():", ex);
Logger.Error($"Fossology Process failed.Please check fossology configuration or Token in sw360");
environmentHelper.CallEnvironmentExit(-1);

}
catch (InvalidOperationException ex)
{
Logger.Debug($"TriggerFossologyProcessForValidation():", ex);
Logger.Error($"Fossology Process failed.Please check fossology configuration in sw360");
environmentHelper.CallEnvironmentExit(-1);
}
catch (UriFormatException ex)
{
Logger.Debug($"TriggerFossologyProcessForValidation():", ex);
Logger.Error($"Fossology Process failed.Please check fossology configuration in sw360");
environmentHelper.CallEnvironmentExit(-1);

}
catch (TaskCanceledException ex)
{
Logger.Debug($"TriggerFossologyProcessForValidation():", ex);
Logger.Error($"Fossology Process failed.Please check fossology configuration in sw360");
environmentHelper.CallEnvironmentExit(-1);

}
return fossTriggerStatus;

}
public async Task<ReleaseCreateStatus> CreateReleaseForComponent(ComparisonBomData componentInfo, string componentId,
Dictionary<string, string> attachmentUrlList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public void ComponentCreatorExe_ProvidedBOMFilePath_ReturnsSuccess()
TestConstant.SW360ProjectID, testParameters.SW360ProjectID,
TestConstant.SW360ProjectName, testParameters.SW360ProjectName,
TestConstant.ProjectType,"ALPINE",
TestConstant.FossologyURL, testParameters.FossUrl,
TestConstant.Mode,""}),
"Test to run component creator EXE execution");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public void TestComponentCreatorExe_Conan()
TestConstant.SW360AuthTokenType, testParameters.SW360AuthTokenType,
TestConstant.SW360ProjectID, testParameters.SW360ProjectID,
TestConstant.SW360ProjectName, testParameters.SW360ProjectName,
TestConstant.FossologyURL, testParameters.FossUrl,
TestConstant.Mode,""
}),
"Test to run Package Creator EXE execution");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public void ComponentCreatorExe_ProvidedBOMFilePath_ReturnsSuccess()
TestConstant.SW360ProjectID, testParameters.SW360ProjectID,
TestConstant.SW360ProjectName, testParameters.SW360ProjectName,
TestConstant.ProjectType,"DEBIAN",
TestConstant.FossologyURL, testParameters.FossUrl,
TestConstant.Mode,""}),
"Test to run component creator EXE execution");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public void ComponentCreatorExe_ProvidedBOMFilePath_ReturnsSuccess()
TestConstant.SW360AuthTokenType, testParameters.SW360AuthTokenType,
TestConstant.SW360ProjectID, testParameters.SW360ProjectID,
TestConstant.SW360ProjectName, testParameters.SW360ProjectName,
TestConstant.FossologyURL, testParameters.FossUrl,
TestConstant.Mode,""}),
"Test to run Package Creator EXE execution");
}
Expand Down
Loading

0 comments on commit 2b81af8

Please sign in to comment.