Skip to content

Commit eea4aa7

Browse files
committed
chore: remove SNYK and OSS_INDEX refs
1 parent ed55b29 commit eea4aa7

3 files changed

Lines changed: 0 additions & 114 deletions

File tree

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

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
import java.util.function.Supplier;
6161
import java.util.logging.Logger;
6262
import java.util.stream.Collectors;
63-
import java.util.stream.Stream;
6463

6564
/** Concrete implementation of the Exhort {@link Api} Service. */
6665
public final class ExhortApi implements Api {
@@ -88,38 +87,6 @@ public String getEndpoint() {
8887
return endpoint;
8988
}
9089

91-
/** Enum for identifying token environment variables and their corresponding request headers. */
92-
private enum TokenProvider {
93-
SNYK,
94-
OSS_INDEX;
95-
96-
/**
97-
* Get the expected environment variable name.
98-
*
99-
* @return i.e. TRUSTIFY_DA_SNYK_TOKEN
100-
*/
101-
String getVarName() {
102-
return String.format("TRUSTIFY_DA_%s_TOKEN", this);
103-
}
104-
105-
String getUserVarName() {
106-
return String.format("TRUSTIFY_DA_%s_USER", this);
107-
}
108-
109-
/**
110-
* Get the expected request header name.
111-
*
112-
* @return i.e. ex-snyk-token
113-
*/
114-
String getHeaderName() {
115-
return String.format("ex-%s-token", this.toString().replace("_", "-").toLowerCase());
116-
}
117-
118-
String getUserHeaderName() {
119-
return String.format("ex-%s-user", this.toString().replace("_", "-").toLowerCase());
120-
}
121-
}
122-
12390
private final HttpClient client;
12491
private final ObjectMapper mapper;
12592

@@ -648,29 +615,6 @@ private HttpRequest buildRequest(
648615
.setHeader("Content-Type", content.type)
649616
.POST(HttpRequest.BodyPublishers.ofString(new String(content.buffer)));
650617

651-
// include tokens from environment variables of java properties as request headers
652-
Stream.of(ExhortApi.TokenProvider.values())
653-
.forEach(
654-
p -> {
655-
var envToken = Environment.get(p.getVarName());
656-
if (Objects.nonNull(envToken)) {
657-
request.setHeader(p.getHeaderName(), envToken);
658-
} else {
659-
var propToken = Environment.get(p.getVarName());
660-
if (Objects.nonNull(propToken)) {
661-
request.setHeader(p.getHeaderName(), propToken);
662-
}
663-
}
664-
var envUser = Environment.get(p.getUserHeaderName());
665-
if (Objects.nonNull(envUser)) {
666-
request.setHeader(p.getUserHeaderName(), envUser);
667-
} else {
668-
var propUser = Environment.get(p.getUserVarName());
669-
if (Objects.nonNull(propUser)) {
670-
request.setHeader(p.getUserHeaderName(), propUser);
671-
}
672-
}
673-
});
674618
// set trust-da-token
675619
// Environment variable/property name = TRUST_DA_TOKEN
676620
String trustDaToken = calculateHeaderValue(TRUST_DA_TOKEN_HEADER);

src/main/resources/exhort/openapi.yaml

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,13 @@ paths:
2020
summary: Takes a client-resolved dependency graph to perform a full stack analysis from all the available Vulnerability sources
2121
security:
2222
- TrustDaTokenAuth: []
23-
- SnykTokenAuth: []
24-
- OssIndexUserAuth: []
25-
OssIndexTokenAuth: []
2623
parameters:
2724
- name: providers
2825
in: query
2926
description: List of vulnerability providers to get the report from
3027
required: false
3128
schema:
32-
enum:
33-
- snyk
34-
- oss-index
3529
type: string
36-
example: snyk
3730
requestBody:
3831
required: true
3932
description: Dependency graph in SBOM format
@@ -75,20 +68,13 @@ paths:
7568
summary: Takes an array of client-resolved dependency graphs to perform a full stack analysis from all the available Vulnerability sources
7669
security:
7770
- TrustDaTokenAuth: [ ]
78-
- SnykTokenAuth: [ ]
79-
- OssIndexUserAuth: [ ]
80-
OssIndexTokenAuth: [ ]
8171
parameters:
8272
- name: providers
8373
in: query
8474
description: List of vulnerability providers to get the report from
8575
required: false
8676
schema:
87-
enum:
88-
- snyk
89-
- oss-index
9077
type: string
91-
example: snyk
9278
requestBody:
9379
required: true
9480
description: An array of dependency graphs in SBOM format
@@ -138,9 +124,6 @@ paths:
138124
summary: Validates a vulnerability provider token
139125
security:
140126
- TrustDaTokenAuth: []
141-
- SnykTokenAuth: []
142-
- OssIndexUserAuth: []
143-
OssIndexTokenAuth: []
144127
responses:
145128
'200':
146129
description: Successful token validation
@@ -184,18 +167,6 @@ components:
184167
type: apiKey
185168
in: header
186169
name: trust-da-token
187-
SnykTokenAuth:
188-
type: apiKey
189-
in: header
190-
name: ex-snyk-token
191-
OssIndexUserAuth:
192-
type: apiKey
193-
in: header
194-
name: ex-oss-index-name
195-
OssIndexTokenAuth:
196-
type: apiKey
197-
in: header
198-
name: ex-oss-index-token
199170
schemas:
200171
AnalysisReport:
201172
type: object

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

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
import java.util.function.Function;
6767
import java.util.function.Supplier;
6868
import java.util.stream.Collectors;
69-
import org.junit.jupiter.api.AfterEach;
7069
import org.junit.jupiter.api.Test;
7170
import org.junit.jupiter.api.extension.ExtendWith;
7271
import org.junitpioneer.jupiter.ClearSystemProperty;
@@ -80,7 +79,6 @@
8079
import org.mockito.junit.jupiter.MockitoExtension;
8180

8281
@ExtendWith(MockitoExtension.class)
83-
@ClearSystemProperty(key = "TRUSTIFY_DA_SNYK_TOKEN")
8482
@ClearSystemProperty(key = "TRUSTIFY_DA_DEV_MODE")
8583
@ClearSystemProperty(key = "TRUSTIFY_DA_PROXY_URL")
8684
@ClearSystemProperty(key = "DEV_TRUSTIFY_DA_BACKEND_URL")
@@ -95,13 +93,7 @@ class TRUSTIFY_DA_Api_Test extends ExhortTest {
9593

9694
@InjectMocks ExhortApi exhortApiSut;
9795

98-
@AfterEach
99-
void cleanup() {
100-
System.clearProperty("TRUSTIFY_DA_SNYK_TOKEN");
101-
}
102-
10396
@Test
104-
@SetSystemProperty(key = "TRUSTIFY_DA_SNYK_TOKEN", value = "snyk-token-from-env-var")
10597
@SetSystemProperty(key = "TRUST_DA_TOKEN", value = "trust-da-token-from-env-var")
10698
@SetSystemProperty(key = "TRUST_DA_SOURCE", value = "trust-da-source-from-env-var")
10799
void stackAnalysisHtml_with_pom_xml_should_return_html_report_from_the_backend()
@@ -122,9 +114,6 @@ void stackAnalysisHtml_with_pom_xml_should_return_html_report_from_the_backend()
122114
r ->
123115
r.headers().firstValue("Content-Type").get().equals("fake-content-type")
124116
&& r.headers().firstValue("Accept").get().equals("text/html")
125-
&&
126-
// snyk token is set using the environment variable (annotation)
127-
r.headers().firstValue("ex-snyk-token").get().equals("snyk-token-from-env-var")
128117
&& r.headers()
129118
.firstValue("trust-da-token")
130119
.get()
@@ -168,7 +157,6 @@ void stackAnalysisHtml_with_pom_xml_should_return_html_report_from_the_backend()
168157
}
169158

170159
@Test
171-
@SetSystemProperty(key = "TRUSTIFY_DA_SNYK_TOKEN", value = "snyk-token")
172160
@SetSystemProperty(key = "TRUST_DA_TOKEN", value = "trust-da-token")
173161
@SetSystemProperty(key = "TRUST_DA_SOURCE", value = "trust-da-source")
174162
void stackAnalysis_with_pom_xml_should_return_json_object_from_the_backend()
@@ -189,7 +177,6 @@ void stackAnalysis_with_pom_xml_should_return_json_object_from_the_backend()
189177
r ->
190178
r.headers().firstValue("Content-Type").get().equals("fake-content-type")
191179
&& r.headers().firstValue("Accept").get().equals("application/json")
192-
&& r.headers().firstValue("ex-snyk-token").get().equals("snyk-token")
193180
&& r.headers().firstValue("trust-da-token").get().equals("trust-da-token")
194181
&& r.headers().firstValue("trust-da-source").get().equals("trust-da-source")
195182
&& r.headers().firstValue("trust-da-operation-type").get().equals("Stack Analysis")
@@ -244,7 +231,6 @@ void componentAnalysis_with_pom_xml_should_return_json_object_from_the_backend()
244231
.willReturn(new Provider.Content("fake-body-content".getBytes(), "fake-content-type"));
245232

246233
// we expect this to picked up because no env var to take precedence
247-
System.setProperty("TRUSTIFY_DA_SNYK_TOKEN", "snyk-token-from-property");
248234
System.setProperty("TRUST_DA_TOKEN", "trust-da-token-from-property");
249235
System.setProperty("TRUST_DA_SOURCE", "trust-da-source-from-property");
250236

@@ -253,10 +239,6 @@ void componentAnalysis_with_pom_xml_should_return_json_object_from_the_backend()
253239
r ->
254240
r.headers().firstValue("Content-Type").get().equals("fake-content-type")
255241
&& r.headers().firstValue("Accept").get().equals("application/json")
256-
&&
257-
// snyk token is set using properties which is picked up because no env var
258-
// specified
259-
r.headers().firstValue("ex-snyk-token").get().equals("snyk-token-from-property")
260242
&& r.headers()
261243
.firstValue("trust-da-token")
262244
.get()
@@ -388,17 +370,12 @@ void componentAnalysis_with_pom_xml_as_path_should_return_json_object_from_the_b
388370
.willReturn(new Provider.Content("fake-body-content".getBytes(), "fake-content-type"));
389371

390372
// we expect this to picked up because no env var to take precedence
391-
System.setProperty("TRUSTIFY_DA_SNYK_TOKEN", "snyk-token-from-property");
392373

393374
// create an argument matcher to make sure we mock the response for the right request
394375
ArgumentMatcher<HttpRequest> matchesRequest =
395376
r ->
396377
r.headers().firstValue("Content-Type").get().equals("fake-content-type")
397378
&& r.headers().firstValue("Accept").get().equals("application/json")
398-
&&
399-
// snyk token is set using properties which is picked up because no env var
400-
// specified
401-
r.headers().firstValue("ex-snyk-token").get().equals("snyk-token-from-property")
402379
&& r.method().equals("POST");
403380

404381
// load dummy json and set as the expected analysis
@@ -472,7 +449,6 @@ void check_TRUSTIFY_DA_Url_When_Nothing_Set_Then_Default_TRUSTIFY_DA_URL_Selecte
472449
}
473450

474451
@Test
475-
@SetSystemProperty(key = "TRUSTIFY_DA_SNYK_TOKEN", value = "snyk-token-from-env-var")
476452
@SetSystemProperty(key = "TRUST_DA_TOKEN", value = "trust-da-token-from-env-var")
477453
@SetSystemProperty(key = "TRUST_DA_SOURCE", value = "trust-da-source-from-env-var")
478454
@SetSystemProperty(key = SKIP_VALIDATION_KEY, value = "true")
@@ -536,7 +512,6 @@ void test_image_analysis()
536512
.firstValue("Accept")
537513
.get()
538514
.equals(Api.MediaType.APPLICATION_JSON.toString())
539-
&& r.headers().firstValue("ex-snyk-token").get().equals("snyk-token-from-env-var")
540515
&& r.headers()
541516
.firstValue("trust-da-token")
542517
.get()
@@ -581,7 +556,6 @@ void test_image_analysis()
581556
}
582557

