-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Updates/improvements for
issue list
commands
- Loading branch information
Showing
10 changed files
with
323 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...e/fcli-fod/src/main/java/com/fortify/cli/fod/_common/cli/mixin/AbstractFoDEmbedMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/******************************************************************************* | ||
* Copyright 2021, 2023 Open Text. | ||
* | ||
* The only warranties for products and services of Open Text | ||
* and its affiliates and licensors ("Open Text") are as may | ||
* be set forth in the express warranty statements accompanying | ||
* such products and services. Nothing herein should be construed | ||
* as constituting an additional warranty. Open Text shall not be | ||
* liable for technical or editorial errors or omissions contained | ||
* herein. The information contained herein is subject to change | ||
* without notice. | ||
*******************************************************************************/ | ||
package com.fortify.cli.fod._common.cli.mixin; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fortify.cli.common.cli.mixin.CommandHelperMixin; | ||
import com.fortify.cli.common.output.transform.IRecordTransformer; | ||
import com.fortify.cli.common.rest.unirest.IUnirestInstanceSupplier; | ||
import com.fortify.cli.fod._common.rest.embed.FoDEmbedder; | ||
import com.fortify.cli.fod._common.rest.embed.IFoDEntityEmbedderSupplier; | ||
|
||
import kong.unirest.UnirestInstance; | ||
import picocli.CommandLine.Mixin; | ||
|
||
public abstract class AbstractFoDEmbedMixin implements IRecordTransformer { | ||
@Mixin private CommandHelperMixin commandHelper; | ||
private FoDEmbedder embedder; | ||
|
||
@Override | ||
public final JsonNode transformRecord(JsonNode record) { | ||
if ( embedder==null ) { embedder = new FoDEmbedder(getEmbedSuppliers()); } | ||
UnirestInstance unirest = commandHelper | ||
.getCommandAs(IUnirestInstanceSupplier.class) | ||
.orElseThrow().getUnirestInstance(); | ||
embedder.transformRecord(unirest, record); | ||
return record; | ||
} | ||
|
||
protected abstract IFoDEntityEmbedderSupplier[] getEmbedSuppliers(); | ||
} |
51 changes: 51 additions & 0 deletions
51
fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/_common/rest/embed/FoDEmbedder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/******************************************************************************* | ||
* Copyright 2021, 2023 Open Text. | ||
* | ||
* The only warranties for products and services of Open Text | ||
* and its affiliates and licensors ("Open Text") are as may | ||
* be set forth in the express warranty statements accompanying | ||
* such products and services. Nothing herein should be construed | ||
* as constituting an additional warranty. Open Text shall not be | ||
* liable for technical or editorial errors or omissions contained | ||
* herein. The information contained herein is subject to change | ||
* without notice. | ||
*******************************************************************************/ | ||
package com.fortify.cli.fod._common.rest.embed; | ||
|
||
import java.util.Collection; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
|
||
import kong.unirest.UnirestInstance; | ||
|
||
/** | ||
* This class takes zero or more {@link IFoDEntityEmbedderSupplier} instances | ||
* as constructor argument(s), storing the {@link IFoDEntityEmbedder} instances | ||
* generated by these suppliers, to provide the {@link #transformRecord(UnirestInstance, JsonNode)} | ||
* method that embeds the requested data into a given record. | ||
* | ||
* @author rsenden | ||
* | ||
*/ | ||
public class FoDEmbedder { | ||
private final Collection<IFoDEntityEmbedder> embedders; | ||
|
||
public FoDEmbedder(IFoDEntityEmbedderSupplier... suppliers) { | ||
this.embedders = suppliers==null ? null : Stream.of(suppliers) | ||
.map(IFoDEntityEmbedderSupplier::createEntityEmbedder) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public JsonNode transformRecord(UnirestInstance unirest, JsonNode record) { | ||
if ( embedders!=null ) { | ||
if ( !(record instanceof ObjectNode) ) { | ||
throw new RuntimeException("Can't embed data in records of type "+record.getNodeType()); | ||
} | ||
embedders.forEach(e->e.embed(unirest, (ObjectNode)record)); | ||
} | ||
return record; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...ore/fcli-fod/src/main/java/com/fortify/cli/fod/_common/rest/embed/IFoDEntityEmbedder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/******************************************************************************* | ||
* Copyright 2021, 2023 Open Text. | ||
* | ||
* The only warranties for products and services of Open Text | ||
* and its affiliates and licensors ("Open Text") are as may | ||
* be set forth in the express warranty statements accompanying | ||
* such products and services. Nothing herein should be construed | ||
* as constituting an additional warranty. Open Text shall not be | ||
* liable for technical or editorial errors or omissions contained | ||
* herein. The information contained herein is subject to change | ||
* without notice. | ||
*******************************************************************************/ | ||
package com.fortify.cli.fod._common.rest.embed; | ||
|
||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
|
||
import kong.unirest.UnirestInstance; | ||
|
||
/** | ||
* Interface for executing one or more requests and adding the response data | ||
* as embedded properties to a given record. | ||
* | ||
* @author rsenden | ||
*/ | ||
@FunctionalInterface | ||
public interface IFoDEntityEmbedder { | ||
void embed(UnirestInstance unirest, ObjectNode record); | ||
} |
22 changes: 22 additions & 0 deletions
22
...-fod/src/main/java/com/fortify/cli/fod/_common/rest/embed/IFoDEntityEmbedderSupplier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/******************************************************************************* | ||
* Copyright 2021, 2023 Open Text. | ||
* | ||
* The only warranties for products and services of Open Text | ||
* and its affiliates and licensors ("Open Text") are as may | ||
* be set forth in the express warranty statements accompanying | ||
* such products and services. Nothing herein should be construed | ||
* as constituting an additional warranty. Open Text shall not be | ||
* liable for technical or editorial errors or omissions contained | ||
* herein. The information contained herein is subject to change | ||
* without notice. | ||
*******************************************************************************/ | ||
package com.fortify.cli.fod._common.rest.embed; | ||
|
||
/** | ||
* Interface for supplying an {@link IFoDEntityEmbedder} instance. | ||
* @author rsenden | ||
*/ | ||
@FunctionalInterface | ||
public interface IFoDEntityEmbedderSupplier { | ||
IFoDEntityEmbedder createEntityEmbedder(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
173 changes: 173 additions & 0 deletions
173
fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/issue/cli/mixin/FoDIssueEmbedMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
/******************************************************************************* | ||
* Copyright 2021, 2023 Open Text. | ||
* | ||
* The only warranties for products and services of Open Text | ||
* and its affiliates and licensors ("Open Text") are as may | ||
* be set forth in the express warranty statements accompanying | ||
* such products and services. Nothing herein should be construed | ||
* as constituting an additional warranty. Open Text shall not be | ||
* liable for technical or editorial errors or omissions contained | ||
* herein. The information contained herein is subject to change | ||
* without notice. | ||
*******************************************************************************/ | ||
package com.fortify.cli.fod.issue.cli.mixin; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import com.fortify.cli.common.util.DisableTest; | ||
import com.fortify.cli.common.util.DisableTest.TestType; | ||
import com.fortify.cli.fod._common.cli.mixin.AbstractFoDEmbedMixin; | ||
import com.fortify.cli.fod._common.rest.embed.IFoDEntityEmbedder; | ||
import com.fortify.cli.fod._common.rest.embed.IFoDEntityEmbedderSupplier; | ||
|
||
import kong.unirest.GetRequest; | ||
import kong.unirest.UnirestInstance; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import picocli.CommandLine.Option; | ||
|
||
public class FoDIssueEmbedMixin extends AbstractFoDEmbedMixin { | ||
@DisableTest(TestType.MULTI_OPT_PLURAL_NAME) | ||
@Option(names = "--embed", required = false, split = ",", descriptionKey = "fcli.fod.issue.embed" ) | ||
@Getter private FoDIssueEmbedderSupplier[] embedSuppliers; | ||
|
||
@RequiredArgsConstructor | ||
public static enum FoDIssueEmbedderSupplier implements IFoDEntityEmbedderSupplier { | ||
allData(FoDIssueAllDataEmbedder::new), | ||
summary(FoDIssueSummaryEmbedder::new), | ||
details(FoDIssueDetailsEmbedder::new), | ||
recommendations(FoDIssueRecommendationsEmbedder::new), | ||
history(FoDIssueHistoryEmbedder::new), | ||
requestResponse(FoDIssueRequestResponseEmbedder::new), | ||
headers(FoDIssueHeadersEmbedder::new), | ||
parameters(FoDIssueParametersEmbedder::new), | ||
traces(FoDIssueTracesEmbedder::new), | ||
; | ||
|
||
private final Supplier<IFoDEntityEmbedder> supplier; | ||
|
||
public IFoDEntityEmbedder createEntityEmbedder() { | ||
return supplier.get(); | ||
} | ||
|
||
private static abstract class AbstractFoDIssueEmbedder implements IFoDEntityEmbedder { | ||
@Override | ||
public void embed(UnirestInstance unirest, ObjectNode record) { | ||
var releaseId = record.get("releaseId").asText(); | ||
var vulnId = record.get("vulnId").asText(); | ||
JsonNode response = getBaseRequest(unirest) | ||
.routeParam("releaseId", releaseId) | ||
.routeParam("vulnId", vulnId) | ||
.queryString("limit", "-1") | ||
.asObject(JsonNode.class) | ||
.getBody(); | ||
process(record, response); | ||
} | ||
|
||
protected abstract GetRequest getBaseRequest(UnirestInstance unirest); | ||
protected abstract void process(ObjectNode record, JsonNode response); | ||
} | ||
|
||
private static final class FoDIssueAllDataEmbedder extends AbstractFoDIssueEmbedder { | ||
@Override | ||
protected GetRequest getBaseRequest(UnirestInstance unirest) { | ||
return unirest.get("/api/v3/releases/{releaseId}/vulnerabilities/{vulnId}/all-data"); | ||
} | ||
@Override | ||
protected void process(ObjectNode record, JsonNode response) { | ||
record.set("allData", response); | ||
} | ||
} | ||
|
||
private static final class FoDIssueSummaryEmbedder extends AbstractFoDIssueEmbedder { | ||
@Override | ||
protected GetRequest getBaseRequest(UnirestInstance unirest) { | ||
return unirest.get("/api/v3/releases/{releaseId}/vulnerabilities/{vulnId}/summary"); | ||
} | ||
@Override | ||
protected void process(ObjectNode record, JsonNode response) { | ||
record.set("summary", response); | ||
} | ||
} | ||
|
||
private static final class FoDIssueDetailsEmbedder extends AbstractFoDIssueEmbedder { | ||
@Override | ||
protected GetRequest getBaseRequest(UnirestInstance unirest) { | ||
return unirest.get("/api/v3/releases/{releaseId}/vulnerabilities/{vulnId}/details"); | ||
} | ||
@Override | ||
protected void process(ObjectNode record, JsonNode response) { | ||
record.set("details", response); | ||
} | ||
} | ||
|
||
private static final class FoDIssueRecommendationsEmbedder extends AbstractFoDIssueEmbedder { | ||
@Override | ||
protected GetRequest getBaseRequest(UnirestInstance unirest) { | ||
return unirest.get("/api/v3/releases/{releaseId}/vulnerabilities/{vulnId}/recommendations"); | ||
} | ||
@Override | ||
protected void process(ObjectNode record, JsonNode response) { | ||
record.set("recommendations", response); | ||
} | ||
} | ||
|
||
private static final class FoDIssueHistoryEmbedder extends AbstractFoDIssueEmbedder { | ||
@Override | ||
protected GetRequest getBaseRequest(UnirestInstance unirest) { | ||
return unirest.get("/api/v3/releases/{releaseId}/vulnerabilities/{vulnId}/history"); | ||
} | ||
@Override | ||
protected void process(ObjectNode record, JsonNode response) { | ||
record.set("history", response); | ||
} | ||
} | ||
|
||
private static final class FoDIssueRequestResponseEmbedder extends AbstractFoDIssueEmbedder { | ||
@Override | ||
protected GetRequest getBaseRequest(UnirestInstance unirest) { | ||
return unirest.get("/api/v3/releases/{releaseId}/vulnerabilities/{vulnId}/request-response"); | ||
} | ||
@Override | ||
protected void process(ObjectNode record, JsonNode response) { | ||
record.set("requestResponse", response); | ||
} | ||
} | ||
|
||
private static final class FoDIssueHeadersEmbedder extends AbstractFoDIssueEmbedder { | ||
@Override | ||
protected GetRequest getBaseRequest(UnirestInstance unirest) { | ||
return unirest.get("/api/v3/releases/{releaseId}/vulnerabilities/{vulnId}/headers"); | ||
} | ||
@Override | ||
protected void process(ObjectNode record, JsonNode response) { | ||
record.set("headers", response); | ||
} | ||
} | ||
|
||
private static final class FoDIssueParametersEmbedder extends AbstractFoDIssueEmbedder { | ||
@Override | ||
protected GetRequest getBaseRequest(UnirestInstance unirest) { | ||
return unirest.get("/api/v3/releases/{releaseId}/vulnerabilities/{vulnId}/parameters"); | ||
} | ||
@Override | ||
protected void process(ObjectNode record, JsonNode response) { | ||
record.set("parameters", response); | ||
} | ||
} | ||
|
||
private static final class FoDIssueTracesEmbedder extends AbstractFoDIssueEmbedder { | ||
@Override | ||
protected GetRequest getBaseRequest(UnirestInstance unirest) { | ||
return unirest.get("/api/v3/releases/{releaseId}/vulnerabilities/{vulnId}/traces"); | ||
} | ||
@Override | ||
protected void process(ObjectNode record, JsonNode response) { | ||
record.set("traces", response); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters