-
Notifications
You must be signed in to change notification settings - Fork 33
feat: Implement --skip-if-exceeding-quota and `--test-exceeding-quo…
#929
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
base: feat/v3.x/aviator/26.2
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,6 +69,9 @@ public class AviatorSSCAuditCommand extends AbstractSSCJsonNodeOutputCommand imp | |
| @Option(names = {"--tag-mapping"}) private String tagMapping; | ||
| @Option(names = {"--no-filterset"}) private boolean noFilterSet; | ||
| @Option(names = {"--folder"}, split = ",") @DisableTest(DisableTest.TestType.MULTI_OPT_PLURAL_NAME) private List<String> folderNames; | ||
| @Option(names = {"--skip-if-exceeding-quota"}) private boolean skipIfExceedingQuota; | ||
| @Option(names = {"--test-exceeding-quota"}) private boolean testExceedingQuota; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PR description states 'dry run'; does this do anything other than checking quota? Maybe we should just have |
||
| @Option(names = {"--default-quota-fallback"}, hidden = true) private boolean defaultQuotaFallback; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We (almost) never use hidden options in fcli, and given that this is explicitly used by bulkaudit.yaml, maybe we should just make this a non-hidden option? |
||
| @Option(names = {"--folder-priority-order"}, split = ",", | ||
| description = "Custom priority order by folder (comma-separated, highest first). Example: Critical,High,Medium,Low") | ||
| @DisableTest(DisableTest.TestType.MULTI_OPT_PLURAL_NAME) | ||
|
|
@@ -99,6 +102,66 @@ public JsonNode getJsonNode(UnirestInstance unirest) { | |
| return AviatorSSCAuditHelper.buildResultNode(av, "N/A", "SKIPPED (no auditable issues)"); | ||
| } | ||
|
|
||
| // Quota check: only when --skip-if-exceeding-quota or --test-exceeding-quota is active | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure how long the original method was, but for sure the method becomes much longer with this change. Can we please split into multiple methods? |
||
| if (skipIfExceedingQuota || testExceedingQuota) { | ||
| String effectiveAppName = appName != null ? appName : av.getApplicationName(); | ||
| long availableQuota = AviatorSSCAuditHelper.getAvailableQuota( | ||
| sessionDescriptor.getAviatorUrl(), sessionDescriptor.getAviatorToken(), | ||
| effectiveAppName, logger); | ||
|
|
||
| // App not found — behavior depends on --default-quota-fallback | ||
| if (availableQuota == AviatorSSCAuditHelper.QUOTA_APP_NOT_FOUND) { | ||
| if (defaultQuotaFallback) { | ||
| // Bulk audit mode: use default quota for non-existing apps | ||
| logger.progress("Application '%s' not found, using default quota for new applications.", effectiveAppName); | ||
| availableQuota = AviatorSSCAuditHelper.getDefaultQuota( | ||
| sessionDescriptor.getAviatorUrl(), sessionDescriptor.getAviatorToken(), logger); | ||
| if (availableQuota == AviatorSSCAuditHelper.QUOTA_UNKNOWN) { | ||
| if (testExceedingQuota) { | ||
| return AviatorSSCAuditHelper.buildResultNode(av, "N/A", | ||
| "QUOTA UNKNOWN (application '" + effectiveAppName + "' not found, could not retrieve default quota)"); | ||
| } | ||
| logger.progress("Warning: Could not retrieve default quota, proceeding with audit."); | ||
| } | ||
| // Fall through to normal quota comparison below with the default quota value | ||
| } else { | ||
| // Individual audit mode: report app not found and stop | ||
| logger.progress("Application '%s' does not exist in Aviator.", effectiveAppName); | ||
| return AviatorSSCAuditHelper.buildResultNode(av, "N/A", | ||
| "SKIPPED (application '" + effectiveAppName + "' not found in Aviator)"); | ||
| } | ||
| } | ||
|
|
||
| // If quota retrieval failed for other reasons, handle accordingly | ||
| if (availableQuota == AviatorSSCAuditHelper.QUOTA_UNKNOWN) { | ||
| if (testExceedingQuota) { | ||
| return AviatorSSCAuditHelper.buildResultNode(av, "N/A", | ||
| "QUOTA UNKNOWN (could not retrieve quota for application '" + effectiveAppName + "')"); | ||
| } | ||
| // --skip-if-exceeding-quota with unknown quota — fall through to normal audit | ||
| logger.progress("Warning: Could not retrieve quota for '%s', proceeding with audit.", effectiveAppName); | ||
| } else if (availableQuota >= 0 && auditableIssueCount > availableQuota) { | ||
| // Exceeding quota — gather top categories | ||
| var topCategories = AviatorSSCAuditHelper.getTopUnauditedCategories(unirest, av, logger, 10); | ||
| String detailedMessage = AviatorSSCAuditHelper.formatQuotaExceededMessage( | ||
| av, auditableIssueCount, availableQuota, topCategories); | ||
| LOG.info(detailedMessage); | ||
| logger.progress("Quota exceeded for %s:%s -- Open issues: %d, Available quota: %d. Audit skipped.", | ||
| av.getApplicationName(), av.getVersionName(), auditableIssueCount, availableQuota); | ||
| return AviatorSSCAuditHelper.buildQuotaExceededResultNode( | ||
| av, auditableIssueCount, availableQuota, topCategories); | ||
| } else if (testExceedingQuota) { | ||
| // Test mode but NOT exceeding quota — report pass, no audit | ||
| logger.progress("Quota check passed for %s:%s -- Open issues: %d, Available quota: %s", | ||
| av.getApplicationName(), av.getVersionName(), auditableIssueCount, | ||
| availableQuota < 0 ? "unlimited" : String.valueOf(availableQuota)); | ||
| return AviatorSSCAuditHelper.buildResultNode(av, "N/A", | ||
| String.format("QUOTA OK (issues: %d, quota: %s)", auditableIssueCount, | ||
| availableQuota < 0 ? "unlimited" : String.valueOf(availableQuota))); | ||
| } | ||
| // --skip-if-exceeding-quota with quota OK: fall through to normal audit | ||
| } | ||
|
|
||
| downloadedFprPath = downloadFpr(unirest, av, logger); | ||
| if (downloadedFprPath == null) { | ||
| return AviatorSSCAuditHelper.buildResultNode(av, "N/A", "SKIPPED (no FPR available to audit)"); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quite a long option name; nothing better comes to mind right now but maybe worth giving this another thought, to see whether some creativity can result in shorter option names?