Skip to content

Commit 81d45d3

Browse files
committed
chore: update http headers
1 parent ab919ba commit 81d45d3

5 files changed

Lines changed: 97 additions & 55 deletions

File tree

catalog-info.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ apiVersion: backstage.io/v1alpha1
22
kind: Component
33
metadata:
44
annotations:
5-
backstage.io/kubernetes-id: trustify-da-java-client
5+
backstage.io/kuberqnetes-id: trustify-da-java-client
66
github.com/project-slug: guacsec/trustify-da-java-client
77
github.com/project-readme-path: README.md
88
backstage.io/view-url: https://github.com/guacsec/trustify-da-java-client/blob/main/catalog-info.yaml
99
backstage.io/edit-url: https://github.com/guacsec/trustify-da-java-client/blob/main/catalog-info.yaml
1010
backstage.io/source-location: url:https://github.com/guacsec/trustify-da-java-client
11-
rhda/manifest-file-path: package.json
11+
trust-da/manifest-file-path: package.json
1212
backstage.io/techdocs-ref: url:https://github.com/guacsec/trustify-da-java-client
1313
name: trustify-da-java-client
1414
tags:
15-
- rhda
15+
- trust-da
1616
spec:
1717
lifecycle: production
1818
owner: ecosystem-appeng

