Skip to content

Commit 522e38b

Browse files
authored
Merge pull request #3173 from dheerajodha/EC-1603
feat: Add --show-policy-docs-link flag (default: false)
2 parents b84ac3b + 30170a0 commit 522e38b

19 files changed

Lines changed: 143 additions & 101 deletions

File tree

cmd/validate/image.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ func validateImageCmd(validate imageValidationFunc) *cobra.Command {
338338

339339
showSuccesses, _ := cmd.Flags().GetBool("show-successes")
340340
showWarnings, _ := cmd.Flags().GetBool("show-warnings")
341+
showPolicyDocsLink, _ := cmd.Flags().GetBool("show-policy-docs-link")
341342

342343
// worker is responsible for processing one component at a time from the jobs channel,
343344
// and for emitting a corresponding result for the component on the results channel.
@@ -429,13 +430,14 @@ func validateImageCmd(validate imageValidationFunc) *cobra.Command {
429430
}
430431

431432
reportData := validate_utils.ReportData{
432-
Snapshot: data.snapshot,
433-
Components: components,
434-
Policy: data.policy,
435-
PolicyInputs: manyPolicyInput,
436-
Expansion: data.expansion,
437-
ShowSuccesses: showSuccesses,
438-
ShowWarnings: showWarnings,
433+
Snapshot: data.snapshot,
434+
Components: components,
435+
Policy: data.policy,
436+
PolicyInputs: manyPolicyInput,
437+
Expansion: data.expansion,
438+
ShowSuccesses: showSuccesses,
439+
ShowWarnings: showWarnings,
440+
ShowPolicyDocsLink: showPolicyDocsLink,
439441
}
440442
outputOpts := validate_utils.ReportOutputOptions{
441443
Output: data.output,

cmd/validate/input.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ func validateInputCmd(validate InputValidationFunc) *cobra.Command {
121121

122122
showSuccesses, _ := cmd.Flags().GetBool("show-successes")
123123
showWarnings, _ := cmd.Flags().GetBool("show-warnings")
124+
showPolicyDocsLink, _ := cmd.Flags().GetBool("show-policy-docs-link")
124125

125126
// Set numWorkers to the value from our flag. The default is 5.
126127
numWorkers := data.workers
@@ -210,14 +211,14 @@ func validateInputCmd(validate InputValidationFunc) *cobra.Command {
210211
return inputs[i].FilePath > inputs[j].FilePath
211212
})
212213

213-
report, err := input.NewReport(inputs, data.policy, manyPolicyInput, showSuccesses, showWarnings)
214+
report, err := input.NewReport(inputs, data.policy, manyPolicyInput, showSuccesses, showWarnings, showPolicyDocsLink)
214215
if err != nil {
215216
return err
216217
}
217218

218219
utils.SetColorEnabled(data.noColor, data.forceColor)
219220

220-
p := format.NewTargetParser(input.Text, format.Options{ShowSuccesses: showSuccesses, ShowWarnings: showWarnings}, cmd.OutOrStdout(), utils.FS(cmd.Context()))
221+
p := format.NewTargetParser(input.Text, format.Options{ShowSuccesses: showSuccesses, ShowWarnings: showWarnings, ShowPolicyDocsLink: showPolicyDocsLink}, cmd.OutOrStdout(), utils.FS(cmd.Context()))
221222
if err := report.WriteAll(data.output, p); err != nil {
222223
return err
223224
}

cmd/validate/validate.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@ func NewValidateCmd() *cobra.Command {
4545
}
4646
validateCmd.PersistentFlags().Bool("show-successes", false, "")
4747
validateCmd.PersistentFlags().Bool("show-warnings", true, "")
48+
validateCmd.PersistentFlags().Bool("show-policy-docs-link", false, "Show link to policy documentation in output when there are violations or warnings")
4849
return validateCmd
4950
}

cmd/validate/vsa.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ type validateVSAData struct {
126126
workers int // Number of worker threads for parallel processing
127127

128128
// Output formatting options
129-
noColor bool // Disable color output
130-
forceColor bool // Force color output
129+
noColor bool // Disable color output
130+
forceColor bool // Force color output
131+
showPolicyDocsLink bool // Show policy docs link in output
131132

132133
// Internal state
133134
policySpec ecapi.EnterpriseContractPolicySpec
@@ -266,6 +267,9 @@ func runValidateVSA(cmd *cobra.Command, data *validateVSAData, args []string) er
266267
// Set color support based on flags
267268
utils.SetColorEnabled(data.noColor, data.forceColor)
268269

270+
// Get show-policy-docs-link flag value
271+
data.showPolicyDocsLink, _ = cmd.Flags().GetBool("show-policy-docs-link")
272+
269273
// Parse VSA expiration
270274
if err := parseVSAExpiration(data); err != nil {
271275
return err
@@ -1095,13 +1099,14 @@ func buildFallbackReportData(fallbackResults []validate_utils.Result, vsaData *v
10951099
}
10961100

10971101
return validate_utils.ReportData{
1098-
Snapshot: vsaData.images,
1099-
Components: components,
1100-
Policy: vsaData.fallbackContext.FallbackPolicy,
1101-
PolicyInputs: manyPolicyInput,
1102-
Expansion: nil,
1103-
ShowSuccesses: false,
1104-
ShowWarnings: true,
1102+
Snapshot: vsaData.images,
1103+
Components: components,
1104+
Policy: vsaData.fallbackContext.FallbackPolicy,
1105+
PolicyInputs: manyPolicyInput,
1106+
Expansion: nil,
1107+
ShowSuccesses: false,
1108+
ShowWarnings: true,
1109+
ShowPolicyDocsLink: vsaData.showPolicyDocsLink,
11051110
}, nil
11061111
}
11071112

@@ -1121,6 +1126,7 @@ func createFallbackReport(allData AllSectionsData, vsaData *validateVSAData) (*a
11211126
reportData.PolicyInputs,
11221127
reportData.ShowSuccesses,
11231128
reportData.ShowWarnings,
1129+
reportData.ShowPolicyDocsLink,
11241130
reportData.Expansion,
11251131
)
11261132
if err != nil {
@@ -1425,8 +1431,9 @@ func determineStatusFromReport(report VSAReport, display ComponentResultsDisplay
14251431
// captureFallbackText captures the text output from a fallback report
14261432
func captureFallbackText(fallbackReport *applicationsnapshot.Report, fs afero.Fs) (string, error) {
14271433
formatOpts := format.Options{
1428-
ShowSuccesses: fallbackReport.ShowSuccesses,
1429-
ShowWarnings: fallbackReport.ShowWarnings,
1434+
ShowSuccesses: fallbackReport.ShowSuccesses,
1435+
ShowWarnings: fallbackReport.ShowWarnings,
1436+
ShowPolicyDocsLink: fallbackReport.ShowPolicyDocsLink,
14301437
}
14311438
var fallbackBuf strings.Builder
14321439
fallbackWriter := &stringWriter{&fallbackBuf}

cmd/validate/vsa_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,8 @@ func TestValidateSingleVSA(t *testing.T) {
10341034
ctx := context.Background()
10351035
cmd := &cobra.Command{}
10361036
cmd.SetContext(ctx)
1037+
// Add the persistent flag that runValidateVSA expects
1038+
cmd.Flags().Bool("show-policy-docs-link", false, "")
10371039

10381040
// Use the unified runValidateVSA function which handles both single and snapshot cases
10391041
err := runValidateVSA(cmd, tt.data, tt.args)
@@ -1132,6 +1134,8 @@ func TestValidateSnapshotVSAs(t *testing.T) {
11321134
ctx := context.Background()
11331135
cmd := &cobra.Command{}
11341136
cmd.SetContext(ctx)
1137+
// Add the persistent flag that runValidateVSA expects
1138+
cmd.Flags().Bool("show-policy-docs-link", false, "")
11351139

11361140
// Use the unified runValidateVSA function which handles both single and snapshot cases
11371141
err := runValidateVSA(cmd, tt.data, []string{})

docs/modules/ROOT/pages/ec_validate.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Validate conformance with the provided policies
55
== Options
66

77
-h, --help:: help for validate (Default: false)
8+
--show-policy-docs-link:: Show link to policy documentation in output when there are violations or warnings (Default: false)
89
--show-successes:: (Default: false)
910
--show-warnings:: (Default: true)
1011

docs/modules/ROOT/pages/ec_validate_image.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ JSON of the "spec" or a reference to a Kubernetes object [<namespace>/]<name>
172172
--retry-jitter:: randomness factor for backoff calculation (0.0-1.0) (Default: 0.1)
173173
--retry-max-retry:: maximum number of retry attempts (Default: 3)
174174
--retry-max-wait:: maximum wait time between retries (Default: 3s)
175+
--show-policy-docs-link:: Show link to policy documentation in output when there are violations or warnings (Default: false)
175176
--show-successes:: (Default: false)
176177
--show-warnings:: (Default: true)
177178
--timeout:: max overall execution duration (Default: 5m0s)

docs/modules/ROOT/pages/ec_validate_input.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ mark (?) sign, for example: --output text=output.txt?show-successes=false
7676
--retry-jitter:: randomness factor for backoff calculation (0.0-1.0) (Default: 0.1)
7777
--retry-max-retry:: maximum number of retry attempts (Default: 3)
7878
--retry-max-wait:: maximum wait time between retries (Default: 3s)
79+
--show-policy-docs-link:: Show link to policy documentation in output when there are violations or warnings (Default: false)
7980
--show-successes:: (Default: false)
8081
--show-warnings:: (Default: true)
8182
--timeout:: max overall execution duration (Default: 5m0s)

docs/modules/ROOT/pages/ec_validate_policy.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ ec validate policy --policy-configuration github.com/org/repo/policy.yaml
3737
--retry-jitter:: randomness factor for backoff calculation (0.0-1.0) (Default: 0.1)
3838
--retry-max-retry:: maximum number of retry attempts (Default: 3)
3939
--retry-max-wait:: maximum wait time between retries (Default: 3s)
40+
--show-policy-docs-link:: Show link to policy documentation in output when there are violations or warnings (Default: false)
4041
--show-successes:: (Default: false)
4142
--show-warnings:: (Default: true)
4243
--timeout:: max overall execution duration (Default: 5m0s)

docs/modules/ROOT/pages/ec_validate_vsa.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ mark (?) sign, for example: --output text=output.txt?show-successes=false
6060
--retry-jitter:: randomness factor for backoff calculation (0.0-1.0) (Default: 0.1)
6161
--retry-max-retry:: maximum number of retry attempts (Default: 3)
6262
--retry-max-wait:: maximum wait time between retries (Default: 3s)
63+
--show-policy-docs-link:: Show link to policy documentation in output when there are violations or warnings (Default: false)
6364
--show-successes:: (Default: false)
6465
--show-warnings:: (Default: true)
6566
--timeout:: max overall execution duration (Default: 5m0s)

0 commit comments

Comments
 (0)