Skip to content

Commit cabdf37

Browse files
committed
chore: remove SNYK and OSS_INDEX refs
1 parent 81d45d3 commit cabdf37

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
@@ -59,7 +59,6 @@
5959
import java.util.function.Supplier;
6060
import java.util.logging.Logger;
6161
import java.util.stream.Collectors;
62-
import java.util.stream.Stream;
6362

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

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

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

650-
// include tokens from environment variables of java properties as request headers
651-
Stream.of(ExhortApi.TokenProvider.values())
652-
.forEach(
653-
p -> {
654-
var envToken = Environment.get(p.getVarName());
655-
if (Objects.nonNull(envToken)) {
656-
request.setHeader(p.getHeaderName(), envToken);
657-
} else {
658-
var propToken = Environment.get(p.getVarName());
659-
if (Objects.nonNull(propToken)) {
660-
request.setHeader(p.getHeaderName(), propToken);
661-
}
662-
}
663-
var envUser = Environment.get(p.getUserHeaderName());
664-
if (Objects.nonNull(envUser)) {
665-
request.setHeader(p.getUserHeaderName(), envUser);
666-
} else {
667-
var propUser = Environment.get(p.getUserVarName());
668-
if (Objects.nonNull(propUser)) {
669-
request.setHeader(p.getUserHeaderName(), propUser);
670-
}
671-
}
672-
});
673617
// set trust-da-token
674618
// Environment variable/property name = TRUST_DA_TOKEN
675619
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
@@ -65,7 +65,6 @@
6565
import java.util.function.Function;
6666
import java.util.function.Supplier;
6767
import java.util.stream.Collectors;
68-
import org.junit.jupiter.api.AfterEach;
6968
import org.junit.jupiter.api.Test;
7069
import org.junit.jupiter.api.extension.ExtendWith;
7170
import org.junitpioneer.jupiter.ClearSystemProperty;
@@ -79,7 +78,6 @@
7978
import org.mockito.junit.jupiter.MockitoExtension;
8079

8180
@ExtendWith(MockitoExtension.class)
82-
@ClearSystemProperty(key = "TRUSTIFY_DA_SNYK_TOKEN")
8381
@ClearSystemProperty(key = "TRUSTIFY_DA_DEV_MODE")
8482
@ClearSystemProperty(key = "TRUSTIFY_DA_PROXY_URL")
8583
@ClearSystemProperty(key = "DEV_TRUSTIFY_DA_BACKEND_URL")
@@ -94,13 +92,7 @@ class TRUSTIFY_DA_Api_Test extends ExhortTest {
9492

9593
@InjectMocks ExhortApi exhortApiSut;
9694

97-
@AfterEach
98-
void cleanup() {
99-
System.clearProperty("TRUSTIFY_DA_SNYK_TOKEN");
100-
}
101-
10295
@Test
103-
@SetSystemProperty(key = "TRUSTIFY_DA_SNYK_TOKEN", value = "snyk-token-from-env-var")
10496
@SetSystemProperty(key = "TRUST_DA_TOKEN", value = "trust-da-token-from-env-var")
10597
@SetSystemProperty(key = "TRUST_DA_SOURCE", value = "trust-da-source-from-env-var")
10698
void stackAnalysisHtml_with_pom_xml_should_return_html_report_from_the_backend()
@@ -121,9 +113,6 @@ void stackAnalysisHtml_with_pom_xml_should_return_html_report_from_the_backend()
121113
r ->
122114
r.headers().firstValue("Content-Type").get().equals("fake-content-type")
123115
&& r.headers().firstValue("Accept").get().equals("text/html")
124-
&&
125-
// snyk token is set using the environment variable (annotation)
126-
r.headers().firstValue("ex-snyk-token").get().equals("snyk-token-from-env-var")
127116
&& r.headers()
128117
.firstValue("trust-da-token")
129118
.get()
@@ -167,7 +156,6 @@ void stackAnalysisHtml_with_pom_xml_should_return_html_report_from_the_backend()
167156
}
168157

