Skip to content

Commit

Permalink
chore: FoD refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
rsenden committed Aug 9, 2023
1 parent ee4a823 commit faefbb5
Show file tree
Hide file tree
Showing 38 changed files with 484 additions and 355 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,6 @@ public static <T> T jsonStringToValue(String jsonString, Class<T> returnType) {
}
}

public static final void stripNulls(JsonNode node) {
Iterator<JsonNode> it = node.iterator();
while (it.hasNext()) {
JsonNode child = it.next();
if (child.isNull())
it.remove();
else
stripNulls(child);
}
}

private static final class ArrayNodeCollector implements Collector<JsonNode, ArrayNode, ArrayNode> {
@Override
public Supplier<ArrayNode> supplier() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,60 @@
import com.fortify.cli.common.output.cli.mixin.IOutputHelper;
import com.fortify.cli.common.output.cli.mixin.OutputHelperMixins;

import picocli.CommandLine.Command;

/**
* <p>This class provides FoD-specific {@link IOutputHelper} implementations.</p>
*
* @author rsenden
*/
public class FoDOutputHelperMixins {
public static class SetupSast extends OutputHelperMixins.TableNoQuery {
public static class SetupSast extends OutputHelperMixins.DetailsNoQuery {
public static final String CMD_NAME = "setup-sast";
}
public static class SetupDast extends OutputHelperMixins.TableNoQuery {
public static class SetupDast extends OutputHelperMixins.DetailsNoQuery {
public static final String CMD_NAME = "setup-dast";
}
public static class SetupOss extends OutputHelperMixins.TableNoQuery {
public static final String CMD_NAME = "setup-oss";
}
public static class SetupMobile extends OutputHelperMixins.TableNoQuery {
public static class SetupMobile extends OutputHelperMixins.DetailsNoQuery {
public static final String CMD_NAME = "setup-mobile";
}
public static class GetSast extends OutputHelperMixins.DetailsNoQuery {
public static final String CMD_NAME = "get-sast";
}
public static class GetDast extends OutputHelperMixins.DetailsNoQuery {
public static final String CMD_NAME = "get-dast";
}
public static class GetMobile extends OutputHelperMixins.DetailsNoQuery {
public static final String CMD_NAME = "get-mobile";
}

public static class StartSast extends OutputHelperMixins.TableNoQuery {
public static class StartSast extends OutputHelperMixins.TableNoQuery {
public static final String CMD_NAME = "start-sast";
}
public static class StartDast extends OutputHelperMixins.TableNoQuery {
public static class StartDast extends OutputHelperMixins.TableNoQuery {
public static final String CMD_NAME = "start-dast";
}
public static class StartOss extends OutputHelperMixins.TableNoQuery {
public static final String CMD_NAME = "start-oss";
}
public static class StartMobile extends OutputHelperMixins.TableNoQuery {
public static class StartMobile extends OutputHelperMixins.TableNoQuery {
public static final String CMD_NAME = "start-mobile";
}

public static class ImportScan extends OutputHelperMixins.TableNoQuery {
public static final String CMD_NAME = "import-scan";
}

public static class ImportSast extends OutputHelperMixins.TableNoQuery {
public static final String CMD_NAME = "import-sast";
}
public static class ImportDast extends OutputHelperMixins.TableNoQuery {
public static final String CMD_NAME = "import-dast";
}
public static class ImportMobile extends OutputHelperMixins.TableNoQuery {
public static final String CMD_NAME = "import-mobile";
}
@Command(aliases = "import-oss")
public static class ImportOpenSource extends OutputHelperMixins.TableNoQuery {
public static final String CMD_NAME = "import-open-source";
}

public static class Lookup extends OutputHelperMixins.TableWithQuery {
public static final String CMD_NAME = "lookup";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.fortify.cli.fod.release.cli.cmd.FoDReleaseCommands;
import com.fortify.cli.fod.rest.cli.cmd.FoDRestCommands;
import com.fortify.cli.fod.scan.cli.cmd.FoDScanCommands;
import com.fortify.cli.fod.scan_import.cli.cmd.FoDScanImportCommands;
import com.fortify.cli.fod.scan_setup.cli.cmd.FoDScanSetupCommands;
import com.fortify.cli.fod.user.cli.cmd.FoDUserCommands;
import com.fortify.cli.fod.user_group.cli.cmd.FoDUserGroupCommands;

Expand All @@ -41,6 +43,8 @@
FoDReleaseCommands.class,
FoDMicroserviceCommands.class,
FoDScanCommands.class,
FoDScanImportCommands.class,
FoDScanSetupCommands.class,
FoDUserCommands.class,
FoDUserGroupCommands.class,
FoDRestCommands.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
FoDReleaseCreateCommand.class,
FoDReleaseListCommand.class,
FoDReleaseGetCommand.class,
FoDReleaseImportScanCommand.class,
FoDReleaseUpdateCommand.class,
FoDReleaseDeleteCommand.class
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@

import com.fortify.cli.common.cli.cmd.AbstractContainerCommand;
import com.fortify.cli.common.variable.DefaultVariablePropertyName;
import com.fortify.cli.fod.scan.cli.cmd.dast.FoDDastScanStartCommand;
import com.fortify.cli.fod.scan.cli.cmd.mobile.FoDMobileScanStartCommand;
import com.fortify.cli.fod.scan.cli.cmd.sast.FoDSastScanSetupCommand;
import com.fortify.cli.fod.scan.cli.cmd.sast.FoDSastScanStartCommand;

import picocli.CommandLine;

Expand All @@ -27,10 +23,9 @@
FoDScanCancelCommand.class,
FoDScanGetCommand.class,
FoDScanListCommand.class,
FoDSastScanSetupCommand.class,
FoDSastScanStartCommand.class,
FoDDastScanStartCommand.class,
FoDMobileScanStartCommand.class,
FoDScanStartSastCommand.class,
FoDScanStartDastCommand.class,
FoDScanStartMobileCommand.class,
FoDScanWaitForCommand.class
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* without notice.
*******************************************************************************/

package com.fortify.cli.fod.scan.cli.cmd.dast;
package com.fortify.cli.fod.scan.cli.cmd;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
Expand All @@ -37,9 +37,10 @@
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.dast.FoDDastScanHelper;
import com.fortify.cli.fod.scan.helper.dast.FoDDastScanSetupDescriptor;
import com.fortify.cli.fod.scan.helper.dast.FoDStartDastScanRequest;
import com.fortify.cli.fod.scan.helper.dast.FoDScanDastHelper;
import com.fortify.cli.fod.scan.helper.dast.FoDScanDastStartRequest;
import com.fortify.cli.fod.scan_setup.helper.FoDScanDastSetupDescriptor;
import com.fortify.cli.fod.scan_setup.helper.FoDScanDastSetupHelper;

import kong.unirest.UnirestInstance;
import lombok.Getter;
Expand All @@ -48,7 +49,7 @@
import picocli.CommandLine.Option;

@Command(name = FoDOutputHelperMixins.StartDast.CMD_NAME)
public class FoDDastScanStartCommand extends AbstractFoDJsonNodeOutputCommand implements IRecordTransformer, IActionCommandResultSupplier {
public class FoDScanStartDastCommand extends AbstractFoDJsonNodeOutputCommand implements IRecordTransformer, IActionCommandResultSupplier {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm");
@Getter @Mixin private FoDOutputHelperMixins.StartDast outputHelper;
@Mixin private FoDDelimiterMixin delimiterMixin; // Is automatically injected in resolver mixins
Expand Down Expand Up @@ -99,7 +100,7 @@ public JsonNode getJsonNode(UnirestInstance unirest) {

var relId = String.valueOf(releaseDescriptor.getReleaseId());
// get current setup and check if its valid
FoDDastScanSetupDescriptor currentSetup = FoDDastScanHelper.getSetupDescriptor(unirest, relId);
FoDScanDastSetupDescriptor currentSetup = FoDScanDastSetupHelper.getSetupDescriptor(unirest, relId);
if (StringUtils.isBlank(currentSetup.getDynamicSiteURL())) {
throw new IllegalStateException("The dynamic scan configuration for release with id '" + relId +
"' has not been setup correctly - 'Dynamic Site URL' is missing or empty.");
Expand All @@ -119,11 +120,11 @@ public JsonNode getJsonNode(UnirestInstance unirest) {
} else if (remediationScanType.getRemediationScanPreferenceType() != null &&
(remediationScanType.getRemediationScanPreferenceType() == FoDEnums.RemediationScanPreferenceType.RemediationScanOnly)) {
// if requesting a remediation scan make we have one available
entitlementToUse = FoDDastScanHelper.validateRemediationEntitlement(unirest, progressWriter, relId,
entitlementToUse = FoDScanDastHelper.validateRemediationEntitlement(unirest, progressWriter, relId,
currentSetup.getEntitlementId(), FoDScanType.Dynamic);
} else if (assessmentType != null && entitlementType.getEntitlementPreferenceType() != null) {
// if assessment and entitlement type are both specified, find entitlement to use
entitlementToUse = FoDDastScanHelper.getEntitlementToUse(unirest, progressWriter, relId,
entitlementToUse = FoDScanDastHelper.getEntitlementToUse(unirest, progressWriter, relId,
assessmentType, entitlementType.getEntitlementPreferenceType(),
FoDScanType.Dynamic);
} else {
Expand All @@ -138,7 +139,7 @@ public JsonNode getJsonNode(UnirestInstance unirest) {
String startDateStr = (startDate == null || startDate.isEmpty())
? LocalDateTime.now().format(dtf)
: LocalDateTime.parse(startDate, dtf).toString();
FoDStartDastScanRequest startScanRequest = FoDStartDastScanRequest.builder()
FoDScanDastStartRequest startScanRequest = FoDScanDastStartRequest.builder()
.startDate(startDateStr)
.assessmentTypeId(entitlementToUse.getAssessmentTypeId())
.entitlementId(entitlementToUse.getEntitlementId())
Expand All @@ -150,7 +151,7 @@ public JsonNode getJsonNode(UnirestInstance unirest) {
.scanToolVersion(fcliProperties.getProperty("projectVersion", "unknown")).build();

//System.out.println(startScanRequest);
return FoDDastScanHelper.startScan(unirest, releaseDescriptor, startScanRequest).asJsonNode();
return FoDScanDastHelper.startScan(unirest, releaseDescriptor, startScanRequest).asJsonNode();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* without notice.
*******************************************************************************/

package com.fortify.cli.fod.scan.cli.cmd.mobile;
package com.fortify.cli.fod.scan.cli.cmd;

import java.io.File;
import java.time.LocalDateTime;
Expand All @@ -38,8 +38,8 @@
import com.fortify.cli.fod.scan.helper.FoDAssessmentTypeDescriptor;
import com.fortify.cli.fod.scan.helper.FoDScanHelper;
import com.fortify.cli.fod.scan.helper.FoDScanType;
import com.fortify.cli.fod.scan.helper.mobile.FoDMobileScanHelper;
import com.fortify.cli.fod.scan.helper.mobile.FoDStartMobileScanRequest;
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;
Expand All @@ -48,7 +48,7 @@
import picocli.CommandLine.Option;

@Command(name = FoDOutputHelperMixins.StartMobile.CMD_NAME)
public class FoDMobileScanStartCommand extends AbstractFoDJsonNodeOutputCommand implements IRecordTransformer, IActionCommandResultSupplier {
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
Expand Down Expand Up @@ -101,7 +101,7 @@ public JsonNode getJsonNode(UnirestInstance unirest) {
? LocalDateTime.now().format(dtf)
: LocalDateTime.parse(startDate, dtf).toString();

FoDStartMobileScanRequest startScanRequest = FoDStartMobileScanRequest.builder()
FoDScanMobileStartRequest startScanRequest = FoDScanMobileStartRequest.builder()
.startDate(startDateStr)
.assessmentTypeId(entitlementToUse.getAssessmentTypeId())
.entitlementId(entitlementToUse.getEntitlementId())
Expand All @@ -113,7 +113,7 @@ public JsonNode getJsonNode(UnirestInstance unirest) {
.scanTool(fcliProperties.getProperty("projectName", "fcli"))
.scanToolVersion(fcliProperties.getProperty("projectVersion", "unknown")).build();

return FoDMobileScanHelper.startScan(unirest, progressWriter, releaseDescriptor, startScanRequest, scanFile).asJsonNode();
return FoDScanMobileHelper.startScan(unirest, progressWriter, releaseDescriptor, startScanRequest, scanFile).asJsonNode();
}
}

Expand Down Expand Up @@ -148,7 +148,7 @@ private FoDAssessmentTypeDescriptor getEntitlementToUse(UnirestInstance unirest,
// if assessment and entitlement type are both specified, find entitlement to use
FoDAssessmentType assessmentType = FoDAssessmentType.valueOf(String.valueOf(mobileAssessmentType));
FoDEnums.EntitlementPreferenceType entitlementPreferenceType = FoDEnums.EntitlementPreferenceType.fromInt(entitlementFrequencyTypeMixin.getEntitlementFrequencyType().getValue());
entitlementToUse = FoDMobileScanHelper.getEntitlementToUse(unirest, progressWriter, relId,
entitlementToUse = FoDScanMobileHelper.getEntitlementToUse(unirest, progressWriter, relId,
assessmentType, entitlementPreferenceType,
FoDScanType.Mobile);

Expand Down
Loading

0 comments on commit faefbb5

Please sign in to comment.