From 77fcc1c57f044aa99ba49e77710b98fd062593c0 Mon Sep 17 00:00:00 2001 From: Ruud Senden <8635138+rsenden@users.noreply.github.com> Date: Tue, 24 Sep 2024 09:17:21 +0200 Subject: [PATCH] feat: Add `fcli sc-sast sensor-pool list` command --- .../sc_sast/_main/cli/cmd/SCSastCommands.java | 2 + .../cli/cmd/SCSastSensorPoolCommands.java | 26 +++++++++++++ .../cli/cmd/SCSastSensorPoolListCommand.java | 38 +++++++++++++++++++ .../sc_sast/i18n/SCSastMessages.properties | 5 +++ 4 files changed, 71 insertions(+) create mode 100644 fcli-core/fcli-sc-sast/src/main/java/com/fortify/cli/sc_sast/sensor_pool/cli/cmd/SCSastSensorPoolCommands.java create mode 100644 fcli-core/fcli-sc-sast/src/main/java/com/fortify/cli/sc_sast/sensor_pool/cli/cmd/SCSastSensorPoolListCommand.java diff --git a/fcli-core/fcli-sc-sast/src/main/java/com/fortify/cli/sc_sast/_main/cli/cmd/SCSastCommands.java b/fcli-core/fcli-sc-sast/src/main/java/com/fortify/cli/sc_sast/_main/cli/cmd/SCSastCommands.java index 299f8bf401..71fb7bc4f4 100644 --- a/fcli-core/fcli-sc-sast/src/main/java/com/fortify/cli/sc_sast/_main/cli/cmd/SCSastCommands.java +++ b/fcli-core/fcli-sc-sast/src/main/java/com/fortify/cli/sc_sast/_main/cli/cmd/SCSastCommands.java @@ -17,6 +17,7 @@ import com.fortify.cli.sc_sast.rest.cli.cmd.SCSastControllerRestCommands; import com.fortify.cli.sc_sast.scan.cli.cmd.SCSastScanCommands; import com.fortify.cli.sc_sast.sensor.cli.cmd.SCSastSensorCommands; +import com.fortify.cli.sc_sast.sensor_pool.cli.cmd.SCSastSensorPoolCommands; import picocli.CommandLine.Command; @@ -35,6 +36,7 @@ SCSastSessionCommands.class, SCSastScanCommands.class, SCSastSensorCommands.class, + SCSastSensorPoolCommands.class, SCSastControllerRestCommands.class, } ) diff --git a/fcli-core/fcli-sc-sast/src/main/java/com/fortify/cli/sc_sast/sensor_pool/cli/cmd/SCSastSensorPoolCommands.java b/fcli-core/fcli-sc-sast/src/main/java/com/fortify/cli/sc_sast/sensor_pool/cli/cmd/SCSastSensorPoolCommands.java new file mode 100644 index 0000000000..35af0fd7da --- /dev/null +++ b/fcli-core/fcli-sc-sast/src/main/java/com/fortify/cli/sc_sast/sensor_pool/cli/cmd/SCSastSensorPoolCommands.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * 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.sc_sast.sensor_pool.cli.cmd; + +import com.fortify.cli.common.cli.cmd.AbstractContainerCommand; +import picocli.CommandLine.Command; + +@Command( + name = "sensor-pool", + subcommands = { + SCSastSensorPoolListCommand.class, + } +) + +public class SCSastSensorPoolCommands extends AbstractContainerCommand { +} diff --git a/fcli-core/fcli-sc-sast/src/main/java/com/fortify/cli/sc_sast/sensor_pool/cli/cmd/SCSastSensorPoolListCommand.java b/fcli-core/fcli-sc-sast/src/main/java/com/fortify/cli/sc_sast/sensor_pool/cli/cmd/SCSastSensorPoolListCommand.java new file mode 100644 index 0000000000..c6d325bd9b --- /dev/null +++ b/fcli-core/fcli-sc-sast/src/main/java/com/fortify/cli/sc_sast/sensor_pool/cli/cmd/SCSastSensorPoolListCommand.java @@ -0,0 +1,38 @@ +package com.fortify.cli.sc_sast.sensor_pool.cli.cmd; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fortify.cli.common.json.JsonHelper; +import com.fortify.cli.common.output.cli.mixin.OutputHelperMixins; +import com.fortify.cli.common.output.transform.IInputTransformer; +import com.fortify.cli.sc_sast._common.output.cli.cmd.AbstractSCSastControllerBaseRequestOutputCommand; + +import kong.unirest.HttpRequest; +import kong.unirest.UnirestInstance; +import lombok.Getter; +import picocli.CommandLine.Command; +import picocli.CommandLine.Mixin; + +@Command(name = OutputHelperMixins.List.CMD_NAME) +public class SCSastSensorPoolListCommand extends AbstractSCSastControllerBaseRequestOutputCommand implements IInputTransformer { + + @Getter @Mixin private OutputHelperMixins.List outputHelper; + + + @Override + protected HttpRequest getBaseRequest(UnirestInstance unirest) { + return unirest.get("/rest/v4/info/pools"); + } + + @Override + public JsonNode transformInput(JsonNode input) { + return JsonHelper.evaluateSpelExpression(input, "beans", ArrayNode.class); + } + + @Override + public boolean isSingular() { + return false; + } + + +} diff --git a/fcli-core/fcli-sc-sast/src/main/resources/com/fortify/cli/sc_sast/i18n/SCSastMessages.properties b/fcli-core/fcli-sc-sast/src/main/resources/com/fortify/cli/sc_sast/i18n/SCSastMessages.properties index 32fda1c02c..6b2665ebf0 100644 --- a/fcli-core/fcli-sc-sast/src/main/resources/com/fortify/cli/sc_sast/i18n/SCSastMessages.properties +++ b/fcli-core/fcli-sc-sast/src/main/resources/com/fortify/cli/sc_sast/i18n/SCSastMessages.properties @@ -148,6 +148,10 @@ fcli.sc-sast.sensor.list.usage.header = List ScanCentral SAST sensors fcli.sc-sast.sensor.list.usage.description = This command lists sensor information for all \ available SanCentral SAST sensors. It calls the SSC API and as such requires an active SSC session. +# fcli sc-sast sensor-pool +fcli.sc-sast.sensor-pool.usage.header = Manage ScanCentral SAST sensor pools +fcli.sc-sast.sensor-pool.list.usage.header = List ScanCentral SAST sensor pools + # fcli sc-sast rest fcli.sc-sast.rest.usage.header = Interact with ScanCentral SAST Controller REST API endpoints. fcli.sc-sast.rest.usage.description = These commands allow for direct interaction with ScanCentral SAST \ @@ -186,3 +190,4 @@ fcli.env.default.prefix=FCLI_DEFAULT fcli.sc-sast.session.output.table.options = name,type,url,created,expires,expired fcli.sc-sast.scan.output.table.options = jobToken,hasFiles,scanState,publishState,sscArtifactState,endpointVersion fcli.sc-sast.sensor.output.table.options = hostName,state,cloudPool?.name,ipAddress,scaVersion,lastSeen,workerStartTime +fcli.sc-sast.sensor-pool.output.table.options = uuid,name,description \ No newline at end of file