Skip to content

Commit

Permalink
Artifactory Uploader changes for CONAN package
Browse files Browse the repository at this point in the history
  • Loading branch information
NihalBarick13 committed Nov 3, 2023
1 parent fad30ea commit e418cf9
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 11 deletions.
65 changes: 57 additions & 8 deletions src/ArtifactoryUploader/PackageUploadHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public async static Task<List<ComponentsToArtifactory>> 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,
Expand All @@ -86,6 +86,7 @@ public async static Task<List<ComponentsToArtifactory>> 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);
Expand Down Expand Up @@ -126,13 +127,32 @@ 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
}
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;
Expand All @@ -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
Expand All @@ -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";
Expand All @@ -203,26 +231,39 @@ private static string GetComponentType(Component item)
{
return "PYTHON";
}
else if (item.Purl.Contains("conan", StringComparison.OrdinalIgnoreCase))
{
return "CONAN";
}
else
{
// Do nothing
}
return string.Empty;
}

private async static Task<AqlResult> GetSrcRepoDetailsForPyPiPackages(Component item, CommonAppSettings appSettings)
private async static Task<AqlResult> 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;
}

Expand Down Expand Up @@ -340,6 +381,14 @@ private static AqlResult GetArtifactoryRepoName(List<AqlResult> aqlResultList, C
return repoName;
}

}
private static AqlResult GetArtifactoryRepoNameForConan(List<AqlResult> aqlResultList, Component component)
{
string jfrogcomponentPath = $"{component.Name}/{component.Version}";

AqlResult repoName = aqlResultList.Find(x => x.Path.Contains(
jfrogcomponentPath, StringComparison.OrdinalIgnoreCase));

return repoName;
}
}
}
2 changes: 1 addition & 1 deletion src/LCT.APICommunications/Model/ComponentsToArtifactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
2 changes: 2 additions & 0 deletions src/LCT.Common/CommonAppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/LCT.Common/Model/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

}
Expand Down
3 changes: 2 additions & 1 deletion src/LCT.Common/appSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"JfrogNpmDestRepoName": "<Insert NpmDestRepoName>",
"JfrogMavenDestRepoName": "<Insert MavenDestRepoName>",
"JfrogPythonDestRepoName": "<Insert PythonDestRepoName>",
"JfrogConanDestRepoName": "<Insert ConanDestRepoName>",
"PackageFilePath": "/PathToInputDirectory", //For Docker run set as /mnt/Input
"BomFolderPath": "/PathToOutputDirectory", //For Docker run set as /mnt/Output
"BomFilePath": "/PathToOutputDirectory/<SW360 Project Name>_Bom.cdx.json",
Expand Down Expand Up @@ -70,7 +71,7 @@
"Python": {
"Include": [ "poetry.lock", "*.cdx.json" ],
"Exclude": [],
"JfrogPythonRepoList": [
"JfrogPythonRepoList": [
"<Python Remote Cache Repo Name>", //This is a mirror repo for pypi in JFrog
"<Python Release Repo Name>" //This should be the release pypi in JFrog
],
Expand Down
2 changes: 1 addition & 1 deletion src/LCT.SW360PackageCreator/URLHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public async Task<string> 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();
}
Expand Down

0 comments on commit e418cf9

Please sign in to comment.