Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat issue list #521

Merged
merged 3 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ protected final UnirestInstance getUnirestInstance() {
* @param cmd
*/
protected final void addRecordTransformersForCommand(StandardOutputConfig standardOutputConfig, Object cmd) {
for ( var mixin : commandHelper.getCommandSpec().mixins().values() ) {
addRecordTransformersFromObject(standardOutputConfig, mixin.userObject());
}
addRecordTransformersFromObject(standardOutputConfig, getProductHelper());
addRecordTransformersFromObject(standardOutputConfig, cmd);
addCommandActionResultRecordTransformer(standardOutputConfig, cmd);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*******************************************************************************
* 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.cli.mixin;

import com.fasterxml.jackson.databind.JsonNode;
import com.fortify.cli.common.cli.mixin.CommandHelperMixin;
import com.fortify.cli.common.output.transform.IRecordTransformer;
import com.fortify.cli.common.rest.unirest.IUnirestInstanceSupplier;
import com.fortify.cli.fod._common.rest.embed.FoDEmbedder;
import com.fortify.cli.fod._common.rest.embed.IFoDEntityEmbedderSupplier;

import kong.unirest.UnirestInstance;
import picocli.CommandLine.Mixin;

public abstract class AbstractFoDEmbedMixin implements IRecordTransformer {
@Mixin private CommandHelperMixin commandHelper;
private FoDEmbedder embedder;

@Override
public final JsonNode transformRecord(JsonNode record) {
if ( embedder==null ) { embedder = new FoDEmbedder(getEmbedSuppliers()); }
UnirestInstance unirest = commandHelper
.getCommandAs(IUnirestInstanceSupplier.class)
.orElseThrow().getUnirestInstance();
embedder.transformRecord(unirest, record);
return record;
}

protected abstract IFoDEntityEmbedderSupplier[] getEmbedSuppliers();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*******************************************************************************
* 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.embed;

import java.util.Collection;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;

import kong.unirest.UnirestInstance;

/**
* This class takes zero or more {@link IFoDEntityEmbedderSupplier} instances
* as constructor argument(s), storing the {@link IFoDEntityEmbedder} instances
* generated by these suppliers, to provide the {@link #transformRecord(UnirestInstance, JsonNode)}
* method that embeds the requested data into a given record.
*
* @author rsenden
*
*/
public class FoDEmbedder {
private final Collection<IFoDEntityEmbedder> embedders;

public FoDEmbedder(IFoDEntityEmbedderSupplier... suppliers) {
this.embedders = suppliers==null ? null : Stream.of(suppliers)
.map(IFoDEntityEmbedderSupplier::createEntityEmbedder)
.collect(Collectors.toList());
}

public JsonNode transformRecord(UnirestInstance unirest, JsonNode record) {
if ( embedders!=null ) {
if ( !(record instanceof ObjectNode) ) {
throw new RuntimeException("Can't embed data in records of type "+record.getNodeType());
}
embedders.forEach(e->e.embed(unirest, (ObjectNode)record));
}
return record;
}
}
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._common.rest.embed;

import com.fasterxml.jackson.databind.node.ObjectNode;

import kong.unirest.UnirestInstance;

/**
* Interface for executing one or more requests and adding the response data
* as embedded properties to a given record.
*
* @author rsenden
*/
@FunctionalInterface
public interface IFoDEntityEmbedder {
void embed(UnirestInstance unirest, ObjectNode record);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*******************************************************************************
* 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.embed;

/**
* Interface for supplying an {@link IFoDEntityEmbedder} instance.
* @author rsenden
*/
@FunctionalInterface
public interface IFoDEntityEmbedderSupplier {
IFoDEntityEmbedder createEntityEmbedder();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.fortify.cli.fod.action.cli.cmd.FoDActionCommands;
import com.fortify.cli.fod.app.cli.cmd.FoDAppCommands;
import com.fortify.cli.fod.dast_scan.cli.cmd.FoDDastScanCommands;
import com.fortify.cli.fod.issue.cli.cmd.FoDIssueCommands;
import com.fortify.cli.fod.mast_scan.cli.cmd.FoDMastScanCommands;
import com.fortify.cli.fod.microservice.cli.cmd.FoDMicroserviceCommands;
import com.fortify.cli.fod.oss_scan.cli.cmd.FoDOssScanCommands;
Expand Down Expand Up @@ -52,6 +53,7 @@
FoDDastScanCommands.class,
FoDMastScanCommands.class,
FoDOssScanCommands.class,
FoDIssueCommands.class,
FoDReportCommands.class,
FoDRestCommands.class,

Expand Down
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.issue.cli.cmd;

import com.fortify.cli.common.cli.cmd.AbstractContainerCommand;

import picocli.CommandLine;

@CommandLine.Command(name = "issue",
subcommands = {
FoDIssueListCommand.class,
}
)
//@DefaultVariablePropertyName("applicationId")
public class FoDIssueCommands extends AbstractContainerCommand {
}
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.fod.issue.cli.cmd;

import com.fortify.cli.common.output.cli.mixin.OutputHelperMixins;
import com.fortify.cli.common.rest.query.IServerSideQueryParamGeneratorSupplier;
import com.fortify.cli.common.rest.query.IServerSideQueryParamValueGenerator;
import com.fortify.cli.fod._common.cli.mixin.FoDDelimiterMixin;
import com.fortify.cli.fod._common.output.cli.cmd.AbstractFoDBaseRequestOutputCommand;
import com.fortify.cli.fod._common.rest.query.FoDFiltersParamGenerator;
import com.fortify.cli.fod._common.rest.query.cli.mixin.FoDFiltersParamMixin;
import com.fortify.cli.fod.issue.cli.mixin.FoDIssueEmbedMixin;
import com.fortify.cli.fod.release.cli.mixin.FoDReleaseByQualifiedNameOrIdResolverMixin;

import kong.unirest.HttpRequest;
import kong.unirest.UnirestInstance;
import lombok.Getter;
import picocli.CommandLine.Command;
import picocli.CommandLine.Mixin;

@Command(name = OutputHelperMixins.List.CMD_NAME)
public class FoDIssueListCommand extends AbstractFoDBaseRequestOutputCommand implements IServerSideQueryParamGeneratorSupplier {
@Getter @Mixin private OutputHelperMixins.List outputHelper;
@Mixin private FoDDelimiterMixin delimiterMixin; // Is automatically injected in resolver mixins
@Mixin private FoDReleaseByQualifiedNameOrIdResolverMixin.RequiredOption releaseResolver;
@Mixin private FoDFiltersParamMixin filterParamMixin;
@Mixin private FoDIssueEmbedMixin embedMixin;
@Getter private IServerSideQueryParamValueGenerator serverSideQueryParamGenerator = new FoDFiltersParamGenerator();
// .add("id","applicationId")
// .add("name","applicationName")
// .add("criticality", "businessCriticalityType")
// .add("type", "applicationType");

@Override
public HttpRequest<?> getBaseRequest(UnirestInstance unirest) {
return unirest.get("/api/v3/releases/{releaseId}/vulnerabilities")
.routeParam("releaseId", releaseResolver.getReleaseId(unirest));
}

@Override
public boolean isSingular() {
return false;
}
}
Loading
Loading