Skip to content

Commit db65f06

Browse files
authored
Merge pull request #2314 from cuipinghuo/ec-1061
dropping the data output target
2 parents 7ecce20 + 5961b7b commit db65f06

23 files changed

+55
-107
lines changed

cmd/validate/common_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ type mockEvaluator struct {
4141
mock.Mock
4242
}
4343

44-
func (e *mockEvaluator) Evaluate(ctx context.Context, target evaluator.EvaluationTarget) ([]evaluator.Outcome, evaluator.Data, error) {
44+
func (e *mockEvaluator) Evaluate(ctx context.Context, target evaluator.EvaluationTarget) ([]evaluator.Outcome, error) {
4545
args := e.Called(ctx, target.Inputs)
4646

47-
return args.Get(0).([]evaluator.Outcome), args.Get(1).(evaluator.Data), args.Error(2)
47+
return args.Get(0).([]evaluator.Outcome), args.Error(1)
4848
}
4949

5050
func (e *mockEvaluator) Destroy() {

cmd/validate/image.go

+1-11
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,6 @@ func validateImageCmd(validate imageValidationFunc) *cobra.Command {
170170
171171
ec validate image --image registry/name:tag --output yaml --output appstudio=<path>
172172
173-
Write the data used in the policy evaluation to a file in YAML format
174-
175-
ec validate image --image registry/name:tag --output data=<path>
176173
177174
Validate a single image with keyless workflow.
178175
@@ -302,7 +299,6 @@ func validateImageCmd(validate imageValidationFunc) *cobra.Command {
302299
type result struct {
303300
err error
304301
component applicationsnapshot.Component
305-
data []evaluator.Data
306302
policyInput []byte
307303
}
308304

@@ -382,7 +378,6 @@ func validateImageCmd(validate imageValidationFunc) *cobra.Command {
382378
res.component.Attestations = append(res.component.Attestations, attResult)
383379
}
384380
res.component.ContainerImage = out.ImageURL
385-
res.data = out.Data
386381
res.policyInput = out.PolicyInput
387382
}
388383
res.component.Success = err == nil && len(res.component.Violations) == 0
@@ -415,7 +410,6 @@ func validateImageCmd(validate imageValidationFunc) *cobra.Command {
415410
close(jobs)
416411

417412
var components []applicationsnapshot.Component
418-
var evaluatorData [][]evaluator.Data
419413
var manyPolicyInput [][]byte
420414
var allErrors error = nil
421415
for i := 0; i < numComponents; i++ {
@@ -425,10 +419,6 @@ func validateImageCmd(validate imageValidationFunc) *cobra.Command {
425419
allErrors = errors.Join(allErrors, e)
426420
} else {
427421
components = append(components, r.component)
428-
// evaluator data is duplicated per component, so only collect it once.
429-
if len(evaluatorData) == 0 && containsOutput(data.output, "data") {
430-
evaluatorData = append(evaluatorData, r.data)
431-
}
432422
manyPolicyInput = append(manyPolicyInput, r.policyInput)
433423
}
434424
}
@@ -446,7 +436,7 @@ func validateImageCmd(validate imageValidationFunc) *cobra.Command {
446436
data.output = append(data.output, fmt.Sprintf("%s=%s", applicationsnapshot.JSON, data.outputFile))
447437
}
448438

449-
report, err := applicationsnapshot.NewReport(data.snapshot, components, data.policy, evaluatorData, manyPolicyInput, showSuccesses)
439+
report, err := applicationsnapshot.NewReport(data.snapshot, components, data.policy, manyPolicyInput, showSuccesses)
450440
if err != nil {
451441
return err
452442
}

cmd/validate/image_integration_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func TestEvaluatorLifecycle(t *testing.T) {
6161

6262
for i := 0; i < noEvaluators; i++ {
6363
e := mockEvaluator{}
64-
call := e.On("Evaluate", ctx, mock.Anything).Return([]evaluator.Outcome{}, evaluator.Data{}, nil)
64+
call := e.On("Evaluate", ctx, mock.Anything).Return([]evaluator.Outcome{}, nil)
6565

6666
evaluators = append(evaluators, &e)
6767
expectations = append(expectations, call)
@@ -84,7 +84,7 @@ func TestEvaluatorLifecycle(t *testing.T) {
8484

8585
validate := func(_ context.Context, component app.SnapshotComponent, _ *app.SnapshotSpec, _ policy.Policy, evaluators []evaluator.Evaluator, _ bool) (*output.Output, error) {
8686
for _, e := range evaluators {
87-
_, _, err := e.Evaluate(ctx, evaluator.EvaluationTarget{Inputs: []string{}})
87+
_, err := e.Evaluate(ctx, evaluator.EvaluationTarget{Inputs: []string{}})
8888
require.NoError(t, err)
8989
}
9090

cmd/validate/input.go

+1-11
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"github.com/spf13/cobra"
3030

3131
"github.com/enterprise-contract/ec-cli/internal/applicationsnapshot"
32-
"github.com/enterprise-contract/ec-cli/internal/evaluator"
3332
"github.com/enterprise-contract/ec-cli/internal/format"
3433
"github.com/enterprise-contract/ec-cli/internal/input"
3534
"github.com/enterprise-contract/ec-cli/internal/output"
@@ -114,7 +113,6 @@ func validateInputCmd(validate InputValidationFunc) *cobra.Command {
114113
type result struct {
115114
err error
116115
input input.Input
117-
data []evaluator.Data
118116
policyInput []byte
119117
}
120118

@@ -155,9 +153,6 @@ func validateInputCmd(validate InputValidationFunc) *cobra.Command {
155153
if showSuccesses {
156154
res.input.Successes = successes
157155
}
158-
if containsOutput(data.output, "data") {
159-
res.data = out.Data
160-
}
161156
res.input.Success = (len(res.input.Violations) == 0)
162157
res.policyInput = out.PolicyInput
163158
}
@@ -182,7 +177,6 @@ func validateInputCmd(validate InputValidationFunc) *cobra.Command {
182177
close(jobs)
183178

184179
var inputs []input.Input
185-
var evaluatorData [][]evaluator.Data
186180
var manyPolicyInput [][]byte
187181
var allErrors error = nil
188182

@@ -194,10 +188,6 @@ func validateInputCmd(validate InputValidationFunc) *cobra.Command {
194188
allErrors = errors.Join(allErrors, e)
195189
} else {
196190
inputs = append(inputs, r.input)
197-
// evaluator data is duplicated per input, so only collect it once.
198-
if len(evaluatorData) == 0 && containsOutput(data.output, "data") {
199-
evaluatorData = append(evaluatorData, r.data)
200-
}
201191
manyPolicyInput = append(manyPolicyInput, r.policyInput)
202192
}
203193
}
@@ -212,7 +202,7 @@ func validateInputCmd(validate InputValidationFunc) *cobra.Command {
212202
return inputs[i].FilePath > inputs[j].FilePath
213203
})
214204

215-
report, err := input.NewReport(inputs, data.policy, evaluatorData, manyPolicyInput)
205+
report, err := input.NewReport(inputs, data.policy, manyPolicyInput)
216206
if err != nil {
217207
return err
218208
}

docs/modules/ROOT/pages/ec_validate_image.adoc

+1-4
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,6 @@ Write output in YAML format to stdout and in appstudio format to a file
9393

9494
ec validate image --image registry/name:tag --output yaml --output appstudio=<path>
9595

96-
Write the data used in the policy evaluation to a file in YAML format
97-
98-
ec validate image --image registry/name:tag --output data=<path>
9996

10097
Validate a single image with keyless workflow.
10198

@@ -137,7 +134,7 @@ rule. (Default: false)
137134
--no-color:: Disable color when using text output even when the current terminal supports it (Default: false)
138135
--output:: write output to a file in a specific format. Use empty string path for stdout.
139136
May be used multiple times. Possible formats are:
140-
json, yaml, text, appstudio, summary, summary-markdown, junit, data, attestation, policy-input, vsa. In following format and file path
137+
json, yaml, text, appstudio, summary, summary-markdown, junit, attestation, policy-input, vsa. In following format and file path
141138
additional options can be provided in key=value form following the question
142139
mark (?) sign, for example: --output text=output.txt?show-successes=false
143140
(Default: [])

docs/modules/ROOT/pages/ec_validate_input.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ violations, include the title and the description of the failed policy
4949
rule. (Default: false)
5050
-o, --output:: Write output to a file in a specific format, e.g. yaml=/tmp/output.yaml. Use empty string
5151
path for stdout, e.g. yaml. May be used multiple times. Possible formats are:
52-
json, yaml, text, appstudio, summary, summary-markdown, junit, data, attestation, policy-input, vsa. In following format and file path
52+
json, yaml, text, appstudio, summary, summary-markdown, junit, attestation, policy-input, vsa. In following format and file path
5353
additional options can be provided in key=value form following the question
5454
mark (?) sign, for example: --output text=output.txt?show-successes=false
5555
(Default: [])

features/validate_image.feature

+1-2
Original file line numberDiff line numberDiff line change
@@ -700,10 +700,9 @@ Feature: evaluate enterprise contract
700700
]
701701
}
702702
"""
703-
When ec command is run with "validate image --image ${REGISTRY}/acceptance/image --policy acceptance/ec-policy --rekor-url ${REKOR} --public-key ${known_PUBLIC_KEY} --output=json --output data=${TMPDIR}/custom-rule-data.yaml --effective-time 2014-05-31 --show-successes"
703+
When ec command is run with "validate image --image ${REGISTRY}/acceptance/image --policy acceptance/ec-policy --rekor-url ${REKOR} --public-key ${known_PUBLIC_KEY} --output=json --effective-time 2014-05-31 --show-successes"
704704
Then the exit status should be 0
705705
And the output should match the snapshot
706-
And the "${TMPDIR}/custom-rule-data.yaml" file should match the snapshot
707706

708707
Scenario: mismatched image digest in signature
709708
Given a key pair named "known"

internal/applicationsnapshot/report.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ const (
103103
Summary = "summary"
104104
SummaryMarkdown = "summary-markdown"
105105
JUnit = "junit"
106-
Data = "data"
107106
Attestation = "attestation"
108107
PolicyInput = "policy-input"
109108
VSA = "vsa"
@@ -119,15 +118,14 @@ var OutputFormats = []string{
119118
Summary,
120119
SummaryMarkdown,
121120
JUnit,
122-
Data,
123121
Attestation,
124122
PolicyInput,
125123
VSA,
126124
}
127125

128126
// WriteReport returns a new instance of Report representing the state of
129127
// components from the snapshot.
130-
func NewReport(snapshot string, components []Component, policy policy.Policy, data any, policyInput [][]byte, showSuccesses bool) (Report, error) {
128+
func NewReport(snapshot string, components []Component, policy policy.Policy, policyInput [][]byte, showSuccesses bool) (Report, error) {
131129
success := true
132130

133131
// Set the report success, remains true if all components are successful
@@ -155,7 +153,6 @@ func NewReport(snapshot string, components []Component, policy policy.Policy, da
155153
Key: string(key),
156154
Policy: policy.Spec(),
157155
EcVersion: info.Version,
158-
Data: data,
159156
PolicyInput: policyInput,
160157
EffectiveTime: policy.EffectiveTime().UTC(),
161158
ShowSuccesses: showSuccesses,
@@ -209,8 +206,6 @@ func (r *Report) toFormat(format string) (data []byte, err error) {
209206
data, err = generateMarkdownSummary(r)
210207
case JUnit:
211208
data, err = xml.Marshal(r.toJUnit())
212-
case Data:
213-
data, err = yaml.Marshal(r.Data)
214209
case Attestation:
215210
data, err = r.renderAttestations()
216211
case PolicyInput:

internal/applicationsnapshot/report_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func Test_ReportJson(t *testing.T) {
5151

5252
ctx := context.Background()
5353
testPolicy := createTestPolicy(t, ctx)
54-
report, err := NewReport("snappy", components, testPolicy, "data here", nil, true)
54+
report, err := NewReport("snappy", components, testPolicy, nil, true)
5555
assert.NoError(t, err)
5656

5757
testEffectiveTime := testPolicy.EffectiveTime().UTC().Format(time.RFC3339Nano)
@@ -109,7 +109,7 @@ func Test_ReportYaml(t *testing.T) {
109109

110110
ctx := context.Background()
111111
testPolicy := createTestPolicy(t, ctx)
112-
report, err := NewReport("snappy", components, testPolicy, "data here", nil, true)
112+
report, err := NewReport("snappy", components, testPolicy, nil, true)
113113
assert.NoError(t, err)
114114

115115
testEffectiveTime := testPolicy.EffectiveTime().UTC().Format(time.RFC3339Nano)
@@ -256,7 +256,7 @@ func Test_GenerateMarkdownSummary(t *testing.T) {
256256
for _, c := range cases {
257257
t.Run(c.name, func(t *testing.T) {
258258
ctx := context.Background()
259-
report, err := NewReport(c.snapshot, c.components, createTestPolicy(t, ctx), nil, nil, true)
259+
report, err := NewReport(c.snapshot, c.components, createTestPolicy(t, ctx), nil, true)
260260
assert.NoError(t, err)
261261
report.created = time.Unix(0, 0).UTC()
262262

@@ -503,7 +503,7 @@ func Test_ReportSummary(t *testing.T) {
503503
for _, tc := range tests {
504504
t.Run(fmt.Sprintf("NewReport=%s", tc.name), func(t *testing.T) {
505505
ctx := context.Background()
506-
report, err := NewReport(tc.snapshot, []Component{tc.input}, createTestPolicy(t, ctx), "data here", nil, true)
506+
report, err := NewReport(tc.snapshot, []Component{tc.input}, createTestPolicy(t, ctx), nil, true)
507507
assert.NoError(t, err)
508508
assert.Equal(t, tc.want, report.toSummary())
509509
})
@@ -640,7 +640,7 @@ func Test_ReportAppstudio(t *testing.T) {
640640
assert.NoError(t, err)
641641

642642
ctx := context.Background()
643-
report, err := NewReport(c.snapshot, c.components, createTestPolicy(t, ctx), nil, nil, true)
643+
report, err := NewReport(c.snapshot, c.components, createTestPolicy(t, ctx), nil, true)
644644
assert.NoError(t, err)
645645
assert.False(t, report.created.IsZero())
646646
assert.Equal(t, c.success, report.Success)
@@ -788,7 +788,7 @@ func Test_ReportHACBS(t *testing.T) {
788788
assert.NoError(t, err)
789789

790790
ctx := context.Background()
791-
report, err := NewReport(c.snapshot, c.components, createTestPolicy(t, ctx), "data here", nil, true)
791+
report, err := NewReport(c.snapshot, c.components, createTestPolicy(t, ctx), nil, true)
792792
assert.NoError(t, err)
793793
assert.False(t, report.created.IsZero())
794794
assert.Equal(t, c.success, report.Success)
@@ -820,7 +820,7 @@ func Test_ReportPolicyInput(t *testing.T) {
820820
}
821821

822822
ctx := context.Background()
823-
report, err := NewReport("snapshot", nil, createTestPolicy(t, ctx), "data", policyInput, true)
823+
report, err := NewReport("snapshot", nil, createTestPolicy(t, ctx), policyInput, true)
824824
require.NoError(t, err)
825825

826826
p := format.NewTargetParser(JSON, format.Options{}, defaultWriter, fs)

internal/applicationsnapshot/vsa_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func TestNewVSA(t *testing.T) {
6060
})
6161
assert.NoError(t, err)
6262

63-
report, err := NewReport("snappy", components, testPolicy, "data here", nil, true)
63+
report, err := NewReport("snappy", components, testPolicy, nil, true)
6464
assert.NoError(t, err)
6565

6666
expected := ProvenanceStatementVSA{

internal/evaluator/__snapshots__/conftest_evaluator_test.snap

-16
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,4 @@
7878
},
7979
},
8080
}
81-
evaluator.Data{
82-
"config": map[string]interface {}{
83-
"default_sigstore_opts": map[string]interface {}{
84-
"certificate_identity": "cert-identity",
85-
"certificate_identity_regexp": "cert-identity-regexp",
86-
"certificate_oidc_issuer": "cert-oidc-issuer",
87-
"certificate_oidc_issuer_regexp": "cert-oidc-issuer-regexp",
88-
"ignore_rekor": bool(true),
89-
"public_key": "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAECBtqKHcvxYkGx7ZXqps3nrYS+ZSA\nmh3m1MZfTGlnr2oN0z+sBWEC23s4RkVSXkEydI6SLYatUtJK8OmiBRS+Xw==\n-----END PUBLIC KEY-----\n",
90-
"rekor_url": "https://rekor.local/",
91-
},
92-
"policy": map[string]interface {}{
93-
"when_ns": "1401494400000000000",
94-
},
95-
},
96-
}
9781
---

0 commit comments

Comments
 (0)