Skip to content

Commit

Permalink
Merge pull request #433 from wtfacoconut/list-group
Browse files Browse the repository at this point in the history
feat: Add `fcli ssc appversion-groupset` command and add group by mixin ...
  • Loading branch information
rsenden authored Sep 19, 2023
2 parents be8a922 + e3d5866 commit 0742643
Show file tree
Hide file tree
Showing 9 changed files with 234 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.fortify.cli.ssc.appversion.cli.cmd.SSCAppVersionCommands;
import com.fortify.cli.ssc.appversion_attribute.cli.cmd.SSCAppVersionAttributeCommands;
import com.fortify.cli.ssc.appversion_filterset.cli.cmd.SSCAppVersionFilterSetCommands;
import com.fortify.cli.ssc.appversion_groupset.cli.cmd.SSCAppVersionGroupSetCommands;
import com.fortify.cli.ssc.appversion_user.cli.cmd.SSCAppVersionUserCommands;
import com.fortify.cli.ssc.artifact.cli.cmd.SSCArtifactCommands;
import com.fortify.cli.ssc.attribute_definition.cli.cmd.SSCAttributeDefinitionCommands;
Expand Down Expand Up @@ -60,6 +61,7 @@
SSCAppVersionCommands.class,
SSCAppVersionAttributeCommands.class,
SSCAppVersionFilterSetCommands.class,
SSCAppVersionGroupSetCommands.class,
SSCAppVersionUserCommands.class,
SSCArtifactCommands.class,
SSCAttributeDefinitionCommands.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*******************************************************************************
* 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.ssc.appversion_groupset.cli.cmd;

import com.fortify.cli.common.cli.cmd.*;
import picocli.CommandLine.*;