169158
@Test
170-
@SetSystemProperty(key = "TRUSTIFY_DA_SNYK_TOKEN", value = "snyk-token")
171159
@SetSystemProperty(key = "TRUST_DA_TOKEN", value = "trust-da-token")
172160
@SetSystemProperty(key = "TRUST_DA_SOURCE", value = "trust-da-source")
173161
void stackAnalysis_with_pom_xml_should_return_json_object_from_the_backend()
@@ -188,7 +176,6 @@ void stackAnalysis_with_pom_xml_should_return_json_object_from_the_backend()
188176
r ->
189177
r.headers().firstValue("Content-Type").get().equals("fake-content-type")
190178
&& r.headers().firstValue("Accept").get().equals("application/json")
191-
&& r.headers().firstValue("ex-snyk-token").get().equals("snyk-token")
192179
&& r.headers().firstValue("trust-da-token").get().equals("trust-da-token")
193180
&& r.headers().firstValue("trust-da-source").get().equals("trust-da-source")
194181
&& r.headers().firstValue("trust-da-operation-type").get().equals("Stack Analysis")
@@ -243,7 +230,6 @@ void componentAnalysis_with_pom_xml_should_return_json_object_from_the_backend()
243230
.willReturn(new Provider.Content("fake-body-content".getBytes(), "fake-content-type"));
244231

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

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

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

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

403380
// load dummy json and set as the expected analysis
@@ -471,7 +448,6 @@ void check_TRUSTIFY_DA_Url_When_Nothing_Set_Then_Default_TRUSTIFY_DA_URL_Selecte
471448
}
472449

473450
@Test
474-
@SetSystemProperty(key = "TRUSTIFY_DA_SNYK_TOKEN", value = "snyk-token-from-env-var")
475451
@SetSystemProperty(key = "TRUST_DA_TOKEN", value = "trust-da-token-from-env-var")
476452
@SetSystemProperty(key = "TRUST_DA_SOURCE", value = "trust-da-source-from-env-var")
477453
@SetSystemProperty(key = SKIP_VALIDATION_KEY, value = "true")
@@ -535,7 +511,6 @@ void test_image_analysis()
535511
.firstValue("Accept")
536512
.get()
537513
.equals(Api.MediaType.APPLICATION_JSON.toString())
538-
&& r.headers().firstValue("ex-snyk-token").get().equals("snyk-token-from-env-var")
539514
&& r.headers()
540515
.firstValue("trust-da-token")
541516
.get()
@@ -580,7 +555,6 @@ void test_image_analysis()
580555
}
581556

582557
@Test
583-
@SetSystemProperty(key = "TRUSTIFY_DA_SNYK_TOKEN", value = "snyk-token-from-env-var")
584558
@SetSystemProperty(key = "TRUST_DA_TOKEN", value = "trust-da-token-from-env-var")
585559
@SetSystemProperty(key = "TRUST_DA_SOURCE", value = "trust-da-source-from-env-var")
586560
@SetSystemProperty(key = SKIP_VALIDATION_KEY, value = "true")
@@ -643,7 +617,6 @@ void imageAnalysisHtml() throws IOException, ExecutionException, InterruptedExce
643617
.firstValue("Accept")
644618
.get()
645619
.equals(Api.MediaType.TEXT_HTML.toString())
646-
&& r.headers().firstValue("ex-snyk-token").get().equals("snyk-token-from-env-var")
647620
&& r.headers()
648621
.firstValue("trust-da-token")
649622
.get()
@@ -667,7 +640,6 @@ void imageAnalysisHtml() throws IOException, ExecutionException, InterruptedExce
667640
}
668641

669642
@Test
670-
@SetSystemProperty(key = "TRUSTIFY_DA_SNYK_TOKEN", value = "snyk-token-from-env-var")
671643
@SetSystemProperty(key = "TRUST_DA_TOKEN", value = "trust-da-token-from-env-var")
672644
@SetSystemProperty(key = "TRUST_DA_SOURCE", value = "trust-da-source-from-env-var")
673645
void test_perform_batch_analysis()
@@ -690,7 +662,6 @@ void test_perform_batch_analysis()
690662
.firstValue("Accept")
691663
.get()
692664
.equals(Api.MediaType.APPLICATION_JSON.toString())
693-
&& r.headers().firstValue("ex-snyk-token").get().equals("snyk-token-from-env-var")
694665
&& r.headers()
695666
.firstValue("trust-da-token")
696667
.get()

0 commit comments

Comments
 (0)