diff --git a/src/ArtifactoryUploader/PackageUploadHelper.cs b/src/ArtifactoryUploader/PackageUploadHelper.cs index 7adbe621..d5f4de6a 100644 --- a/src/ArtifactoryUploader/PackageUploadHelper.cs +++ b/src/ArtifactoryUploader/PackageUploadHelper.cs @@ -73,7 +73,7 @@ public async static Task> GetComponentsToBeUploade { if (item.Properties.Exists(p => p.Name == Dataconstant.Cdx_ClearingState && p.Value.ToUpperInvariant() == "APPROVED")) { - AqlResult aqlResult = await GetSrcRepoDetailsForPyPiPackages(item, appSettings); + AqlResult aqlResult = await GetSrcRepoDetailsForPyPiOrConanPackages(item, appSettings); ComponentsToArtifactory components = new ComponentsToArtifactory() { Name = !string.IsNullOrEmpty(item.Group) ? $"{item.Group}/{item.Name}" : item.Name, @@ -86,6 +86,7 @@ public async static Task> GetComponentsToBeUploade Email = appSettings.ArtifactoryUploadUser, JfrogApi = appSettings.JFrogApi, SrcRepoPathWithFullName = aqlResult != null ? aqlResult.Repo + "/" + aqlResult.Path + "/" + aqlResult.Name : string.Empty, + Path = aqlResult != null ? GetConanPath(aqlResult.Path, $"{item.Name}/{item.Version}") : string.Empty, PypiCompName = aqlResult != null ? aqlResult.Name : string.Empty }; components.PackageInfoApiUrl = GetPackageInfoURL(components); @@ -126,6 +127,11 @@ private static string GetCopyURL(ComponentsToArtifactory component) url = $"{component.JfrogApi}{ApiConstant.CopyPackageApi}{component.SrcRepoPathWithFullName}" + $"?to=/{component.DestRepoName}/{component.PypiCompName}"; } + else if (component.ComponentType == "CONAN") + { + url = $"{component.JfrogApi}{ApiConstant.CopyPackageApi}{component.SrcRepoName}/{component.Path}" + + $"?to=/{component.DestRepoName}/{component.Path}"; + } else { // Do nothing @@ -133,6 +139,20 @@ private static string GetCopyURL(ComponentsToArtifactory component) return url; } + private static string GetConanPath(string path, string package) + { + //// Get Path only till PackageName/Version so that everything in folder can be copied + if (path.Contains(package)) + { + int index = path.IndexOf(package); + return path.Substring(0, index + package.Length); + } + else + { + return path; + } + } + private static string GetPackageInfoURL(ComponentsToArtifactory component) { string url = string.Empty; @@ -152,6 +172,10 @@ private static string GetPackageInfoURL(ComponentsToArtifactory component) { url = $"{component.JfrogApi}{ApiConstant.PackageInfoApi}{component.SrcRepoPathWithFullName}"; } + else if (component.ComponentType == "CONAN") + { + url = $"{component.JfrogApi}{ApiConstant.PackageInfoApi}{component.SrcRepoName}/{component.Path}"; + } else { // Do nothing @@ -177,16 +201,20 @@ private static string GetDestinationRepo(Component item, CommonAppSettings appSe { return appSettings.JfrogPythonDestRepoName; } + else if (item.Purl.Contains("conan", StringComparison.OrdinalIgnoreCase)) + { + return appSettings.JfrogConanDestRepoName; + } else { // Do nothing } + return string.Empty; } private static string GetComponentType(Component item) { - if (item.Purl.Contains("npm", StringComparison.OrdinalIgnoreCase)) { return "NPM"; @@ -203,6 +231,10 @@ private static string GetComponentType(Component item) { return "PYTHON"; } + else if (item.Purl.Contains("conan", StringComparison.OrdinalIgnoreCase)) + { + return "CONAN"; + } else { // Do nothing @@ -210,19 +242,28 @@ private static string GetComponentType(Component item) return string.Empty; } - private async static Task GetSrcRepoDetailsForPyPiPackages(Component item, CommonAppSettings appSettings) + private async static Task GetSrcRepoDetailsForPyPiOrConanPackages(Component item, CommonAppSettings appSettings) { if (item.Purl.Contains("pypi", StringComparison.OrdinalIgnoreCase) && aqlResultList.Count == 0) { // get the component list from Jfrog for given repo aqlResultList = await GetListOfComponentsFromRepo(appSettings.Python?.JfrogPythonRepoList, jFrogService); - } - if (aqlResultList.Count > 0) - { - return GetArtifactoryRepoName(aqlResultList, item); + if (aqlResultList.Count > 0) + { + return GetArtifactoryRepoName(aqlResultList, item); + } } + else if (item.Purl.Contains("conan", StringComparison.OrdinalIgnoreCase)) + { + var aqlConanResultList = await GetListOfComponentsFromRepo(appSettings.Conan?.JfrogConanRepoList, jFrogService); + if (aqlConanResultList.Count > 0) + { + return GetArtifactoryRepoNameForConan(aqlConanResultList, item); + } + } + return null; } @@ -340,6 +381,14 @@ private static AqlResult GetArtifactoryRepoName(List aqlResultList, C return repoName; } - } + private static AqlResult GetArtifactoryRepoNameForConan(List aqlResultList, Component component) + { + string jfrogcomponentPath = $"{component.Name}/{component.Version}"; + + AqlResult repoName = aqlResultList.Find(x => x.Path.Contains( + jfrogcomponentPath, StringComparison.OrdinalIgnoreCase)); + return repoName; + } + } } diff --git a/src/LCT.APICommunications/Model/ComponentsToArtifactory.cs b/src/LCT.APICommunications/Model/ComponentsToArtifactory.cs index 2e0292f0..39a234cd 100644 --- a/src/LCT.APICommunications/Model/ComponentsToArtifactory.cs +++ b/src/LCT.APICommunications/Model/ComponentsToArtifactory.cs @@ -24,6 +24,6 @@ public class ComponentsToArtifactory public string PackageInfoApiUrl { get; set; } public string CopyPackageApiUrl { get; set; } public string PackageExtension { get; set; } - + public string Path { get; set; } } } diff --git a/src/LCT.Common/CommonAppSettings.cs b/src/LCT.Common/CommonAppSettings.cs index ac9580e9..b2cd4ad1 100644 --- a/src/LCT.Common/CommonAppSettings.cs +++ b/src/LCT.Common/CommonAppSettings.cs @@ -65,6 +65,7 @@ public CommonAppSettings(IFolderAction iFolderAction) public Config Maven { get; set; } public Config Debian { get; set; } public Config Python { get; set; } + public Config Conan { get; set; } public string CaVersion { get; set; } public string CycloneDxSBomTemplatePath { get; set; } public string[] InternalRepoList { get; set; } @@ -74,6 +75,7 @@ public CommonAppSettings(IFolderAction iFolderAction) public string JfrogNugetDestRepoName { get; set; } public string JfrogMavenDestRepoName { get; set; } public string JfrogPythonDestRepoName { get; set; } + public string JfrogConanDestRepoName { get; set; } public string JfrogNugetSrcRepo { get; set; } public string Mode { get; set; } = string.Empty; diff --git a/src/LCT.Common/Model/Config.cs b/src/LCT.Common/Model/Config.cs index 9b0f4ca3..6bc38c08 100644 --- a/src/LCT.Common/Model/Config.cs +++ b/src/LCT.Common/Model/Config.cs @@ -22,6 +22,7 @@ public class Config public string[] JfrogNugetRepoList { get; set; } public string[] JfrogMavenRepoList { get; set; } public string[] JfrogPythonRepoList { get; set; } + public string[] JfrogConanRepoList { get; set; } public string[] DevDependentScopeList { get; set; } } diff --git a/src/LCT.Common/appSettings.json b/src/LCT.Common/appSettings.json index 3089715e..5260879e 100644 --- a/src/LCT.Common/appSettings.json +++ b/src/LCT.Common/appSettings.json @@ -19,6 +19,7 @@ "JfrogNpmDestRepoName": "", "JfrogMavenDestRepoName": "", "JfrogPythonDestRepoName": "", + "JfrogConanDestRepoName": "", "PackageFilePath": "/PathToInputDirectory", //For Docker run set as /mnt/Input "BomFolderPath": "/PathToOutputDirectory", //For Docker run set as /mnt/Output "BomFilePath": "/PathToOutputDirectory/_Bom.cdx.json", @@ -70,7 +71,7 @@ "Python": { "Include": [ "poetry.lock", "*.cdx.json" ], "Exclude": [], - "JfrogPythonRepoList": [ + "JfrogPythonRepoList": [ "", //This is a mirror repo for pypi in JFrog "" //This should be the release pypi in JFrog ], diff --git a/src/LCT.SW360PackageCreator/URLHelper.cs b/src/LCT.SW360PackageCreator/URLHelper.cs index 44a1e156..7daad006 100644 --- a/src/LCT.SW360PackageCreator/URLHelper.cs +++ b/src/LCT.SW360PackageCreator/URLHelper.cs @@ -193,7 +193,7 @@ public async Task GetSourceUrlForConanPackage(string componentName, stri } if (packageSourcesInfo.SourcesData.TryGetValue(version,out var release)) { - if (release.Url.GetType().Name == "string") + if (release.Url.GetType().Name.ToLowerInvariant() == "string") { componentSrcURL = release.Url.ToString(); }