@@ -117,75 +117,33 @@ func NewContext(attestors []Attestor, opts ...AttestationContextOption) (*Attest
117
117
}
118
118
119
119
func (ctx * AttestationContext ) RunAttestors () error {
120
- preAttestors := []Attestor {}
121
- materialAttestors := []Attestor {}
122
- exeucteAttestors := []Attestor {}
123
- productAttestors := []Attestor {}
124
- postAttestors := []Attestor {}
125
-
120
+ attestors := make (map [RunType ][]Attestor )
126
121
for _ , attestor := range ctx .attestors {
127
- switch attestor .RunType () {
128
- case PreMaterialRunType :
129
- preAttestors = append (preAttestors , attestor )
130
-
131
- case MaterialRunType :
132
- materialAttestors = append (materialAttestors , attestor )
133
-
134
- case ExecuteRunType :
135
- exeucteAttestors = append (exeucteAttestors , attestor )
136
-
137
- case ProductRunType :
138
- productAttestors = append (productAttestors , attestor )
139
-
140
- case PostProductRunType :
141
- postAttestors = append (postAttestors , attestor )
142
-
143
- default :
122
+ if attestor .RunType () == "" {
144
123
return ErrInvalidOption {
145
- Option : "attestor. RunType" ,
124
+ Option : "RunType" ,
146
125
Reason : fmt .Sprintf ("unknown run type %v" , attestor .RunType ()),
147
126
}
148
127
}
149
128
}
150
129
151
- for _ , attestor := range preAttestors {
152
- if err := ctx .runAttestor (attestor ); err != nil {
153
- return err
154
- }
155
- }
156
-
157
- for _ , attestor := range materialAttestors {
158
- if err := ctx .runAttestor (attestor ); err != nil {
159
- return err
160
- }
161
- }
162
-
163
- for _ , attestor := range exeucteAttestors {
164
- if err := ctx .runAttestor (attestor ); err != nil {
165
- return err
166
- }
167
- }
168
-
169
- for _ , attestor := range productAttestors {
170
- if err := ctx .runAttestor (attestor ); err != nil {
171
- return err
172
- }
173
- }
174
-
175
- for _ , attestor := range postAttestors {
176
- if err := ctx .runAttestor (attestor ); err != nil {
177
- return err
130
+ for _ , atts := range attestors {
131
+ for _ , att := range atts {
132
+ log .Infof ("Starting %v attestor..." , att .Name ())
133
+ if err := ctx .runAttestor (att ); err != nil {
134
+ log .Errorf ("Error running %v attestor: %w" , att .Name (), err )
135
+ return err
136
+ }
178
137
}
179
138
}
180
139
181
140
return nil
182
141
}
183
142
184
143
func (ctx * AttestationContext ) runAttestor (attestor Attestor ) error {
185
- log .Infof ("Starting %v attestor..." , attestor .Name ())
186
144
startTime := time .Now ()
145
+ // NOTE: Not sure if this is the right place to check for an error running the attestor - might be better to let the caller handle it
187
146
if err := attestor .Attest (ctx ); err != nil {
188
- log .Errorf ("Error running %v attestor: %w" , attestor .Name (), err )
189
147
ctx .completedAttestors = append (ctx .completedAttestors , CompletedAttestor {
190
148
Attestor : attestor ,
191
149
StartTime : startTime ,
@@ -205,48 +163,34 @@ func (ctx *AttestationContext) runAttestor(attestor Attestor) error {
205
163
ctx .addMaterials (materialer )
206
164
}
207
165
208
- if producter , ok := attestor .(Producer ); ok {
209
- ctx .addProducts (producter )
166
+ if producer , ok := attestor .(Producer ); ok {
167
+ ctx .addProducts (producer )
210
168
}
211
169
212
170
return nil
213
171
}
214
172
215
173
func (ctx * AttestationContext ) CompletedAttestors () []CompletedAttestor {
216
- attestors := make ([]CompletedAttestor , len (ctx .completedAttestors ))
217
- copy (attestors , ctx .completedAttestors )
218
- return attestors
174
+ return ctx .completedAttestors
219
175
}
220
176
221
177
func (ctx * AttestationContext ) WorkingDir () string {
222
178
return ctx .workingDir
223
179
}
224
180
225
181
func (ctx * AttestationContext ) Hashes () []crypto.Hash {
226
- hashes := make ([]crypto.Hash , len (ctx .hashes ))
227
- copy (hashes , ctx .hashes )
228
- return hashes
182
+ return ctx .hashes
229
183
}
230
184
231
185
func (ctx * AttestationContext ) Context () context.Context {
232
186
return ctx .ctx
233
187
}
234
188
235
189
func (ctx * AttestationContext ) Materials () map [string ]cryptoutil.DigestSet {
236
- matCopy := make (map [string ]cryptoutil.DigestSet )
237
- for k , v := range ctx .materials {
238
- matCopy [k ] = v
239
- }
240
-
241
- return matCopy
190
+ return ctx .materials
242
191
}
243
192
244
193
func (ctx * AttestationContext ) Products () map [string ]Product {
245
- prodCopy := make (map [string ]Product )
246
- for k , v := range ctx .products {
247
- prodCopy [k ] = v
248
- }
249
-
250
194
return ctx .products
251
195
}
252
196
0 commit comments