Skip to content

Commit 935d89b

Browse files
committed
feat: trustification requests will not show oss-index data unless requested
Signed-off-by: Ruben Romero Montes <[email protected]>
1 parent 01a6bb5 commit 935d89b

File tree

5 files changed

+13
-48
lines changed

5 files changed

+13
-48
lines changed

deploy/exhort.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,6 @@ spec:
3535
secretKeyRef:
3636
name: exhort-secret
3737
key: api-snyk-token
38-
- name: API_OSSINDEX_TRUSTIFICATION_TOKEN
39-
valueFrom:
40-
secretKeyRef:
41-
name: exhort-secret
42-
key: api-ossindex-trustification-token
43-
- name: API_OSSINDEX_TRUSTIFICATION_USER
44-
valueFrom:
45-
secretKeyRef:
46-
name: exhort-secret
47-
key: api-ossindex-trustification-user
4838
- name: MONITORING_ENABLED
4939
value: "true"
5040
- name: MONITORING_SENTRY_DSN

deploy/openshift/template.yaml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,7 @@ objects:
147147
valueFrom:
148148
secretKeyRef:
149149
name: exhort-secret
150-
key: api-snyk-token
151-
- name: API_OSSINDEX_TRUSTIFICATION_TOKEN
152-
valueFrom:
153-
secretKeyRef:
154-
name: exhort-secret
155-
key: api-ossindex-trustification-token
156-
- name: API_OSSINDEX_TRUSTIFICATION_USER
157-
valueFrom:
158-
secretKeyRef:
159-
name: exhort-secret
160-
key: api-ossindex-trustification-user
150+
key: api-snyk-token
161151
- name: TELEMETRY_WRITE_KEY
162152
valueFrom:
163153
secretKeyRef:

src/main/java/com/redhat/exhort/integration/providers/VulnerabilityProvider.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
@RegisterForReflection
4545
public class VulnerabilityProvider {
4646

47+
private static final String TRUSTIFICATION_SOURCE = "trustification";
48+
4749
@ConfigProperty(name = "api.snyk.disabled", defaultValue = "false")
4850
boolean snykDisabled;
4951

@@ -89,7 +91,7 @@ public List<String> getProvidersFromQueryParam(@Headers Map<String, String> head
8991
var props = URISupport.parseQuery(query);
9092
var providers = getProviders(props);
9193
if (providers == null || providers.isEmpty()) {
92-
return getEnabled();
94+
return filterProvidersBySource(headers, getEnabled());
9395
}
9496
var missing =
9597
providers.stream()
@@ -101,6 +103,15 @@ public List<String> getProvidersFromQueryParam(@Headers Map<String, String> head
101103
throw new ClientErrorException("Unsupported providers: " + missing, 422);
102104
}
103105

106+
private List<String> filterProvidersBySource(
107+
Map<String, String> headers, List<String> providers) {
108+
var source = headers.get(Constants.RHDA_SOURCE_HEADER);
109+
if (TRUSTIFICATION_SOURCE.equals(source)) {
110+
return providers.stream().filter(Predicate.not(Constants.OSS_INDEX_PROVIDER::equalsIgnoreCase)).toList();
111+
}
112+
return providers;
113+
}
114+
104115
@SuppressWarnings("unchecked")
105116
private List<String> getProviders(Map<String, Object> props) {
106117
var o = props.get(Constants.PROVIDERS_PARAM);

src/main/java/com/redhat/exhort/integration/providers/ossindex/OssIndexIntegration.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import java.util.Base64;
2222
import java.util.List;
23-
import java.util.Optional;
2423

2524
import org.apache.camel.Exchange;
2625
import org.apache.camel.builder.AggregationStrategies;
@@ -40,17 +39,9 @@
4039
@ApplicationScoped
4140
public class OssIndexIntegration extends EndpointRouteBuilder {
4241

43-
private static final String TRUSTIFICATION_SOURCE = "trustification";
44-
4542
@ConfigProperty(name = "api.ossindex.timeout", defaultValue = "10s")
4643
String timeout;
4744

48-
@ConfigProperty(name = "api.ossindex.trustification.user")
49-
Optional<String> trustificationUser;
50-
51-
@ConfigProperty(name = "api.ossindex.trustification.token")
52-
Optional<String> trustificationToken;
53-
5445
@Inject VulnerabilityProvider vulnerabilityProvider;
5546

5647
@Inject OssIndexResponseHandler responseHandler;
@@ -64,7 +55,6 @@ public void configure() {
6455
from(direct("ossIndexScan"))
6556
.routeId("ossIndexScan")
6657
.transform(method(OssIndexRequestBuilder.class, "split"))
67-
.process(this::authenticateTrustificationSource)
6858
.choice()
6959
.when(method(OssIndexRequestBuilder.class, "missingAuthHeaders"))
7060
.setBody(method(OssIndexResponseHandler.class, "unauthenticatedResponse"))
@@ -127,17 +117,4 @@ private void processComponentRequest(Exchange exchange) {
127117
message.removeHeader(Constants.OSS_INDEX_USER_HEADER);
128118
message.removeHeader(Constants.OSS_INDEX_TOKEN_HEADER);
129119
}
130-
131-
private void authenticateTrustificationSource(Exchange exchange) {
132-
var headers = exchange.getIn().getHeaders();
133-
var source = headers.get(Constants.RHDA_SOURCE_HEADER);
134-
if (!TRUSTIFICATION_SOURCE.equals(source)) {
135-
return;
136-
}
137-
if (!headers.containsKey(Constants.OSS_INDEX_USER_HEADER)
138-
&& !headers.containsKey(Constants.OSS_INDEX_TOKEN_HEADER)) {
139-
headers.put(Constants.OSS_INDEX_USER_HEADER, trustificationUser.orElse(null));
140-
headers.put(Constants.OSS_INDEX_TOKEN_HEADER, trustificationToken.orElse(null));
141-
}
142-
}
143120
}

src/main/resources/application.properties

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ project.name=${pom.name}
55
project.version=${pom.version}
66
project.build=${timestamp}
77

8-
9-
10-
118
api.snyk.token=placeholder
129
api.snyk.host=https://app.snyk.io/api/v1
1310
# api.snyk.timeout=10s

0 commit comments

Comments
 (0)