@Command(
hidden = true,
name = "appversion-groupset",
subcommands = {
SSCAppVersionGroupSetGetCommand.class,
SSCAppVersionGroupSetListCommand.class,
}
)
public class SSCAppVersionGroupSetCommands extends AbstractContainerCommand {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*******************************************************************************
* 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.ssc.appversion_groupset.cli.cmd;

import com.fasterxml.jackson.databind.JsonNode;
import com.fortify.cli.common.output.cli.mixin.*;
import com.fortify.cli.ssc._common.output.cli.cmd.*;
import com.fortify.cli.ssc.appversion.cli.mixin.*;
import com.fortify.cli.ssc.appversion_groupset.cli.mixin.*;
import kong.unirest.*;
import lombok.*;
import picocli.CommandLine.*;

@Command(name = OutputHelperMixins.Get.CMD_NAME)
public class SSCAppVersionGroupSetGetCommand extends AbstractSSCJsonNodeOutputCommand {
@Getter @Mixin private OutputHelperMixins.Get outputHelper;
@Mixin SSCAppVersionGroupSetResolverMixin.PositionalParameterSingle groupSetResolver;
@Mixin private SSCAppVersionResolverMixin.RequiredOption parentResolver;

@Override
public JsonNode getJsonNode(UnirestInstance unirest) {
return groupSetResolver.getGroupSetDescriptor(unirest, parentResolver.getAppVersionId(unirest)).asJsonNode();
}

@Override
public boolean isSingular() {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*******************************************************************************
* 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.ssc.appversion_groupset.cli.cmd;

import com.fasterxml.jackson.databind.JsonNode;
import com.fortify.cli.common.output.cli.mixin.*;
import com.fortify.cli.ssc._common.output.cli.cmd.*;
import com.fortify.cli.ssc._common.rest.*;
import com.fortify.cli.ssc.appversion.cli.mixin.*;
import kong.unirest.*;
import lombok.*;
import picocli.CommandLine.*;

@Command(name = OutputHelperMixins.List.CMD_NAME)
public class SSCAppVersionGroupSetListCommand extends AbstractSSCJsonNodeOutputCommand {
@Getter @Mixin private OutputHelperMixins.List outputHelper;
@Mixin private SSCAppVersionResolverMixin.RequiredOption parentResolver;

@Override
public JsonNode getJsonNode(UnirestInstance unirest) {
return unirest.get(SSCUrls.PROJECT_VERSION_ISSUE_SELECTOR_SET(parentResolver.getAppVersionId(unirest)))
.asObject(JsonNode.class).getBody()
.get("data")
.get("groupBySet");
}

@Override
public boolean isSingular() {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*******************************************************************************
* 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.ssc.appversion_groupset.cli.mixin;

import com.fortify.cli.ssc.appversion_groupset.helper.*;
import kong.unirest.*;
import lombok.*;
import picocli.CommandLine.*;

public class SSCAppVersionGroupSetResolverMixin {
private static abstract class AbstractSSCGroupSetResolverMixin {
public abstract String getGroupSetDisplayNameOrId();

public SSCAppVersionGroupSetDescriptor getGroupSetDescriptor(UnirestInstance unirest, String appVersionId) {
return new SSCAppVersionGroupSetHelper(unirest, appVersionId).getDescriptorByDisplayNameOrId(getGroupSetDisplayNameOrId(), true);
}
}

public static class GroupByOption extends AbstractSSCGroupSetResolverMixin {
@Option(names="--by", defaultValue = "FOLDER", descriptionKey = "fcli.ssc.appversion-group-set.resolver.displayNameOrId")
@Getter public String groupSetDisplayNameOrId;
}

public static class PositionalParameterSingle extends AbstractSSCGroupSetResolverMixin {
@Parameters(index = "0", arity = "1", descriptionKey = "fcli.ssc.appversion-group-set.resolver.displayNameOrId")
@Getter private String groupSetDisplayNameOrId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*******************************************************************************
* 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.ssc.appversion_groupset.helper;

import com.formkiq.graalvm.annotations.*;
import com.fortify.cli.common.json.*;
import lombok.*;

@Reflectable @NoArgsConstructor
@Data @EqualsAndHashCode(callSuper=true)
public class SSCAppVersionGroupSetDescriptor extends JsonNodeHolder {
private String guid;
private String displayName;

}
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.ssc.appversion_groupset.helper;

import com.fasterxml.jackson.databind.JsonNode;
import com.fortify.cli.common.json.*;
import com.fortify.cli.ssc._common.rest.*;
import kong.unirest.*;

import java.util.*;

public final class SSCAppVersionGroupSetHelper {
private final Map<String, SSCAppVersionGroupSetDescriptor> descriptorsByGuid = new HashMap<>();
private final Map<String, SSCAppVersionGroupSetDescriptor> descriptorsByDisplayName = new HashMap<>();

/**
* This constructor calls the SSC projectVersion issueSelectorSet endpoint to retrieve filter and grouping data.
* As we are only interested in the grouping data, we then call the {@link #processGroupSet(JsonNode)} method for
* each grouping to collect the relevant data.
* @param unirest
*/
public SSCAppVersionGroupSetHelper(UnirestInstance unirest, String applicationVersionId) {
JsonNode body = unirest.get(SSCUrls.PROJECT_VERSION_ISSUE_SELECTOR_SET(applicationVersionId)).asObject(JsonNode.class).getBody();
body.get("data").get("groupBySet").forEach(this::processGroupSet);
}

private void processGroupSet(JsonNode issueTemplate) {
SSCAppVersionGroupSetDescriptor descriptor = JsonHelper.treeToValue(issueTemplate, SSCAppVersionGroupSetDescriptor.class);
descriptorsByGuid.put(descriptor.getGuid(), descriptor);
descriptorsByDisplayName.put(descriptor.getDisplayName(), descriptor);
}

public SSCAppVersionGroupSetDescriptor getDescriptorByDisplayNameOrId(String groupBySetDisplayNameOrId, boolean failIfNotFound) {
SSCAppVersionGroupSetDescriptor descriptor = descriptorsByGuid.get(groupBySetDisplayNameOrId);
descriptor = descriptor!=null ? descriptor : descriptorsByDisplayName.get(groupBySetDisplayNameOrId);
if ( failIfNotFound && descriptor==null ) {
throw new IllegalArgumentException("No grouping found with display name or id "+groupBySetDisplayNameOrId);
}
return descriptor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.fortify.cli.ssc.appversion_filterset.cli.mixin.SSCAppVersionFilterSetResolverMixin;
import com.fortify.cli.ssc.appversion_filterset.helper.SSCAppVersionFilterSetDescriptor;

import com.fortify.cli.ssc.appversion_groupset.cli.mixin.*;
import com.fortify.cli.ssc.appversion_groupset.helper.*;
import kong.unirest.GetRequest;
import kong.unirest.HttpRequest;
import kong.unirest.UnirestInstance;
Expand All @@ -31,19 +33,20 @@
public class SSCVulnerabilityCountCommand extends AbstractSSCBaseRequestOutputCommand {
@Getter @Mixin private SSCOutputHelperMixins.VulnCount outputHelper;
@Mixin private SSCAppVersionResolverMixin.RequiredOption parentResolver;
@Option(names="--by", defaultValue="FOLDER") private String groupingType;
@Mixin private SSCAppVersionGroupSetResolverMixin.GroupByOption groupSetResolver;
@Mixin private SSCAppVersionFilterSetResolverMixin.FilterSetOption filterSetResolver;

// TODO Include options for includeRemoved/Hidden/Suppressed?

@Override
public HttpRequest<?> getBaseRequest(UnirestInstance unirest) {
String appVersionId = parentResolver.getAppVersionId(unirest);
SSCAppVersionGroupSetDescriptor groupSetDescriptor = groupSetResolver.getGroupSetDescriptor(unirest, appVersionId);
SSCAppVersionFilterSetDescriptor filterSetDescriptor = filterSetResolver.getFilterSetDescriptor(unirest, appVersionId);
GetRequest request = unirest.get(SSCUrls.PROJECT_VERSION_ISSUE_GROUPS(appVersionId))
.queryString("limit","-1")
.queryString("qm", "issues")
.queryString("groupingtype", groupingType);
.queryString("groupingtype", groupSetDescriptor.getGuid());
if ( filterSetDescriptor!=null ) {
request.queryString("filterset", filterSetDescriptor.getGuid());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ fcli.ssc.appversion-filterset.get.usage.header = Get filter set details.
fcli.ssc.appversion-filterset.list.usage.header = List application version filter sets.
fcli.ssc.appversion-filter-set.resolver.titleOrId = Filter set title (name) or id.

# fcli ssc appversion-groupset
fcli.ssc.appversion-groupset.usage.header = Manage SSC application version group sets.
fcli.ssc.appversion-groupset.get.usage.header = Get group set details.
fcli.ssc.appversion-groupset.list.usage.header = List application version group sets.
fcli.ssc.appversion-group-set.resolver.displayNameOrId = Group set (groupBy) display name or id.

# fcli ssc appversion-user
fcli.ssc.appversion-user.usage.header = Manage SSC application version users.
fcli.ssc.appversion-user.add.usage.header = Add users to an application version.
Expand Down

0 comments on commit 0742643

Please sign in to comment.