-
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.
Merge pull request #458 from kadraman/fod-2.0-stabilization
FoD 2.0 stabilization
- Loading branch information
Showing
26 changed files
with
443 additions
and
181 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
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
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
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
77 changes: 77 additions & 0 deletions
77
...e/fcli-fod/src/main/java/com/fortify/cli/fod/oss_scan/cli/cmd/FoDOssScanStartCommand.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,77 @@ | ||
/******************************************************************************* | ||
* 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.oss_scan.cli.cmd; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fortify.cli.common.output.cli.mixin.OutputHelperMixins; | ||
import com.fortify.cli.common.output.transform.IActionCommandResultSupplier; | ||
import com.fortify.cli.common.output.transform.IRecordTransformer; | ||
import com.fortify.cli.common.util.FcliBuildPropertiesHelper; | ||
import com.fortify.cli.common.util.StringUtils; | ||
import com.fortify.cli.fod._common.cli.mixin.FoDDelimiterMixin; | ||
import com.fortify.cli.fod._common.output.cli.AbstractFoDJsonNodeOutputCommand; | ||
import com.fortify.cli.fod._common.util.FoDEnums; | ||
import com.fortify.cli.fod.release.cli.mixin.FoDReleaseByQualifiedNameOrIdResolverMixin; | ||
import com.fortify.cli.fod.sast_scan.helper.FoDScanConfigSastDescriptor; | ||
import com.fortify.cli.fod.scan.cli.mixin.FoDRemediationScanPreferenceTypeMixins; | ||
import com.fortify.cli.fod.scan.helper.FoDScanHelper; | ||
import com.fortify.cli.fod.scan.helper.oss.FoDScanOssHelper; | ||
import com.fortify.cli.fod.scan.helper.oss.FoDScanOssStartRequest; | ||
import com.fortify.cli.fod.scan.helper.sast.FoDScanSastHelper; | ||
import com.fortify.cli.fod.scan.helper.sast.FoDScanSastStartRequest; | ||
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 = OutputHelperMixins.Start.CMD_NAME, hidden = false) | ||
public class FoDOssScanStartCommand extends AbstractFoDJsonNodeOutputCommand implements IRecordTransformer, IActionCommandResultSupplier { | ||
@Getter @Mixin private OutputHelperMixins.Start outputHelper; | ||
|
||
@Mixin private FoDDelimiterMixin delimiterMixin; // Is automatically injected in resolver mixins | ||
@Mixin private FoDReleaseByQualifiedNameOrIdResolverMixin.RequiredOption releaseResolver; | ||
|
||
@Option(names = {"-f", "--file"}, required = true) | ||
private File scanFile; | ||
|
||
@Override | ||
public JsonNode getJsonNode(UnirestInstance unirest) { | ||
var releaseDescriptor = releaseResolver.getReleaseDescriptor(unirest); | ||
String relId = releaseDescriptor.getReleaseId(); | ||
|
||
FoDScanOssStartRequest startScanRequest = FoDScanOssStartRequest.builder().build(); | ||
|
||
return FoDScanOssHelper.startScanWithDefaults(unirest, releaseDescriptor, startScanRequest, scanFile).asJsonNode(); | ||
} | ||
|
||
@Override | ||
public JsonNode transformRecord(JsonNode record) { | ||
return FoDScanHelper.renameFields(record); | ||
} | ||
|
||
@Override | ||
public String getActionCommandResult() { | ||
return "STARTED"; | ||
} | ||
|
||
@Override | ||
public boolean isSingular() { | ||
return true; | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
...cli-fod/src/main/java/com/fortify/cli/fod/oss_scan/helper/FoDScanConfigOssDescriptor.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,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.fod.oss_scan.helper; | ||
|
||
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 FoDScanConfigOssDescriptor extends JsonNodeHolder { | ||
private Integer releaseId; | ||
} |
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
28 changes: 28 additions & 0 deletions
28
...core/fcli-fod/src/main/java/com/fortify/cli/fod/scan/helper/oss/FoDScanOssDescriptor.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.scan.helper.oss; | ||
|
||
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 = true) | ||
public class FoDScanOssDescriptor extends JsonNodeHolder { | ||
private Integer scanId; | ||
private String scanType; | ||
|
||
} |
80 changes: 80 additions & 0 deletions
80
fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/scan/helper/oss/FoDScanOssHelper.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,80 @@ | ||
/******************************************************************************* | ||
* 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.scan.helper.oss; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import com.fortify.cli.common.json.JsonHelper; | ||
import com.fortify.cli.fod._common.rest.FoDUrls; | ||
import com.fortify.cli.fod._common.rest.helper.FoDFileTransferHelper; | ||
import com.fortify.cli.fod.oss_scan.helper.FoDScanConfigOssDescriptor; | ||
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.GetRequest; | ||
import kong.unirest.HttpRequest; | ||
import kong.unirest.UnirestInstance; | ||
import lombok.Getter; | ||
|
||
import java.io.File; | ||
|
||
public class FoDScanOssHelper extends FoDScanHelper { | ||
@Getter | ||
private static final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
public static final FoDScanDescriptor startScanWithDefaults(UnirestInstance unirest, FoDReleaseDescriptor releaseDescriptor, | ||
FoDScanOssStartRequest req, File scanFile) { | ||
var relId = releaseDescriptor.getReleaseId(); | ||
HttpRequest<?> request = unirest.post(FoDUrls.OSS_SCANS_START).routeParam("relId", relId); | ||
return startScan(unirest, releaseDescriptor, request, scanFile); | ||
} | ||
|
||
private static FoDScanDescriptor startScan(UnirestInstance unirest, FoDReleaseDescriptor releaseDescriptor, HttpRequest<?> request, File scanFile) { | ||
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 OSS scan."); | ||
} | ||
JsonNode node = objectMapper.createObjectNode() | ||
.put("scanId", startScanResponse.getScanId()) | ||
.put("scanType", FoDScanType.OpenSource.name()) | ||
.put("analysisStatusType", "Pending") | ||
.put("applicationName", releaseDescriptor.getApplicationName()) | ||
.put("releaseName", releaseDescriptor.getReleaseName()) | ||
.put("microserviceName", releaseDescriptor.getMicroserviceName()); | ||
return JsonHelper.treeToValue(node, FoDScanDescriptor.class); | ||
} | ||
|
||
public static final FoDScanConfigOssDescriptor getSetupDescriptor(UnirestInstance unirest, String relId) { | ||
GetRequest request = unirest.get(FoDUrls.OSS_SCANS + "/scan-setup") | ||
.routeParam("relId", relId); | ||
JsonNode setup = request.asObject(ObjectNode.class).getBody() | ||
.put("applicationName", "test"); | ||
return JsonHelper.treeToValue(setup, FoDScanConfigOssDescriptor.class); | ||
} | ||
|
||
public static final FoDScanConfigOssDescriptor getSetupDescriptorWithAppRel(UnirestInstance unirest, FoDReleaseDescriptor releaseDescriptor) { | ||
GetRequest request = unirest.get(FoDUrls.OSS_SCANS + "/scan-setup") | ||
.routeParam("relId", releaseDescriptor.getReleaseId()); | ||
JsonNode setup = request.asObject(ObjectNode.class).getBody() | ||
.put("applicationName", releaseDescriptor.getApplicationName()) | ||
.put("releaseName", releaseDescriptor.getReleaseName()) | ||
.put("microserviceName", releaseDescriptor.getMicroserviceName()); | ||
return JsonHelper.treeToValue(setup, FoDScanConfigOssDescriptor.class); | ||
} | ||
|
||
} |
Oops, something went wrong.