Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/com/redhat/exhort/integration/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ private Constants() {}
public static final String OSS_INDEX_PROVIDER = "oss-index";
public static final String UNKNOWN_PROVIDER = "unknown";

public static final String HTTP_UNAUTHENTICATED = "Unauthenticated";

public static final String MAVEN_PKG_MANAGER = "maven";
public static final String NPM_PKG_MANAGER = "npm";
public static final String PYPI_PKG_MANAGER = "pypi";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public ProviderReport unauthenticatedResponse(Exchange exchange) {
new ProviderStatus()
.name(getProviderName())
.ok(Boolean.FALSE)
.message("Missing mandatory credentials")
.message(Constants.HTTP_UNAUTHENTICATED)
.code(Response.Status.UNAUTHORIZED.getStatusCode()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import java.util.Base64;
import java.util.List;
import java.util.Objects;

import org.apache.camel.Exchange;
import org.apache.camel.builder.AggregationStrategies;
Expand All @@ -34,7 +33,6 @@

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.ClientErrorException;
import jakarta.ws.rs.HttpMethod;
import jakarta.ws.rs.core.MediaType;

Expand All @@ -58,45 +56,45 @@ public void configure() {
.routeId("ossIndexScan")
.transform(method(OssIndexRequestBuilder.class, "split"))
.choice()
.when(method(OssIndexRequestBuilder.class, "missingAuthHeaders"))
.setBody(method(OssIndexResponseHandler.class, "unauthenticatedResponse"))
.when(method(OssIndexRequestBuilder.class, "isEmpty"))
.setBody(method(OssIndexResponseHandler.class, "emptyResponse"))
.transform().method(OssIndexResponseHandler.class, "buildReport")
.when(method(OssIndexRequestBuilder.class, "missingAuthHeaders"))
.setBody(method(OssIndexResponseHandler.class, "unauthenticatedResponse"))
.when(method(OssIndexRequestBuilder.class, "isEmpty"))
.setBody(method(OssIndexResponseHandler.class, "emptyResponse"))
.transform().method(OssIndexResponseHandler.class, "buildReport")
.endChoice()
.otherwise()
.to(direct("ossSplitReq"))
.transform().method(OssIndexResponseHandler.class, "buildReport");
.to(direct("ossSplitReq"))
.transform().method(OssIndexResponseHandler.class, "buildReport");

from(direct("ossSplitReq"))
.routeId("ossSplitReq")
.split(body(), AggregationStrategies.beanAllowNull(OssIndexResponseHandler.class, "aggregateSplit"))
.parallelProcessing()
.transform().method(OssIndexRequestBuilder.class, "buildRequest")
.process(this::processComponentRequest)
.circuitBreaker()
.faultToleranceConfiguration()
.timeoutEnabled(true)
.timeoutDuration(timeout)
.end()
.to(vertxHttp("{{api.ossindex.host}}"))
.transform(method(OssIndexResponseHandler.class, "responseToIssues"))
.onFallback()
.process(responseHandler::processResponseError);
.split(body(), AggregationStrategies.beanAllowNull(OssIndexResponseHandler.class, "aggregateSplit"))
.parallelProcessing()
.transform().method(OssIndexRequestBuilder.class, "buildRequest")
.process(this::processComponentRequest)
.circuitBreaker()
.faultToleranceConfiguration()
.timeoutEnabled(true)
.timeoutDuration(timeout)
.end()
.to(vertxHttp("{{api.ossindex.host}}"))
.transform(method(OssIndexResponseHandler.class, "responseToIssues"))
.onFallback()
.process(responseHandler::processResponseError);

from(direct("ossValidateCredentials"))
.routeId("ossValidateCredentials")
.circuitBreaker()
.routeId("ossValidateCredentials")
.circuitBreaker()
.faultToleranceConfiguration()
.timeoutEnabled(true)
.timeoutDuration(timeout)
.end()
.timeoutEnabled(true)
.timeoutDuration(timeout)
.end()
.setBody(constant(List.of(DependencyTree.getDefaultRoot(Constants.MAVEN_PKG_MANAGER))))
.transform().method(OssIndexRequestBuilder.class, "buildRequest")
.process(this::processComponentRequest)
.process(this::processComponentRequest)
.to(vertxHttp("{{api.ossindex.host}}"))
.setBody(constant("Token validated successfully"))
.onFallback()
.onFallback()
.process(responseHandler::processTokenFallBack);
// fmt:on
}
Expand All @@ -112,15 +110,10 @@ private void processComponentRequest(Exchange exchange) {

var username = message.getHeader(Constants.OSS_INDEX_USER_HEADER, String.class);
var token = message.getHeader(Constants.OSS_INDEX_TOKEN_HEADER, String.class);
if (Objects.nonNull(username) && Objects.nonNull(token)) {
message.setHeader(Exchange.HTTP_PATH, Constants.OSS_INDEX_AUTH_COMPONENT_API_PATH);
var auth = new StringBuilder().append(username).append(":").append(token);
message.setHeader(
"Authorization",
"Basic " + Base64.getEncoder().encodeToString(auth.toString().getBytes()));
} else {
throw new ClientErrorException(401);
}
message.setHeader(Exchange.HTTP_PATH, Constants.OSS_INDEX_AUTH_COMPONENT_API_PATH);
var auth = new StringBuilder().append(username).append(":").append(token);
message.setHeader(
"Authorization", "Basic " + Base64.getEncoder().encodeToString(auth.toString().getBytes()));
message.removeHeader(Constants.OSS_INDEX_USER_HEADER);
message.removeHeader(Constants.OSS_INDEX_TOKEN_HEADER);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/freemarker/templates/generated/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/mocks/reportWithUnauthenticated.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const unauthenticatedReport: AppData = {
"ok": false,
"name": "oss-index",
"code": 401,
"message": "Missing mandatory credentials"
"message": "Unauthenticated"
}
},
"snyk": {
Expand Down
2 changes: 1 addition & 1 deletion ui/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const getSignUpLink = (provider: string): string => {
}

export const hasSignUpTab = (provider: ProviderStatus): boolean => {
if(!provider.ok && provider.code === 401) {
if(!provider.ok && provider.code === 401 && provider.message === 'Unauthenticated') {
return SIGN_UP_TAB_PROVIDERS.includes(provider.name);
}
return false;
Expand Down