Skip to content

Commit

Permalink
Merge pull request #162 from ruromero/npm-pkg
Browse files Browse the repository at this point in the history
fix: npm package ns parsing and enhance logs
  • Loading branch information
ruromero authored Sep 20, 2023
2 parents f1e6e93 + 5d3a1e9 commit 32d0073
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/main/java/com/redhat/exhort/api/PackageRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public String name() {
return purl.getName();
}
switch (purl.getType()) {
case Constants.GOLANG_PKG_MANAGER:
return new StringBuffer(purl.getNamespace()).append("/").append(purl.getName()).toString();
default:
case Constants.MAVEN_PKG_MANAGER:
return new StringBuilder(purl.getNamespace()).append(":").append(purl.getName()).toString();
default:
return new StringBuffer(purl.getNamespace()).append("/").append(purl.getName()).toString();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,16 @@ public static void processResponseError(Exchange exchange, String provider) {
Throwable cause = exception.getCause();

if (cause != null) {
LOGGER.warn("Unable to process request to: {}", provider, cause);
if (cause instanceof HttpOperationFailedException) {
HttpOperationFailedException httpException = (HttpOperationFailedException) cause;
status.message(prettifyHttpError(httpException)).status(httpException.getStatusCode());
String message = prettifyHttpError(httpException);
status.message(message).status(httpException.getStatusCode());
LOGGER.warn("Unable to process request: {}", message, cause);
} else {
status
.message(cause.getMessage())
.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
LOGGER.warn("Unable to process request to: {}", provider, cause);
}
} else {
status
Expand Down Expand Up @@ -113,10 +115,8 @@ private static String prettifyHttpError(HttpOperationFailedException httpExcepti
return text + ": The provided credentials don't have the required permissions.";
case 429:
return text + ": The rate limit has been exceeded.";
case 500:
return text + ": " + httpException.getResponseBody();
default:
return text;
return text + ": " + httpException.getResponseBody();
}
}
}
3 changes: 3 additions & 0 deletions src/test/java/com/redhat/exhort/api/PackageRefTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public void testNamespace() {
ref = new PackageRef("pkg:npm/[email protected]");
assertEquals("foobar", ref.name());

ref = new PackageRef("pkg:npm/%40babel/[email protected]");
assertEquals("@babel/helper-compilation-targets", ref.name());

ref = new PackageRef("pkg:maven/org.apache.xmlgraphics/[email protected]?packaging=sources");
assertEquals("org.apache.xmlgraphics:batik-anim", ref.name());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,13 @@ static Stream<Arguments> getSbomUseCases() {
.version("0.0.0-development")
.pkgManager(Constants.NPM_PKG_MANAGER)
.build()));
consumer.accept(arguments(t, Constants.PYPI_PKG_MANAGER, 2, 0, DEFAULT_MAVEN_ROOT));
consumer.accept(
arguments(
t,
Constants.PYPI_PKG_MANAGER,
2,
0,
DependencyTree.getDefaultRoot(Constants.PYPI_PKG_MANAGER)));
});
}

Expand Down

0 comments on commit 32d0073

Please sign in to comment.