-
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: Add `fcli ssc action` commands for running a variety of yaml-based actions feat: Add `fcli fod action` commands for running a variety of yaml-based actions feat: Migrate FortifyVulnerabilityExporter functionality to yaml-based fcli actions feat: Add preview actions for generating GitHub Pull Request comments
- Loading branch information
Showing
123 changed files
with
6,611 additions
and
132 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
task zipResources_templates(type: Zip) { | ||
destinationDirectory = file("${buildDir}/generated-zip-resources/com/fortify/cli/common") | ||
archiveFileName = "actions.zip" | ||
from("${projectDir}/src/main/resources//com/fortify/cli/common/actions/zip") | ||
} | ||
|
||
apply from: "${sharedGradleScriptsDir}/fcli-java.gradle" |
30 changes: 30 additions & 0 deletions
30
...-common/src/main/java/com/fortify/cli/common/action/cli/cmd/AbstractActionGetCommand.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,30 @@ | ||
/******************************************************************************* | ||
* 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.common.action.cli.cmd; | ||
|
||
import com.fortify.cli.common.action.helper.ActionHelper; | ||
import com.fortify.cli.common.cli.cmd.AbstractRunnableCommand; | ||
|
||
import picocli.CommandLine.Parameters; | ||
|
||
public abstract class AbstractActionGetCommand extends AbstractRunnableCommand implements Runnable { | ||
@Parameters(arity="1", descriptionKey="fcli.action.run.action") private String action; | ||
|
||
@Override | ||
public final void run() { | ||
initMixins(); | ||
System.out.println(ActionHelper.loadContents(getType(), action)); | ||
} | ||
|
||
protected abstract String getType(); | ||
} |
47 changes: 47 additions & 0 deletions
47
...common/src/main/java/com/fortify/cli/common/action/cli/cmd/AbstractActionHelpCommand.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,47 @@ | ||
/******************************************************************************* | ||
* 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.common.action.cli.cmd; | ||
|
||
import com.fortify.cli.common.action.helper.ActionDescriptor; | ||
import com.fortify.cli.common.action.helper.ActionHelper; | ||
import com.fortify.cli.common.action.helper.ActionParameterHelper; | ||
import com.fortify.cli.common.cli.cmd.AbstractRunnableCommand; | ||
|
||
import picocli.CommandLine.Parameters; | ||
import picocli.CommandLine.Unmatched; | ||
|
||
public abstract class AbstractActionHelpCommand extends AbstractRunnableCommand implements Runnable { | ||
@Parameters(arity="1", descriptionKey="fcli.action.run.action") private String action; | ||
@Unmatched private String[] actionArgs; // We explicitly ignore any unknown CLI args, to allow for | ||
// users to simply switch between run and help commands. | ||
|
||
@Override | ||
public final void run() { | ||
initMixins(); | ||
var actionDescriptor = ActionHelper.load(getType(), action); | ||
System.out.println(getActionHelp(actionDescriptor)); | ||
} | ||
|
||
private final String getActionHelp(ActionDescriptor action) { | ||
var usage = action.getUsage(); | ||
return String.format( | ||
"\nAction: %s\n"+ | ||
"\n%s\n"+ | ||
"\n%s\n"+ | ||
"\nAction options:\n"+ | ||
"%s", | ||
action.getName(), usage.getHeader(), usage.getDescription(), ActionParameterHelper.getSupportedOptionsTable(action)); | ||
} | ||
|
||
protected abstract String getType(); | ||
} |
54 changes: 54 additions & 0 deletions
54
...mmon/src/main/java/com/fortify/cli/common/action/cli/cmd/AbstractActionImportCommand.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,54 @@ | ||
/******************************************************************************* | ||
* 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.common.action.cli.cmd; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fortify.cli.common.action.helper.ActionHelper; | ||
import com.fortify.cli.common.output.cli.cmd.AbstractOutputCommand; | ||
import com.fortify.cli.common.output.cli.cmd.IJsonNodeSupplier; | ||
import com.fortify.cli.common.util.StringUtils; | ||
|
||
import picocli.CommandLine.ArgGroup; | ||
import picocli.CommandLine.Option; | ||
|
||
public abstract class AbstractActionImportCommand extends AbstractOutputCommand implements IJsonNodeSupplier { | ||
@ArgGroup(exclusive = true, multiplicity = "1") private ImportArgGroup argGroup = new ImportArgGroup(); | ||
private static final class ImportArgGroup { | ||
@ArgGroup(exclusive=false) private ZipArgGroup zipArgGroup = new ZipArgGroup(); | ||
@ArgGroup(exclusive=false) private FileArgGroup fileArgGroup = new FileArgGroup(); | ||
} | ||
private static final class ZipArgGroup { | ||
@Option(names = {"--zip", "-z"}, required = true, descriptionKey="cli.action.import.zip") private String zip; | ||
} | ||
private static final class FileArgGroup { | ||
@Option(names = {"--file", "-f"}, required = true, descriptionKey="cli.action.import.file") private String file; | ||
@Option(names = {"--name", "-n"}, required = false, descriptionKey="cli.action.import.name") private String name; | ||
} | ||
|
||
@Override | ||
public final JsonNode getJsonNode() { | ||
var zip = argGroup.zipArgGroup.zip; | ||
if ( StringUtils.isNotBlank(zip) ) { | ||
return ActionHelper.importZip(getType(), zip); | ||
} else { | ||
return ActionHelper.importSingle(getType(), argGroup.fileArgGroup.name, argGroup.fileArgGroup.file); | ||
} | ||
} | ||
@Override | ||
public final boolean isSingular() { | ||
return false; | ||
} | ||
protected abstract String getType(); | ||
|
||
|
||
} |
37 changes: 37 additions & 0 deletions
37
...common/src/main/java/com/fortify/cli/common/action/cli/cmd/AbstractActionListCommand.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,37 @@ | ||
/******************************************************************************* | ||
* 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.common.action.cli.cmd; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import com.fortify.cli.common.action.helper.ActionHelper; | ||
import com.fortify.cli.common.json.JsonHelper; | ||
import com.fortify.cli.common.output.cli.cmd.AbstractOutputCommand; | ||
import com.fortify.cli.common.output.cli.cmd.IJsonNodeSupplier; | ||
|
||
public abstract class AbstractActionListCommand extends AbstractOutputCommand implements IJsonNodeSupplier { | ||
@Override | ||
public final JsonNode getJsonNode() { | ||
return ActionHelper.list(getType()) | ||
.map(JsonHelper.getObjectMapper()::valueToTree) | ||
.map(ObjectNode.class::cast) | ||
.collect(JsonHelper.arrayNodeCollector()); | ||
} | ||
@Override | ||
public final boolean isSingular() { | ||
return false; | ||
} | ||
protected abstract String getType(); | ||
|
||
|
||
} |
37 changes: 37 additions & 0 deletions
37
...ommon/src/main/java/com/fortify/cli/common/action/cli/cmd/AbstractActionResetCommand.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,37 @@ | ||
/******************************************************************************* | ||
* 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.common.action.cli.cmd; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fortify.cli.common.action.helper.ActionHelper; | ||
import com.fortify.cli.common.output.cli.cmd.AbstractOutputCommand; | ||
import com.fortify.cli.common.output.cli.cmd.IJsonNodeSupplier; | ||
import com.fortify.cli.common.output.transform.IActionCommandResultSupplier; | ||
|
||
public abstract class AbstractActionResetCommand extends AbstractOutputCommand implements IJsonNodeSupplier, IActionCommandResultSupplier { | ||
@Override | ||
public final JsonNode getJsonNode() { | ||
return ActionHelper.reset(getType()); | ||
} | ||
@Override | ||
public String getActionCommandResult() { | ||
return "DELETED"; | ||
} | ||
@Override | ||
public final boolean isSingular() { | ||
return false; | ||
} | ||
protected abstract String getType(); | ||
|
||
|
||
} |
78 changes: 78 additions & 0 deletions
78
...-common/src/main/java/com/fortify/cli/common/action/cli/cmd/AbstractActionRunCommand.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,78 @@ | ||
/******************************************************************************* | ||
* 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.common.action.cli.cmd; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.expression.spel.support.SimpleEvaluationContext; | ||
|
||
import com.fortify.cli.common.action.helper.ActionHelper; | ||
import com.fortify.cli.common.action.helper.ActionParameterHelper; | ||
import com.fortify.cli.common.action.helper.ActionRunner; | ||
import com.fortify.cli.common.cli.cmd.AbstractRunnableCommand; | ||
import com.fortify.cli.common.cli.mixin.CommandHelperMixin; | ||
import com.fortify.cli.common.cli.util.SimpleOptionsParser.OptionsParseResult; | ||
import com.fortify.cli.common.progress.cli.mixin.ProgressWriterFactoryMixin; | ||
import com.fortify.cli.common.progress.helper.IProgressWriterI18n; | ||
import com.fortify.cli.common.util.DisableTest; | ||
import com.fortify.cli.common.util.DisableTest.TestType; | ||
|
||
import picocli.CommandLine.Mixin; | ||
import picocli.CommandLine.Option; | ||
import picocli.CommandLine.ParameterException; | ||
import picocli.CommandLine.Parameters; | ||
import picocli.CommandLine.Unmatched; | ||
|
||
public abstract class AbstractActionRunCommand extends AbstractRunnableCommand implements Runnable { | ||
@Parameters(arity="1", descriptionKey="fcli.action.run.action") private String action; | ||
@DisableTest({TestType.MULTI_OPT_SPLIT, TestType.MULTI_OPT_PLURAL_NAME, TestType.OPT_LONG_NAME}) | ||
@Option(names="--<action-parameter>", paramLabel="<value>", descriptionKey="fcli.action.run.action-parameter") | ||
private List<String> dummyForSynopsis; | ||
@Mixin private ProgressWriterFactoryMixin progressWriterFactory; | ||
@Mixin CommandHelperMixin commandHelper; | ||
@Unmatched private String[] actionArgs; | ||
|
||
@Override | ||
public final void run() { | ||
initMixins(); | ||
Runnable delayedConsoleWriter = null; | ||
try ( var progressWriter = progressWriterFactory.create() ) { | ||
progressWriter.writeProgress("Loading action %s", action); | ||
var actionDescriptor = ActionHelper.load(getType(), action); | ||
try ( var actionRunner = ActionRunner.builder() | ||
.onValidationErrors(this::onValidationErrors) | ||
.action(actionDescriptor) | ||
.progressWriter(progressWriter).build() ) | ||
{ | ||
delayedConsoleWriter = run(actionRunner, progressWriter); | ||
} | ||
} | ||
delayedConsoleWriter.run(); | ||
} | ||
|
||
private Runnable run(ActionRunner actionRunner, IProgressWriterI18n progressWriter) { | ||
actionRunner.getSpelEvaluator().configure(context->configure(actionRunner, context)); | ||
progressWriter.writeProgress("Executing action %s", actionRunner.getAction().getName()); | ||
return actionRunner.run(actionArgs); | ||
} | ||
|
||
private ParameterException onValidationErrors(OptionsParseResult optionsParseResult) { | ||
var errorsString = String.join("\n ", optionsParseResult.getValidationErrors()); | ||
var supportedOptionsString = ActionParameterHelper.getSupportedOptionsTable(optionsParseResult.getOptions()); | ||
var msg = String.format("Option errors:\n %s\nSupported options:\n%s\n", errorsString, supportedOptionsString); | ||
return new ParameterException(commandHelper.getCommandSpec().commandLine(), msg); | ||
} | ||
|
||
protected abstract String getType(); | ||
protected abstract void configure(ActionRunner actionRunner, SimpleEvaluationContext context); | ||
} |
Oops, something went wrong.