Skip to content

Commit 450de2e

Browse files
dheerajodhaclaude
andcommitted
feat: Add --show-policy-docs-link flag (default: true)
Allow users to control the policy documentation link in output. Addresses noise in demos while maintaining backward compatibility. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 3ce85d1 commit 450de2e

17 files changed

Lines changed: 134 additions & 97 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", true, "Show the policy documentation link when there are failures or warnings")
4849
return validateCmd
4950
}

cmd/validate/vsa.go

Lines changed: 15 additions & 9 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 documentation link
131132

132133
// Internal state
133134
policySpec ecapi.EnterpriseContractPolicySpec
@@ -194,6 +195,9 @@ func NewValidateVSACmd() *cobra.Command {
194195
// Compute fallback behavior: enabled by default, disabled if --no-fallback is set
195196
data.fallbackToImageValidation = !data.noFallback
196197

198+
// Get persistent flag value from parent command
199+
data.showPolicyDocsLink, _ = cmd.Flags().GetBool("show-policy-docs-link")
200+
197201
return validateVSAInput(data, args)
198202
},
199203
RunE: func(cmd *cobra.Command, args []string) error {
@@ -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 {

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 the policy documentation link when there are failures or warnings (Default: true)
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 the policy documentation link when there are failures or warnings (Default: true)
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 the policy documentation link when there are failures or warnings (Default: true)
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 the policy documentation link when there are failures or warnings (Default: true)
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 the policy documentation link when there are failures or warnings (Default: true)
6364
--show-successes:: (Default: false)
6465
--show-warnings:: (Default: true)
6566
--timeout:: max overall execution duration (Default: 5m0s)

internal/applicationsnapshot/report.go

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,20 @@ type Component struct {
5050
}
5151

5252
type Report struct {
53-
Success bool `json:"success"`
54-
created time.Time
55-
Snapshot string `json:"snapshot,omitempty"`
56-
Components []Component `json:"components"`
57-
Key string `json:"key"`
58-
Policy ecc.EnterpriseContractPolicySpec `json:"policy"`
59-
EcVersion string `json:"ec-version"`
60-
Data any `json:"-"`
61-
EffectiveTime time.Time `json:"effective-time"`
62-
PolicyInput [][]byte `json:"-"`
63-
ShowSuccesses bool `json:"-"`
64-
ShowWarnings bool `json:"-"`
65-
Expansion *ExpansionInfo `json:"-"`
53+
Success bool `json:"success"`
54+
created time.Time
55+
Snapshot string `json:"snapshot,omitempty"`
56+
Components []Component `json:"components"`
57+
Key string `json:"key"`
58+
Policy ecc.EnterpriseContractPolicySpec `json:"policy"`
59+
EcVersion string `json:"ec-version"`
60+
Data any `json:"-"`
61+
EffectiveTime time.Time `json:"effective-time"`
62+
PolicyInput [][]byte `json:"-"`
63+
ShowSuccesses bool `json:"-"`
64+
ShowWarnings bool `json:"-"`
65+
ShowPolicyDocsLink bool `json:"-"`
66+
Expansion *ExpansionInfo `json:"-"`
6667
}
6768

6869
type summary struct {
@@ -128,7 +129,7 @@ var OutputFormats = []string{
128129

129130
// WriteReport returns a new instance of Report representing the state of
130131
// components from the snapshot.
131-
func NewReport(snapshot string, components []Component, policy policy.Policy, policyInput [][]byte, showSuccesses bool, showWarnings bool, expansion *ExpansionInfo) (Report, error) {
132+
func NewReport(snapshot string, components []Component, policy policy.Policy, policyInput [][]byte, showSuccesses bool, showWarnings bool, showPolicyDocsLink bool, expansion *ExpansionInfo) (Report, error) {
132133
success := true
133134

134135
// Set the report success, remains true if all components are successful
@@ -149,18 +150,19 @@ func NewReport(snapshot string, components []Component, policy policy.Policy, po
149150
info, _ := version.ComputeInfo()
150151

151152
return Report{
152-
Snapshot: snapshot,
153-
Success: success,
154-
Components: components,
155-
created: time.Now().UTC(),
156-
Key: string(key),
157-
Policy: policy.Spec(),
158-
EcVersion: info.Version,
159-
PolicyInput: policyInput,
160-
EffectiveTime: policy.EffectiveTime().UTC(),
161-
ShowSuccesses: showSuccesses,
162-
ShowWarnings: showWarnings,
163-
Expansion: expansion,
153+
Snapshot: snapshot,
154+
Success: success,
155+
Components: components,
156+
created: time.Now().UTC(),
157+
Key: string(key),
158+
Policy: policy.Spec(),
159+
EcVersion: info.Version,
160+
PolicyInput: policyInput,
161+
EffectiveTime: policy.EffectiveTime().UTC(),
162+
ShowSuccesses: showSuccesses,
163+
ShowWarnings: showWarnings,
164+
ShowPolicyDocsLink: showPolicyDocsLink,
165+
Expansion: expansion,
164166
}, nil
165167
}
166168

@@ -264,6 +266,7 @@ func (r *Report) toSummary() summary {
264266
func (r *Report) applyOptions(opts format.Options) {
265267
r.ShowSuccesses = opts.ShowSuccesses
266268
r.ShowWarnings = opts.ShowWarnings
269+
r.ShowPolicyDocsLink = opts.ShowPolicyDocsLink
267270
}
268271

269272
// condensedMsg reduces repetitive error messages.

0 commit comments

Comments
 (0)