diff --git a/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/_common/rest/helper/FoDErrorResponse.java b/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/_common/rest/helper/FoDErrorResponse.java deleted file mode 100644 index b9c24bf8b5..0000000000 --- a/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/_common/rest/helper/FoDErrorResponse.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * 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.helper; - -import java.util.ArrayList; - -import com.formkiq.graalvm.annotations.Reflectable; -import com.fortify.cli.common.json.JsonNodeHolder; - -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - -@Reflectable @NoArgsConstructor -@Data @EqualsAndHashCode(callSuper=false) -public class FoDErrorResponse extends JsonNodeHolder { - ArrayList errors; - @Data - public class FoDError { - int errorCode; - String message; - } - - @Override - public String toString() { - String result = "\n"; - for (FoDError error : errors) { - int errorNumber = errors.indexOf(error) + 1; - result += errorNumber + ") " + error.getMessage() + (errorNumber > 1 ? "\n" : ""); - } - return result; - } -} - - diff --git a/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/_common/rest/helper/FoDUploadResponse.java b/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/_common/rest/helper/FoDUploadResponse.java deleted file mode 100644 index 8100c5b07f..0000000000 --- a/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/_common/rest/helper/FoDUploadResponse.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * 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.helper; - -import java.util.ArrayList; - -import com.formkiq.graalvm.annotations.Reflectable; -import com.fortify.cli.common.json.JsonNodeHolder; - -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - -@Reflectable @NoArgsConstructor -@Data @EqualsAndHashCode(callSuper = false) -public class FoDUploadResponse extends JsonNodeHolder { - Integer scanId; - ArrayList messages; - String referenceId; -} diff --git a/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/assessment_type/helper/FoDAssessmentTypeHelper.java b/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/assessment_type/helper/FoDAssessmentTypeHelper.java index 96aa079ba6..2b69567d65 100644 --- a/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/assessment_type/helper/FoDAssessmentTypeHelper.java +++ b/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/assessment_type/helper/FoDAssessmentTypeHelper.java @@ -12,23 +12,22 @@ */ package com.fortify.cli.fod.assessment_type.helper; +import java.time.Instant; +import java.util.Date; + import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fortify.cli.common.json.JsonHelper; import com.fortify.cli.common.progress.helper.IProgressWriterI18n; import com.fortify.cli.fod._common.rest.FoDUrls; import com.fortify.cli.fod._common.util.FoDEnums; import com.fortify.cli.fod.scan.helper.FoDScanType; + import kong.unirest.GetRequest; import kong.unirest.UnirestInstance; import lombok.Getter; -import java.time.Instant; -import java.util.Date; -import java.util.Optional; - public final class FoDAssessmentTypeHelper { @Getter private static final ObjectMapper objectMapper = new ObjectMapper(); diff --git a/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/scan/cli/cmd/FoDScanStartDastCommand.java b/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/scan/cli/cmd/FoDScanStartDastCommand.java index 57b4b2507b..9237a8eeac 100644 --- a/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/scan/cli/cmd/FoDScanStartDastCommand.java +++ b/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/scan/cli/cmd/FoDScanStartDastCommand.java @@ -13,6 +13,13 @@ package com.fortify.cli.fod.scan.cli.cmd; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Arrays; +import java.util.Objects; +import java.util.Optional; +import java.util.Properties; + import com.fasterxml.jackson.databind.JsonNode; import com.fortify.cli.common.output.transform.IActionCommandResultSupplier; import com.fortify.cli.common.output.transform.IRecordTransformer; @@ -34,19 +41,13 @@ import com.fortify.cli.fod.scan.helper.dast.FoDScanDastStartRequest; import com.fortify.cli.fod.scan_config.helper.FoDScanConfigDastDescriptor; import com.fortify.cli.fod.scan_config.helper.FoDScanConfigDastHelper; + import kong.unirest.UnirestInstance; import lombok.Getter; import picocli.CommandLine.Command; import picocli.CommandLine.Mixin; import picocli.CommandLine.Option; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.Arrays; -import java.util.Objects; -import java.util.Optional; -import java.util.Properties; - @Command(name = FoDOutputHelperMixins.StartDast.CMD_NAME) public class FoDScanStartDastCommand extends AbstractFoDJsonNodeOutputCommand implements IRecordTransformer, IActionCommandResultSupplier { DateTimeFormatter dtf = DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm"); diff --git a/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/scan/cli/cmd/FoDScanStartMobileCommand.java b/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/scan/cli/cmd/FoDScanStartMobileCommand.java index fe97be00a6..d18bb77b41 100644 --- a/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/scan/cli/cmd/FoDScanStartMobileCommand.java +++ b/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/scan/cli/cmd/FoDScanStartMobileCommand.java @@ -13,6 +13,14 @@ package com.fortify.cli.fod.scan.cli.cmd; +import java.io.File; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Arrays; +import java.util.Objects; +import java.util.Optional; +import java.util.Properties; + import com.fasterxml.jackson.databind.JsonNode; import com.fortify.cli.common.output.transform.IActionCommandResultSupplier; import com.fortify.cli.common.output.transform.IRecordTransformer; @@ -31,29 +39,20 @@ import com.fortify.cli.fod.scan.helper.FoDScanType; import com.fortify.cli.fod.scan.helper.mobile.FoDScanMobileHelper; import com.fortify.cli.fod.scan.helper.mobile.FoDScanMobileStartRequest; + import kong.unirest.UnirestInstance; import lombok.Getter; import picocli.CommandLine.Command; import picocli.CommandLine.Mixin; import picocli.CommandLine.Option; -import java.io.File; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.Arrays; -import java.util.Objects; -import java.util.Optional; -import java.util.Properties; - @Command(name = FoDOutputHelperMixins.StartMobile.CMD_NAME) public class FoDScanStartMobileCommand extends AbstractFoDJsonNodeOutputCommand implements IRecordTransformer, IActionCommandResultSupplier { DateTimeFormatter dtf = DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm"); @Getter @Mixin private FoDOutputHelperMixins.StartMobile outputHelper; @Mixin private FoDDelimiterMixin delimiterMixin; // Is automatically injected in resolver mixins @Mixin private FoDReleaseByQualifiedNameOrIdResolverMixin.PositionalParameter releaseResolver; - private enum MobileAssessmentTypes { Mobile, MobilePlus, Remediation } @Option(names = {"--assessment-type"}, required = true) - //private MobileAssessmentTypes mobileAssessmentType; private String mobileAssessmentType; @Option(names = {"--entitlement-id"}) private Integer entitlementId; diff --git a/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/scan/cli/cmd/FoDScanStartSastCommand.java b/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/scan/cli/cmd/FoDScanStartSastCommand.java index 7b6ff8f2d4..8e12ff4adf 100644 --- a/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/scan/cli/cmd/FoDScanStartSastCommand.java +++ b/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/scan/cli/cmd/FoDScanStartSastCommand.java @@ -13,6 +13,9 @@ package com.fortify.cli.fod.scan.cli.cmd; +import java.io.File; +import java.util.Properties; + import com.fasterxml.jackson.databind.JsonNode; import com.fortify.cli.common.output.transform.IActionCommandResultSupplier; import com.fortify.cli.common.output.transform.IRecordTransformer; @@ -28,15 +31,13 @@ import com.fortify.cli.fod.scan.helper.sast.FoDScanSastHelper; import com.fortify.cli.fod.scan.helper.sast.FoDScanSastStartRequest; import com.fortify.cli.fod.scan_config.helper.FoDScanConfigSastDescriptor; + import kong.unirest.UnirestInstance; import lombok.Getter; import picocli.CommandLine.Command; import picocli.CommandLine.Mixin; import picocli.CommandLine.Option; -import java.io.File; -import java.util.Properties; - @Command(name = FoDOutputHelperMixins.StartSast.CMD_NAME) public class FoDScanStartSastCommand extends AbstractFoDJsonNodeOutputCommand implements IRecordTransformer, IActionCommandResultSupplier { @Getter @Mixin private FoDOutputHelperMixins.StartSast outputHelper; diff --git a/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/scan/helper/FoDScanHelper.java b/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/scan/helper/FoDScanHelper.java index 12d216aec2..56c220effb 100644 --- a/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/scan/helper/FoDScanHelper.java +++ b/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/scan/helper/FoDScanHelper.java @@ -13,6 +13,10 @@ package com.fortify.cli.fod.scan.helper; +import static java.util.function.Predicate.not; + +import java.util.Optional; + import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -20,21 +24,14 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import com.fortify.cli.common.json.JsonHelper; import com.fortify.cli.common.output.transform.fields.RenameFieldsTransformer; -import com.fortify.cli.common.progress.helper.IProgressWriterI18n; import com.fortify.cli.fod._common.rest.FoDUrls; -import com.fortify.cli.fod._common.util.FoDEnums; -import com.fortify.cli.fod.assessment_type.helper.FoDAssessmentTypeDescriptor; -import com.fortify.cli.fod.assessment_type.helper.FoDAssessmentTypeHelper; import com.fortify.cli.fod.rest.lookup.helper.FoDLookupDescriptor; import com.fortify.cli.fod.rest.lookup.helper.FoDLookupHelper; import com.fortify.cli.fod.rest.lookup.helper.FoDLookupType; + import kong.unirest.UnirestInstance; import lombok.Getter; -import java.util.Optional; - -import static java.util.function.Predicate.not; - // TODO Class contains some fairly long methods; consider splitting methods public class FoDScanHelper { @Getter diff --git a/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/scan/helper/mobile/FoDScanMobileHelper.java b/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/scan/helper/mobile/FoDScanMobileHelper.java index 0bb31e6dc3..7897465505 100644 --- a/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/scan/helper/mobile/FoDScanMobileHelper.java +++ b/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/scan/helper/mobile/FoDScanMobileHelper.java @@ -21,11 +21,11 @@ import com.fortify.cli.common.progress.helper.IProgressWriterI18n; import com.fortify.cli.fod._common.rest.FoDUrls; import com.fortify.cli.fod._common.rest.helper.FoDFileTransferHelper; -import com.fortify.cli.fod._common.rest.helper.FoDUploadResponse; import com.fortify.cli.fod.release.helper.FoDReleaseDescriptor; import com.fortify.cli.fod.scan.helper.FoDScanDescriptor; import com.fortify.cli.fod.scan.helper.FoDScanHelper; import com.fortify.cli.fod.scan.helper.FoDScanType; +import com.fortify.cli.fod.scan.helper.FoDStartScanResponse; import kong.unirest.HttpRequest; import kong.unirest.UnirestInstance; @@ -50,8 +50,8 @@ public static final FoDScanDescriptor startScan(UnirestInstance unirest, IProgre request = request.queryString("entitlementId", req.getEntitlementId()); } - JsonNode uploadResponse = FoDFileTransferHelper.uploadChunked(unirest, request, scanFile); - FoDUploadResponse startScanResponse = JsonHelper.treeToValue(uploadResponse, FoDUploadResponse.class); + JsonNode response = FoDFileTransferHelper.uploadChunked(unirest, request, scanFile); + FoDStartScanResponse startScanResponse = JsonHelper.treeToValue(response, FoDStartScanResponse.class); if (startScanResponse == null || startScanResponse.getScanId() <= 0) { throw new RuntimeException("Unable to retrieve scan id from response when starting Static scan."); } diff --git a/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/scan/helper/sast/FoDScanSastHelper.java b/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/scan/helper/sast/FoDScanSastHelper.java index 8b669a656e..4c557c7036 100644 --- a/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/scan/helper/sast/FoDScanSastHelper.java +++ b/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/scan/helper/sast/FoDScanSastHelper.java @@ -13,6 +13,8 @@ package com.fortify.cli.fod.scan.helper.sast; +import java.io.File; + import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -20,21 +22,20 @@ import com.fortify.cli.common.util.StringUtils; import com.fortify.cli.fod._common.rest.FoDUrls; import com.fortify.cli.fod._common.rest.helper.FoDFileTransferHelper; -import com.fortify.cli.fod._common.rest.helper.FoDUploadResponse; import com.fortify.cli.fod._common.util.FoDConstants; import com.fortify.cli.fod._common.util.FoDEnums; import com.fortify.cli.fod.release.helper.FoDReleaseDescriptor; import com.fortify.cli.fod.scan.helper.FoDScanDescriptor; import com.fortify.cli.fod.scan.helper.FoDScanHelper; import com.fortify.cli.fod.scan.helper.FoDScanType; +import com.fortify.cli.fod.scan.helper.FoDStartScanResponse; import com.fortify.cli.fod.scan_config.helper.FoDScanConfigSastDescriptor; + import kong.unirest.GetRequest; import kong.unirest.HttpRequest; import kong.unirest.UnirestInstance; import lombok.Getter; -import java.io.File; - public class FoDScanSastHelper extends FoDScanHelper { @Getter private static final ObjectMapper objectMapper = new ObjectMapper(); @@ -79,8 +80,8 @@ public static final FoDScanDescriptor startScanAdvanced(UnirestInstance unirest, } private static FoDScanDescriptor startScan(UnirestInstance unirest, FoDReleaseDescriptor releaseDescriptor, HttpRequest request, File scanFile) { - JsonNode uploadResponse = FoDFileTransferHelper.uploadChunked(unirest, request, scanFile); - FoDUploadResponse startScanResponse = JsonHelper.treeToValue(uploadResponse, FoDUploadResponse.class); + JsonNode response = FoDFileTransferHelper.uploadChunked(unirest, request, scanFile); + FoDStartScanResponse startScanResponse = JsonHelper.treeToValue(response, FoDStartScanResponse.class); if (startScanResponse == null || startScanResponse.getScanId() <= 0) { throw new RuntimeException("Unable to retrieve scan id from response when starting Static scan."); }