Skip to content

Commit 01a6bb5

Browse files
authored
Merge pull request #234 from ruromero/trustification-ossindex
feat: allow trustification to use default authentication
2 parents 60362c0 + 4abbb22 commit 01a6bb5

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-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: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.util.Base64;
2222
import java.util.List;
23+
import java.util.Optional;
2324

2425
import org.apache.camel.Exchange;
2526
import org.apache.camel.builder.AggregationStrategies;
@@ -39,9 +40,17 @@
3940
@ApplicationScoped
4041
public class OssIndexIntegration extends EndpointRouteBuilder {
4142

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

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

4756
@Inject OssIndexResponseHandler responseHandler;
@@ -55,6 +64,7 @@ public void configure() {
5564
from(direct("ossIndexScan"))
5665
.routeId("ossIndexScan")
5766
.transform(method(OssIndexRequestBuilder.class, "split"))
67+
.process(this::authenticateTrustificationSource)
5868
.choice()
5969
.when(method(OssIndexRequestBuilder.class, "missingAuthHeaders"))
6070
.setBody(method(OssIndexResponseHandler.class, "unauthenticatedResponse"))
@@ -117,4 +127,17 @@ private void processComponentRequest(Exchange exchange) {
117127
message.removeHeader(Constants.OSS_INDEX_USER_HEADER);
118128
message.removeHeader(Constants.OSS_INDEX_TOKEN_HEADER);
119129
}
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+
}
120143
}

0 commit comments

Comments
 (0)