-
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: `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
Showing
4 changed files
with
105 additions
and
0 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
43 changes: 43 additions & 0 deletions
43
...ssc/src/main/java/com/fortify/cli/ssc/appversion/cli/mixin/SSCAppVersionExcludeMixin.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,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('_', '-'); | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...ssc/src/main/java/com/fortify/cli/ssc/appversion/cli/mixin/SSCAppVersionIncludeMixin.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 @@ | ||
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; | ||
} | ||
} |
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