583558
@Test
584-
@SetSystemProperty(key = "TRUSTIFY_DA_SNYK_TOKEN", value = "snyk-token-from-env-var")
585559
@SetSystemProperty(key = "TRUST_DA_TOKEN", value = "trust-da-token-from-env-var")
586560
@SetSystemProperty(key = "TRUST_DA_SOURCE", value = "trust-da-source-from-env-var")
587561
@SetSystemProperty(key = SKIP_VALIDATION_KEY, value = "true")
@@ -644,7 +618,6 @@ void imageAnalysisHtml() throws IOException, ExecutionException, InterruptedExce
644618
.firstValue("Accept")
645619
.get()
646620
.equals(Api.MediaType.TEXT_HTML.toString())
647-
&& r.headers().firstValue("ex-snyk-token").get().equals("snyk-token-from-env-var")
648621
&& r.headers()
649622
.firstValue("trust-da-token")
650623
.get()
@@ -668,7 +641,6 @@ void imageAnalysisHtml() throws IOException, ExecutionException, InterruptedExce
668641
}
669642

670643
@Test
671-
@SetSystemProperty(key = "TRUSTIFY_DA_SNYK_TOKEN", value = "snyk-token-from-env-var")
672644
@SetSystemProperty(key = "TRUST_DA_TOKEN", value = "trust-da-token-from-env-var")
673645
@SetSystemProperty(key = "TRUST_DA_SOURCE", value = "trust-da-source-from-env-var")
674646
void test_perform_batch_analysis()
@@ -691,7 +663,6 @@ void test_perform_batch_analysis()
691663
.firstValue("Accept")
692664
.get()
693665
.equals(Api.MediaType.APPLICATION_JSON.toString())
694-
&& r.headers().firstValue("ex-snyk-token").get().equals("snyk-token-from-env-var")
695666
&& r.headers()
696667
.firstValue("trust-da-token")
697668
.get()

0 commit comments

Comments
 (0)