From 74c225fa458bed2e1d2fd11cbaa3af05dbf1fbc7 Mon Sep 17 00:00:00 2001 From: Ayan Sinha Mahapatra Date: Tue, 8 Aug 2023 17:21:57 +0530 Subject: [PATCH] Add support for custom repository URLs Adds support for getting packages from custom repository URLs, in the case of maven packages. Signed-off-by: Ayan Sinha Mahapatra --- minecode/visitors/maven.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/minecode/visitors/maven.py b/minecode/visitors/maven.py index 023f672a..293a6bb8 100644 --- a/minecode/visitors/maven.py +++ b/minecode/visitors/maven.py @@ -61,6 +61,9 @@ logger.setLevel(logging.DEBUG) +MAVEN_BASE_URL = 'https://repo1.maven.org/maven2' + + class GzipFileWithTrailing(gzip.GzipFile): """ A subclass of gzip.GzipFile supporting files with trailing garbage. Ignore @@ -104,7 +107,7 @@ def get_seeds(self): # also has a npm mirrors: https://maven-eu.nuxeo.org/nexus/#view-repositories;npmjs~browsestorage -def get_pom_text(namespace, name, version, qualifiers={}): +def get_pom_text(namespace, name, version, qualifiers={}, base_url=MAVEN_BASE_URL): """ Return the contents of the POM file of the package described by the purl field arguments in a string. @@ -116,7 +119,8 @@ def get_pom_text(namespace, name, version, qualifiers={}): namespace=namespace, name=name, version=version, - qualifiers=qualifiers + qualifiers=qualifiers, + base_url=base_url, ) # Get and parse POM info pom_url = urls['api_data_url'] @@ -279,11 +283,17 @@ def map_maven_package(package_url, package_content): db_package = None error = '' + if "repository_url" in package_url.qualifiers: + base_url = package_url.qualifiers["repository_url"] + else: + base_url = MAVEN_BASE_URL + pom_text = get_pom_text( namespace=package_url.namespace, name=package_url.name, version=package_url.version, - qualifiers=package_url.qualifiers + qualifiers=package_url.qualifiers, + base_url=base_url, ) if not pom_text: msg = f'Package does not exist on maven: {package_url}' @@ -302,11 +312,14 @@ def map_maven_package(package_url, package_content): ancestor_pom_texts=ancestor_pom_texts, package=package ) + + urls = get_urls( namespace=package_url.namespace, name=package_url.name, version=package_url.version, - qualifiers=package_url.qualifiers + qualifiers=package_url.qualifiers, + base_url=base_url, ) # In the case of looking up a maven package with qualifiers of # `classifiers=sources`, the purl of the package created from the pom does