Skip to content

Commit a2dc71b

Browse files
soul2zimateclaude
andcommitted
fix: inline lazy endpoint resolution and document IllegalStateException
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3edf7c1 commit a2dc71b

2 files changed

Lines changed: 12 additions & 15 deletions

File tree

src/main/java/io/github/guacsec/trustifyda/Api.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ CompletableFuture<Map<ImageRef, AnalysisReport>> imageAnalysis(Set<ImageRef> ima
131131
* @param manifestFile the path for the manifest file
132132
* @return the CycloneDX JSON SBOM content as a String
133133
* @throws IOException when failed to load the manifest file
134+
* @throws IllegalStateException when the manifest file type is not supported
134135
*/
135136
String generateSbom(String manifestFile) throws IOException;
136137
}

src/main/java/io/github/guacsec/trustifyda/impl/ExhortApi.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ public final class ExhortApi implements Api {
8686
private String endpoint;
8787

8888
public String getEndpoint() {
89-
return getOrResolveEndpoint();
89+
if (this.endpoint == null) {
90+
this.endpoint = getExhortUrl();
91+
}
92+
return this.endpoint;
9093
}
9194

9295
private final HttpClient client;
@@ -162,13 +165,6 @@ private static String getClientRequestId() {
162165
return RequestManager.getInstance().getTraceIdOfRequest();
163166
}
164167

165-
private String getOrResolveEndpoint() {
166-
if (this.endpoint == null) {
167-
this.endpoint = getExhortUrl();
168-
}
169-
return this.endpoint;
170-
}
171-
172168
private String getExhortUrl() {
173169
String endpoint = Environment.get(TRUSTIFY_DA_BACKEND_URL);
174170
if (endpoint == null || endpoint.trim().isEmpty()) {
@@ -352,7 +348,7 @@ public CompletableFuture<AnalysisReport> componentAnalysis(
352348
String exClientTraceId = commonHookBeginning(false);
353349
var manifestPath = Path.of(manifest);
354350
var provider = Ecosystem.getProvider(manifestPath);
355-
var uri = URI.create(String.format(S_API_V_5_ANALYSIS, getOrResolveEndpoint()));
351+
var uri = URI.create(String.format(S_API_V_5_ANALYSIS, getEndpoint()));
356352
var content = provider.provideComponent();
357353
commonHookAfterProviderCreatedSbomAndBeforeExhort();
358354
return getAnalysisReportForComponent(uri, content, exClientTraceId);
@@ -396,7 +392,7 @@ public CompletableFuture<AnalysisReport> componentAnalysis(String manifestFile)
396392
String exClientTraceId = commonHookBeginning(false);
397393
var manifestPath = Path.of(manifestFile);
398394
var provider = Ecosystem.getProvider(manifestPath);
399-
var uri = URI.create(String.format(S_API_V_5_ANALYSIS, getOrResolveEndpoint()));
395+
var uri = URI.create(String.format(S_API_V_5_ANALYSIS, getEndpoint()));
400396
var content = provider.provideComponent();
401397
commonHookAfterProviderCreatedSbomAndBeforeExhort();
402398
return getAnalysisReportForComponent(uri, content, exClientTraceId);
@@ -437,7 +433,7 @@ private HttpRequest buildStackRequest(final String manifestFile, final MediaType
437433
throws IOException {
438434
var manifestPath = Path.of(manifestFile);
439435
var provider = Ecosystem.getProvider(manifestPath);
440-
var uri = URI.create(String.format(S_API_V_5_ANALYSIS, getOrResolveEndpoint()));
436+
var uri = URI.create(String.format(S_API_V_5_ANALYSIS, getEndpoint()));
441437
var content = provider.provideStack();
442438
commonHookAfterProviderCreatedSbomAndBeforeExhort();
443439

@@ -524,7 +520,7 @@ <H, T> CompletableFuture<T> performBatchAnalysis(
524520
final String analysisName)
525521
throws IOException {
526522
String exClientTraceId = commonHookBeginning(false);
527-
var uri = URI.create(String.format(S_API_V_5_BATCH_ANALYSIS, getOrResolveEndpoint()));
523+
var uri = URI.create(String.format(S_API_V_5_BATCH_ANALYSIS, getEndpoint()));
528524
var sboms = sbomsGenerator.get();
529525
var content =
530526
new Provider.Content(
@@ -586,7 +582,7 @@ public CompletableFuture<ComponentAnalysisResult> componentAnalysisWithLicense(
586582
String exClientTraceId = commonHookBeginning(false);
587583
var manifestPath = Path.of(manifestFile);
588584
var provider = Ecosystem.getProvider(manifestPath);
589-
var uri = URI.create(String.format(S_API_V_5_ANALYSIS, getOrResolveEndpoint()));
585+
var uri = URI.create(String.format(S_API_V_5_ANALYSIS, getEndpoint()));
590586
var content = provider.provideComponent();
591587
String sbomJson = new String(content.buffer);
592588
commonHookAfterProviderCreatedSbomAndBeforeExhort();
@@ -617,7 +613,7 @@ public CompletableFuture<ComponentAnalysisResult> componentAnalysisWithLicense(
617613
*/
618614
public CompletableFuture<JsonNode> getLicenseDetails(String spdxId) {
619615
String encodedId = URLEncoder.encode(spdxId, StandardCharsets.UTF_8).replace("+", "%20");
620-
URI uri = URI.create(String.format(S_API_V5_LICENSES, getOrResolveEndpoint(), encodedId));
616+
URI uri = URI.create(String.format(S_API_V5_LICENSES, getEndpoint(), encodedId));
621617
HttpRequest request = buildGetRequest(uri, "License Details");
622618

623619
return this.client
@@ -663,7 +659,7 @@ public CompletableFuture<String> identifyLicense(Path licenseFilePath) {
663659
LOG.warning(String.format("Failed to read license file: %s", e.getMessage()));
664660
return CompletableFuture.completedFuture(null);
665661
}
666-
URI uri = URI.create(String.format(S_API_V5_LICENSES_IDENTIFY, getOrResolveEndpoint()));
662+
URI uri = URI.create(String.format(S_API_V5_LICENSES_IDENTIFY, getEndpoint()));
667663
HttpRequest request =
668664
buildPostRequest(
669665
uri,

0 commit comments

Comments
 (0)