Skip to content

Commit 2d06c26

Browse files
committed
feat: allow trustification to use default authentication
Signed-off-by: Ruben Romero Montes <[email protected]>
1 parent ffd76a5 commit 2d06c26

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

deploy/exhort.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ 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
3848
- name: MONITORING_ENABLED
3949
value: "true"
4050
- name: MONITORING_SENTRY_DSN

deploy/openshift/template.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,16 @@ objects:
148148
secretKeyRef:
149149
name: exhort-secret
150150
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
151161
- name: TELEMETRY_WRITE_KEY
152162
valueFrom:
153163
secretKeyRef:

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,17 @@
3939
@ApplicationScoped
4040
public class OssIndexIntegration extends EndpointRouteBuilder {
4141

42-
@ConfigProperty(name = "api.ossindex.timeout", defaultValue = "1000s")
42+
private static final String TRUSTIFICATION_SOURCE = "trustification";
43+
44+
@ConfigProperty(name = "api.ossindex.timeout", defaultValue = "10s")
4345
String timeout;
4446

47+
@ConfigProperty(name = "api.ossindex.trustification.user")
48+
String trustificationUser;
49+
50+
@ConfigProperty(name = "api.ossindex.trustification.token")
51+
String trustificationToken;
52+
4553
@Inject VulnerabilityProvider vulnerabilityProvider;
4654

4755
@Inject OssIndexResponseHandler responseHandler;
@@ -55,6 +63,7 @@ public void configure() {
5563
from(direct("ossIndexScan"))
5664
.routeId("ossIndexScan")
5765
.transform(method(OssIndexRequestBuilder.class, "split"))
66+
.process(this::authenticateTrustificationSource)
5867
.choice()
5968
.when(method(OssIndexRequestBuilder.class, "missingAuthHeaders"))
6069
.setBody(method(OssIndexResponseHandler.class, "unauthenticatedResponse"))
@@ -117,4 +126,17 @@ private void processComponentRequest(Exchange exchange) {
117126
message.removeHeader(Constants.OSS_INDEX_USER_HEADER);
118127
message.removeHeader(Constants.OSS_INDEX_TOKEN_HEADER);
119128
}
129+
130+
private void authenticateTrustificationSource(Exchange exchange) {
131+
var headers = exchange.getIn().getHeaders();
132+
var source = headers.get(Constants.RHDA_SOURCE_HEADER);
133+
if (!TRUSTIFICATION_SOURCE.equals(source)) {
134+
return;
135+
}
136+
if (!headers.containsKey(Constants.OSS_INDEX_USER_HEADER)
137+
&& !headers.containsKey(Constants.OSS_INDEX_TOKEN_HEADER)) {
138+
headers.put(Constants.OSS_INDEX_USER_HEADER, trustificationUser);
139+
headers.put(Constants.OSS_INDEX_TOKEN_HEADER, trustificationToken);
140+
}
141+
}
120142
}

0 commit comments

Comments
 (0)