Skip to content

Commit

Permalink
chore: fcli ssc av ls features
Browse files Browse the repository at this point in the history
feat: `fcli ssc appversion list`: Add `--include` option to allow for listing active, inactive, or both active and inactive versions

feat: `fcli ssc appversion list`: Add `--exclude` option to allow for excluding empty versions, or versions that have no issues assigned to current user
  • Loading branch information
rsenden committed Dec 11, 2024
1 parent ac4e787 commit ba0c126
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.fortify.cli.ssc._common.rest.query.SSCQParamValueGenerators;
import com.fortify.cli.ssc._common.rest.query.cli.mixin.SSCQParamMixin;
import com.fortify.cli.ssc.appversion.cli.mixin.SSCAppVersionBulkEmbedMixin;
import com.fortify.cli.ssc.appversion.cli.mixin.SSCAppVersionExcludeMixin;
import com.fortify.cli.ssc.appversion.cli.mixin.SSCAppVersionIncludeMixin;
import com.fortify.cli.ssc.appversion.helper.SSCAppVersionHelper;

import kong.unirest.HttpRequest;
Expand All @@ -40,6 +42,8 @@ public class SSCAppVersionListCommand extends AbstractSSCBaseRequestOutputComman
.add("application.id", "project.id", SSCQParamValueGenerators::plain)
.add("name", SSCQParamValueGenerators::wrapInQuotes);
@Mixin private SSCAppVersionBulkEmbedMixin bulkEmbedMixin;
@Mixin private SSCAppVersionIncludeMixin includeMixin;
@Mixin private SSCAppVersionExcludeMixin excludeMixin;

@Override
public HttpRequest<?> getBaseRequest(UnirestInstance unirest) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.fortify.cli.ssc.appversion.cli.mixin;

import java.util.Set;

import com.fortify.cli.common.rest.unirest.IHttpRequestUpdater;
import com.fortify.cli.common.util.DisableTest;
import com.fortify.cli.common.util.DisableTest.TestType;

import kong.unirest.HttpRequest;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import picocli.CommandLine.Option;

public class SSCAppVersionExcludeMixin implements IHttpRequestUpdater {
@DisableTest(TestType.MULTI_OPT_PLURAL_NAME)
@Option(names = {"--exclude", "-e"}, split = ",", descriptionKey = "fcli.ssc.appversion.list.exclude", paramLabel="<values>")
private Set<SSCAppVersionExclude> excludes;

public HttpRequest<?> updateRequest(HttpRequest<?> request) {
if ( excludes!=null ) {
for ( var exclude : excludes) {
var queryParameterName = exclude.getRequestParameterName();
if ( queryParameterName!=null ) {
request = request.queryString(queryParameterName, "true");
}
}
}
return request;
}

@RequiredArgsConstructor
public static enum SSCAppVersionExclude {
empty("onlyIfHasIssues"), no_assigned_issues("myAssignedIssues");

@Getter
private final String requestParameterName;

@Override
public String toString() {
return super.toString().replace('_', '-');
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.fortify.cli.ssc.appversion.cli.mixin;

import java.util.Set;

import com.fasterxml.jackson.databind.JsonNode;
import com.fortify.cli.common.json.JsonHelper;
import com.fortify.cli.common.output.transform.IRecordTransformer;
import com.fortify.cli.common.rest.unirest.IHttpRequestUpdater;
import com.fortify.cli.common.util.DisableTest;
import com.fortify.cli.common.util.DisableTest.TestType;

import kong.unirest.HttpRequest;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import picocli.CommandLine.Option;

public class SSCAppVersionIncludeMixin implements IHttpRequestUpdater, IRecordTransformer {
@DisableTest(TestType.MULTI_OPT_PLURAL_NAME)
@Option(names = {"--include", "-i"}, split = ",", defaultValue = "active", descriptionKey = "fcli.ssc.appversion.list.include", paramLabel="<values>")
private Set<SSCAppVersionInclude> includes;

public HttpRequest<?> updateRequest(HttpRequest<?> request) {
if ( includes!=null ) {
for ( var include : includes) {
var queryParameterName = include.getRequestParameterName();
if ( queryParameterName!=null ) {
request = request.queryString(queryParameterName, "true");
}
}
}
return request;
}

@Override
public JsonNode transformRecord(JsonNode record) {
// If includes doesn't include 'active', we return null for any active application versions
// to remove those from the results. It would be more performant to add q=active:false request
// parameter instead to have SSC filter out active versions, but we need to figure out how
// to properly combine this with 'q'-parameters generated through SSCQParamGenerator as used
// in the 'fcli ssc av ls' command.
return !includes.contains(SSCAppVersionInclude.active)
&& JsonHelper.evaluateSpelExpression(record, "active", Boolean.class)
? null
: record;
}

@RequiredArgsConstructor
public static enum SSCAppVersionInclude {
active(null), inactive("includeInactive");

@Getter
private final String requestParameterName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ fcli.ssc.appversion.list.embed = Embed extra application version data. Allowed v
Using the --output option, this extra data can be included in the output. Using the --query option, \
this extra data can be queried upon. To get an understanding of the structure and contents of the \
embedded data, use the --output json or --output yaml options.
fcli.ssc.appversion.list.include = List either active (default), inactive, or both active and inactive versions. \
Allowed values: ${COMPLETION-CANDIDATES}.
fcli.ssc.appversion.list.exclude = Exclude versions that either have no results, or no issues assigned to the current \
user. Allowed values: ${COMPLETION-CANDIDATES}.
fcli.ssc.appversion.purge-artifacts.usage.header = Purge application version artifacts.
fcli.ssc.appversion.purge-artifacts.usage.description = Purge all application version artifacts older than the specified date. See 'fcli ssc artifact purge' for purging individual artifacts.
fcli.ssc.appversion.purge-artifacts.older-than = Purge artifacts older than the specified value, \
Expand Down

0 comments on commit ba0c126

Please sign in to comment.