mirror of
https://github.com/moby/buildkit.git
synced 2026-08-07 16:20:46 +00:00
attestations: tidy up AddAttestation function
Signed-off-by: Justin Chadwell <me@jedevc.com>
This commit is contained in:
@@ -6489,24 +6489,22 @@ func testExportAttestations(t *testing.T, sb integration.Sandbox) {
|
||||
return nil, err
|
||||
}
|
||||
res.AddAttestation(pk, &result.InTotoAttestation{
|
||||
PredicateRefKey: "foo",
|
||||
PredicatePath: "/attestation.json",
|
||||
PredicateType: "https://example.com/attestations/v1.0",
|
||||
PredicatePath: "/attestation.json",
|
||||
PredicateType: "https://example.com/attestations/v1.0",
|
||||
Subjects: []result.InTotoSubject{
|
||||
&result.InTotoSubjectSelf{},
|
||||
},
|
||||
}, map[string]gateway.Reference{"foo": refAttest})
|
||||
}, refAttest)
|
||||
res.AddAttestation(pk, &result.InTotoAttestation{
|
||||
PredicateRefKey: "bar",
|
||||
PredicatePath: "/attestation2.json",
|
||||
PredicateType: "https://example.com/attestations2/v1.0",
|
||||
PredicatePath: "/attestation2.json",
|
||||
PredicateType: "https://example.com/attestations2/v1.0",
|
||||
Subjects: []result.InTotoSubject{
|
||||
&result.InTotoSubjectRaw{
|
||||
Name: "/attestation.json",
|
||||
Digest: []digest.Digest{successDigest},
|
||||
},
|
||||
},
|
||||
}, map[string]gateway.Reference{"bar": refAttest})
|
||||
}, refAttest)
|
||||
}
|
||||
|
||||
dt, err := json.Marshal(expPlatforms)
|
||||
|
||||
@@ -39,23 +39,19 @@ func (r *Result[T]) AddRef(k string, ref T) {
|
||||
r.mu.Unlock()
|
||||
}
|
||||
|
||||
func (r *Result[T]) AddAttestation(k string, v Attestation, refs map[string]T) {
|
||||
func (r *Result[T]) AddAttestation(k string, v Attestation, ref T) {
|
||||
r.mu.Lock()
|
||||
if r.Attestations == nil {
|
||||
r.Attestations = map[string][]Attestation{}
|
||||
}
|
||||
|
||||
// if the attestation refs aren't already internal, then insert them
|
||||
switch v := v.(type) {
|
||||
case *InTotoAttestation:
|
||||
if !strings.HasPrefix(v.PredicateRefKey, attestationRefPrefix) {
|
||||
internalKey := attestationRefPrefix + identity.NewID()
|
||||
r.Refs[internalKey] = refs[v.PredicateRefKey]
|
||||
v.PredicateRefKey = internalKey
|
||||
v.PredicateRefKey = "attestation:" + identity.NewID()
|
||||
r.Refs[v.PredicateRefKey] = ref
|
||||
}
|
||||
}
|
||||
r.Attestations[k] = append(r.Attestations[k], v)
|
||||
|
||||
r.mu.Unlock()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user