-
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.
feat:
fcli sc-sast scan start
: Add option to select sensor pool for…
… the scan
- Loading branch information
Showing
5 changed files
with
152 additions
and
4 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
32 changes: 32 additions & 0 deletions
32
.../main/java/com/fortify/cli/sc_sast/sensor_pool/cli/helper/SCSastSensorPoolDescriptor.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,32 @@ | ||
/******************************************************************************* | ||
* 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.helper; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.formkiq.graalvm.annotations.Reflectable; | ||
import com.fortify.cli.common.json.JsonNodeHolder; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.Map; | ||
|
||
@Reflectable @NoArgsConstructor | ||
@Data @EqualsAndHashCode(callSuper=true) | ||
public class SCSastSensorPoolDescriptor extends JsonNodeHolder { | ||
private String uuid; | ||
private String path; | ||
private String name; | ||
private String lastChangedOn; | ||
} |
55 changes: 55 additions & 0 deletions
55
.../src/main/java/com/fortify/cli/sc_sast/sensor_pool/cli/helper/SCSastSensorPoolHelper.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,55 @@ | ||
/******************************************************************************* | ||
* 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.helper; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.ArrayNode; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import com.formkiq.graalvm.annotations.Reflectable; | ||
import com.fortify.cli.common.json.JsonHelper; | ||
import com.fortify.cli.common.output.transform.fields.RenameFieldsTransformer; | ||
import com.fortify.cli.ssc._common.rest.SSCUrls; | ||
import com.fortify.cli.ssc.appversion.helper.SSCAppAndVersionNameDescriptor; | ||
import com.fortify.cli.ssc.appversion.helper.SSCAppVersionDescriptor; | ||
import com.fortify.cli.ssc.system_state.helper.SSCJobDescriptor; | ||
import com.fortify.cli.ssc.system_state.helper.SSCJobHelper; | ||
import kong.unirest.GetRequest; | ||
import kong.unirest.UnirestInstance; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
|
||
public class SCSastSensorPoolHelper { | ||
public static final SCSastSensorPoolDescriptor getRequiredSensorPool(UnirestInstance unirest, String sensorPoolNameOrUuid) { | ||
SCSastSensorPoolDescriptor descriptor = getOptionalSensorPool(unirest, sensorPoolNameOrUuid); | ||
if ( descriptor==null ) { | ||
throw new IllegalArgumentException("No sensor pool found for name or uuid: "+sensorPoolNameOrUuid); | ||
} | ||
return descriptor; | ||
} | ||
|
||
public static final SCSastSensorPoolDescriptor getOptionalSensorPool(UnirestInstance unirest, String sensorPoolNameOrUuid) { | ||
JsonNode sensorPools = getBaseRequest(unirest).asObject(ObjectNode.class).getBody().get("beans"); | ||
JsonNode sensorPool = JsonHelper.evaluateSpelExpression(sensorPools,String.format("#this.?[#this.name=='%s' || #this.uuid=='%s' ]", sensorPoolNameOrUuid, sensorPoolNameOrUuid),ArrayNode.class); | ||
|
||
if ( sensorPool.size()>1 ) { | ||
throw new IllegalArgumentException("Multiple sensor pools found"); | ||
} | ||
|
||
return sensorPool.size()==0 ? null : JsonHelper.treeToValue(sensorPool.get(0), SCSastSensorPoolDescriptor.class); | ||
} | ||
|
||
private static GetRequest getBaseRequest(UnirestInstance unirest) { | ||
GetRequest request = unirest.get("/rest/v4/info/pools"); | ||
return request; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...ain/java/com/fortify/cli/sc_sast/sensor_pool/cli/mixin/SCSastSensorPoolResolverMixin.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,45 @@ | ||
/******************************************************************************* | ||
* 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.mixin; | ||
|
||
import com.fortify.cli.common.cli.util.EnvSuffix; | ||
import com.fortify.cli.sc_sast.sensor_pool.cli.helper.SCSastSensorPoolDescriptor; | ||
import com.fortify.cli.sc_sast.sensor_pool.cli.helper.SCSastSensorPoolHelper; | ||
import kong.unirest.UnirestInstance; | ||
import lombok.Getter; | ||
import picocli.CommandLine.Option; | ||
import picocli.CommandLine.Parameters; | ||
|
||
public class SCSastSensorPoolResolverMixin { | ||
public static abstract class AbstractSCSastSensorPoolResolverMixin { | ||
public abstract String getSensorPoolNameOrUuid(); | ||
|
||
public SCSastSensorPoolDescriptor getSensorPoolDescriptor(UnirestInstance unirest){ | ||
return SCSastSensorPoolHelper.getRequiredSensorPool(unirest, getSensorPoolNameOrUuid()); | ||
} | ||
|
||
public String getSensorPoolUuid(UnirestInstance unirest) { | ||
return getSensorPoolDescriptor(unirest).getUuid(); | ||
} | ||
} | ||
|
||
public static class RequiredOption extends AbstractSCSastSensorPoolResolverMixin { | ||
@Option(names = {"--sensor-pool"}, required = true, descriptionKey = "fcli.sc-sast.sensor-pool.resolver.nameOrUuid") | ||
@Getter private String sensorPoolNameOrUuid; | ||
} | ||
|
||
public static class PositionalParameter extends AbstractSCSastSensorPoolResolverMixin { | ||
@EnvSuffix("SENSORPOOL") @Parameters(index = "0", arity = "1", descriptionKey = "fcli.sc-sast.sensor-pool.resolver.nameOrUuid") | ||
@Getter private String sensorPoolNameOrUuid; | ||
} | ||
} |
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