src/main/java/com/redhat/exhort/impl/ExhortApi.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ public final class ExhortApi implements Api {
7676

7777
public static final String DEFAULT_ENDPOINT = "https://rhda.rhcloud.com";
7878
public static final String DEFAULT_ENDPOINT_DEV = "https://exhort.stage.devshift.net";
79-
public static final String RHDA_TOKEN_HEADER = "rhda-token";
80-
public static final String RHDA_SOURCE_HEADER = "rhda-source";
81-
public static final String RHDA_OPERATION_TYPE_HEADER = "rhda-operation-type";
79+
public static final String TRUST_DA_TOKEN_HEADER = "trust-da-token";
80+
public static final String TRUST_DA_SOURCE_HEADER = "trust-da-source";
81+
public static final String TRUST_DA_OPERATION_TYPE_HEADER = "trust-da-operation-type";
8282
public static final String TRUSTIFY_DA_REQUEST_ID_HEADER_NAME = "ex-request-id";
8383

8484
private final String endpoint;
@@ -670,19 +670,19 @@ private HttpRequest buildRequest(
670670
}
671671
}
672672
});
673-
// set rhda-token
674-
// Environment variable/property name = RHDA_TOKEN
675-
String rhdaToken = calculateHeaderValue(RHDA_TOKEN_HEADER);
676-
if (rhdaToken != null) {
677-
request.setHeader(RHDA_TOKEN_HEADER, rhdaToken);
673+
// set trust-da-token
674+
// Environment variable/property name = TRUST_DA_TOKEN
675+
String trustDaToken = calculateHeaderValue(TRUST_DA_TOKEN_HEADER);
676+
if (trustDaToken != null) {
677+
request.setHeader(TRUST_DA_TOKEN_HEADER, trustDaToken);
678678
}
679-
// set rhda-source ( extension/plugin id/name)
680-
// Environment variable/property name = RHDA_SOURCE
681-
String rhdaSource = calculateHeaderValue(RHDA_SOURCE_HEADER);
682-
if (rhdaSource != null) {
683-
request.setHeader(RHDA_SOURCE_HEADER, rhdaSource);
679+
// set trust-da-source ( extension/plugin id/name)
680+
// Environment variable/property name = TRUST_DA_SOURCE
681+
String trustDaSource = calculateHeaderValue(TRUST_DA_SOURCE_HEADER);
682+
if (trustDaSource != null) {
683+
request.setHeader(TRUST_DA_SOURCE_HEADER, trustDaSource);
684684
}
685-
request.setHeader(RHDA_OPERATION_TYPE_HEADER, analysisType);
685+
request.setHeader(TRUST_DA_OPERATION_TYPE_HEADER, analysisType);
686686

687687
return request.build();
688688
}

src/main/resources/exhort/openapi.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ paths:
1919
operationId: analysis
2020
summary: Takes a client-resolved dependency graph to perform a full stack analysis from all the available Vulnerability sources
2121
security:
22-
- RhdaTokenAuth: []
22+
- TrustDaTokenAuth: []
2323
- SnykTokenAuth: []
2424
- OssIndexUserAuth: []
2525
OssIndexTokenAuth: []
@@ -74,7 +74,7 @@ paths:
7474
operationId: batchAnalysis
7575
summary: Takes an array of client-resolved dependency graphs to perform a full stack analysis from all the available Vulnerability sources
7676
security:
77-
- RhdaTokenAuth: [ ]
77+
- TrustDaTokenAuth: [ ]
7878
- SnykTokenAuth: [ ]
7979
- OssIndexUserAuth: [ ]
8080
OssIndexTokenAuth: [ ]
@@ -137,7 +137,7 @@ paths:
137137
operationId: validateToken
138138
summary: Validates a vulnerability provider token
139139
security:
140-
- RhdaTokenAuth: []
140+
- TrustDaTokenAuth: []
141141
- SnykTokenAuth: []
142142
- OssIndexUserAuth: []
143143
OssIndexTokenAuth: []
@@ -180,10 +180,10 @@ paths:
180180

181181
components:
182182
securitySchemes:
183-
RhdaTokenAuth:
183+
TrustDaTokenAuth:
184184
type: apiKey
185185
in: header
186-
name: rhda-token
186+
name: trust-da-token
187187
SnykTokenAuth:
188188
type: apiKey
189189
in: header

src/test/java/com/redhat/exhort/impl/ExhortApiIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
@Tag("IntegrationTest")
7878
@ExtendWith(HelperExtension.class)
7979
@ExtendWith(MockitoExtension.class)
80-
@SetSystemProperty(key = "RHDA_SOURCE", value = "trustify-da-java-client-it")
80+
@SetSystemProperty(key = "TRUST_DA_SOURCE", value = "trustify-da-java-client-it")
8181
@SetSystemProperty(key = "TRUSTIFY_DA_DEV_MODE", value = "false")
8282
@RestoreSystemProperties
8383
class ExhortApiIT extends ExhortTest {

src/test/java/com/redhat/exhort/impl/Exhort_Api_Test.java

Lines changed: 74 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@
8383
@ClearSystemProperty(key = "TRUSTIFY_DA_DEV_MODE")
8484
@ClearSystemProperty(key = "TRUSTIFY_DA_PROXY_URL")
8585
@ClearSystemProperty(key = "DEV_TRUSTIFY_DA_BACKEND_URL")
86-
@ClearSystemProperty(key = "RHDA_TOKEN")
87-
@ClearSystemProperty(key = "RHDA_SOURCE")
86+
@ClearSystemProperty(key = "TRUST_DA_TOKEN")
87+
@ClearSystemProperty(key = "TRUST_DA_SOURCE")
8888
@SuppressWarnings("unchecked")
8989
class TRUSTIFY_DA_Api_Test extends ExhortTest {
9090

@@ -101,8 +101,8 @@ void cleanup() {
101101

102102
@Test
103103
@SetSystemProperty(key = "TRUSTIFY_DA_SNYK_TOKEN", value = "snyk-token-from-env-var")
104-
@SetSystemProperty(key = "RHDA_TOKEN", value = "rhda-token-from-env-var")
105-
@SetSystemProperty(key = "RHDA_SOURCE", value = "rhda-source-from-env-var")
104+
@SetSystemProperty(key = "TRUST_DA_TOKEN", value = "trust-da-token-from-env-var")
105+
@SetSystemProperty(key = "TRUST_DA_SOURCE", value = "trust-da-source-from-env-var")
106106
void stackAnalysisHtml_with_pom_xml_should_return_html_report_from_the_backend()
107107
throws IOException, ExecutionException, InterruptedException {
108108
// create a temporary pom.xml file
@@ -124,9 +124,15 @@ void stackAnalysisHtml_with_pom_xml_should_return_html_report_from_the_backend()
124124
&&
125125
// snyk token is set using the environment variable (annotation)
126126
r.headers().firstValue("ex-snyk-token").get().equals("snyk-token-from-env-var")
127-
&& r.headers().firstValue("rhda-token").get().equals("rhda-token-from-env-var")
128-
&& r.headers().firstValue("rhda-source").get().equals("rhda-source-from-env-var")
129-
&& r.headers().firstValue("rhda-operation-type").get().equals("Stack Analysis")
127+
&& r.headers()
128+
.firstValue("trust-da-token")
129+
.get()
130+
.equals("trust-da-token-from-env-var")
131+
&& r.headers()
132+
.firstValue("trust-da-source")
133+
.get()
134+
.equals("trust-da-source-from-env-var")
135+
&& r.headers().firstValue("trust-da-operation-type").get().equals("Stack Analysis")
130136
&& r.method().equals("POST");
131137

132138
// load dummy html and set as the expected analysis
@@ -162,8 +168,8 @@ void stackAnalysisHtml_with_pom_xml_should_return_html_report_from_the_backend()
162168

163169
@Test
164170
@SetSystemProperty(key = "TRUSTIFY_DA_SNYK_TOKEN", value = "snyk-token")
165-
@SetSystemProperty(key = "RHDA_TOKEN", value = "rhda-token")
166-
@SetSystemProperty(key = "RHDA_SOURCE", value = "rhda-source")
171+
@SetSystemProperty(key = "TRUST_DA_TOKEN", value = "trust-da-token")
172+
@SetSystemProperty(key = "TRUST_DA_SOURCE", value = "trust-da-source")
167173
void stackAnalysis_with_pom_xml_should_return_json_object_from_the_backend()
168174
throws IOException, ExecutionException, InterruptedException {
169175
// create a temporary pom.xml file
@@ -183,9 +189,9 @@ void stackAnalysis_with_pom_xml_should_return_json_object_from_the_backend()
183189
r.headers().firstValue("Content-Type").get().equals("fake-content-type")
184190
&& r.headers().firstValue("Accept").get().equals("application/json")
185191
&& r.headers().firstValue("ex-snyk-token").get().equals("snyk-token")
186-
&& r.headers().firstValue("rhda-token").get().equals("rhda-token")
187-
&& r.headers().firstValue("rhda-source").get().equals("rhda-source")
188-
&& r.headers().firstValue("rhda-operation-type").get().equals("Stack Analysis")
192+
&& r.headers().firstValue("trust-da-token").get().equals("trust-da-token")
193+
&& r.headers().firstValue("trust-da-source").get().equals("trust-da-source")
194+
&& r.headers().firstValue("trust-da-operation-type").get().equals("Stack Analysis")
189195
&& r.method().equals("POST");
190196

191197
// load dummy json and set as the expected analysis
@@ -238,8 +244,8 @@ void componentAnalysis_with_pom_xml_should_return_json_object_from_the_backend()
238244

239245
// we expect this to picked up because no env var to take precedence
240246
System.setProperty("TRUSTIFY_DA_SNYK_TOKEN", "snyk-token-from-property");
241-
System.setProperty("RHDA_TOKEN", "rhda-token-from-property");
242-
System.setProperty("RHDA_SOURCE", "rhda-source-from-property");
247+
System.setProperty("TRUST_DA_TOKEN", "trust-da-token-from-property");
248+
System.setProperty("TRUST_DA_SOURCE", "trust-da-source-from-property");
243249

244250
// create an argument matcher to make sure we mock the response for the right request
245251
ArgumentMatcher<HttpRequest> matchesRequest =
@@ -250,9 +256,18 @@ void componentAnalysis_with_pom_xml_should_return_json_object_from_the_backend()
250256
// snyk token is set using properties which is picked up because no env var
251257
// specified
252258
r.headers().firstValue("ex-snyk-token").get().equals("snyk-token-from-property")
253-
&& r.headers().firstValue("rhda-token").get().equals("rhda-token-from-property")
254-
&& r.headers().firstValue("rhda-source").get().equals("rhda-source-from-property")
255-
&& r.headers().firstValue("rhda-operation-type").get().equals("Component Analysis")
259+
&& r.headers()
260+
.firstValue("trust-da-token")
261+
.get()
262+
.equals("trust-da-token-from-property")
263+
&& r.headers()
264+
.firstValue("trust-da-source")
265+
.get()
266+
.equals("trust-da-source-from-property")
267+
&& r.headers()
268+
.firstValue("trust-da-operation-type")
269+
.get()
270+
.equals("Component Analysis")
256271
&& r.method().equals("POST");
257272

258273
// load dummy json and set as the expected analysis
@@ -457,8 +472,8 @@ void check_TRUSTIFY_DA_Url_When_Nothing_Set_Then_Default_TRUSTIFY_DA_URL_Selecte
457472

458473
@Test
459474
@SetSystemProperty(key = "TRUSTIFY_DA_SNYK_TOKEN", value = "snyk-token-from-env-var")
460-
@SetSystemProperty(key = "RHDA_TOKEN", value = "rhda-token-from-env-var")
461-
@SetSystemProperty(key = "RHDA_SOURCE", value = "rhda-source-from-env-var")
475+
@SetSystemProperty(key = "TRUST_DA_TOKEN", value = "trust-da-token-from-env-var")
476+
@SetSystemProperty(key = "TRUST_DA_SOURCE", value = "trust-da-source-from-env-var")
462477
@SetSystemProperty(key = SKIP_VALIDATION_KEY, value = "true")
463478
void test_image_analysis()
464479
throws IOException, ExecutionException, InterruptedException, MalformedPackageURLException {
@@ -521,9 +536,18 @@ void test_image_analysis()
521536
.get()
522537
.equals(Api.MediaType.APPLICATION_JSON.toString())
523538
&& r.headers().firstValue("ex-snyk-token").get().equals("snyk-token-from-env-var")
524-
&& r.headers().firstValue("rhda-token").get().equals("rhda-token-from-env-var")
525-
&& r.headers().firstValue("rhda-source").get().equals("rhda-source-from-env-var")
526-
&& r.headers().firstValue("rhda-operation-type").get().equals("Image Analysis")
539+
&& r.headers()
540+
.firstValue("trust-da-token")
541+
.get()
542+
.equals("trust-da-token-from-env-var")
543+
&& r.headers()
544+
.firstValue("trust-da-source")
545+
.get()
546+
.equals("trust-da-source-from-env-var")
547+
&& r.headers()
548+
.firstValue("trust-da-operation-type")
549+
.get()
550+
.equals("Image Analysis")
527551
&& r.method().equals("POST");
528552

529553
when(mockHttpClient.sendAsync(argThat(matchesRequest), any()))
@@ -557,8 +581,8 @@ void test_image_analysis()
557581

558582
@Test
559583
@SetSystemProperty(key = "TRUSTIFY_DA_SNYK_TOKEN", value = "snyk-token-from-env-var")
560-
@SetSystemProperty(key = "RHDA_TOKEN", value = "rhda-token-from-env-var")
561-
@SetSystemProperty(key = "RHDA_SOURCE", value = "rhda-source-from-env-var")
584+
@SetSystemProperty(key = "TRUST_DA_TOKEN", value = "trust-da-token-from-env-var")
585+
@SetSystemProperty(key = "TRUST_DA_SOURCE", value = "trust-da-source-from-env-var")
562586
@SetSystemProperty(key = SKIP_VALIDATION_KEY, value = "true")
563587
void imageAnalysisHtml() throws IOException, ExecutionException, InterruptedException {
564588
try (MockedStatic<Operations> mock = Mockito.mockStatic(Operations.class);
@@ -620,9 +644,18 @@ void imageAnalysisHtml() throws IOException, ExecutionException, InterruptedExce
620644
.get()
621645
.equals(Api.MediaType.TEXT_HTML.toString())
622646
&& r.headers().firstValue("ex-snyk-token").get().equals("snyk-token-from-env-var")
623-
&& r.headers().firstValue("rhda-token").get().equals("rhda-token-from-env-var")
624-
&& r.headers().firstValue("rhda-source").get().equals("rhda-source-from-env-var")
625-
&& r.headers().firstValue("rhda-operation-type").get().equals("Image Analysis")
647+
&& r.headers()
648+
.firstValue("trust-da-token")
649+
.get()
650+
.equals("trust-da-token-from-env-var")
651+
&& r.headers()
652+
.firstValue("trust-da-source")
653+
.get()
654+
.equals("trust-da-source-from-env-var")
655+
&& r.headers()
656+
.firstValue("trust-da-operation-type")
657+
.get()
658+
.equals("Image Analysis")
626659
&& r.method().equals("POST");
627660

628661
when(mockHttpClient.sendAsync(argThat(matchesRequest), any()))
@@ -635,8 +668,8 @@ void imageAnalysisHtml() throws IOException, ExecutionException, InterruptedExce
635668

636669
@Test
637670
@SetSystemProperty(key = "TRUSTIFY_DA_SNYK_TOKEN", value = "snyk-token-from-env-var")
638-
@SetSystemProperty(key = "RHDA_TOKEN", value = "rhda-token-from-env-var")
639-
@SetSystemProperty(key = "RHDA_SOURCE", value = "rhda-source-from-env-var")
671+
@SetSystemProperty(key = "TRUST_DA_TOKEN", value = "trust-da-token-from-env-var")
672+
@SetSystemProperty(key = "TRUST_DA_SOURCE", value = "trust-da-source-from-env-var")
640673
void test_perform_batch_analysis()
641674
throws IOException, MalformedPackageURLException, ExecutionException, InterruptedException {
642675
try (var is = getResourceAsStreamDecision(this.getClass(), "msc/image/image_sbom.json")) {
@@ -658,9 +691,18 @@ void test_perform_batch_analysis()
658691
.get()
659692
.equals(Api.MediaType.APPLICATION_JSON.toString())
660693
&& r.headers().firstValue("ex-snyk-token").get().equals("snyk-token-from-env-var")
661-
&& r.headers().firstValue("rhda-token").get().equals("rhda-token-from-env-var")
662-
&& r.headers().firstValue("rhda-source").get().equals("rhda-source-from-env-var")
663-
&& r.headers().firstValue("rhda-operation-type").get().equals("Image Analysis")
694+
&& r.headers()
695+
.firstValue("trust-da-token")
696+
.get()
697+
.equals("trust-da-token-from-env-var")
698+
&& r.headers()
699+
.firstValue("trust-da-source")
700+
.get()
701+
.equals("trust-da-source-from-env-var")
702+
&& r.headers()
703+
.firstValue("trust-da-operation-type")
704+
.get()
705+
.equals("Image Analysis")
664706
&& r.method().equals("POST");
665707

666708
var imageRef =

0 commit comments

Comments
 (0)