Skip to content

Commit 1e06245

Browse files
WIP
1 parent 4e2ba2f commit 1e06245

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

attest/manifest/manifest.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ func MakeDirContentsStatement(dir string, entries *types.PathCheckSummaryCollect
4242
}
4343
}
4444

45+
func MakeDirContentsStatementFrom(statement types.Statement) DirContents {
46+
dirContents := DirContents{
47+
GenericStatement: attestTypes.GenericStatement[SourceDirectory]{},
48+
}
49+
dirContents.ConvertFrom(statement)
50+
return dirContents
51+
}
52+
4553
func (a SourceDirectory) Compare(b SourceDirectory) types.Cmp {
4654
if cmp := cmp.Compare(a.Path, b.Path); cmp != 0 {
4755
return &cmp

attest/types/types.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,30 @@ func Export(s ExportableStatement) toto.Statement {
119119
}
120120
}
121121

122+
func FilterByPredicateType(t string, s Statements) Statements {
123+
results := Statements{}
124+
for i := range s {
125+
if s[i].GetType() == t {
126+
results = append(results, s[i])
127+
}
128+
}
129+
return results
130+
}
131+
132+
type StamentConverter[T any] struct {
133+
Statement
134+
}
135+
136+
func (s *GenericStatement[T]) ConvertFrom(statement Statement) error {
137+
predicate, ok := s.GetPredicate().(ComparablePredicate[T])
138+
if !ok {
139+
return fmt.Errorf("cannot convert statement with predicte of type %T into %T", s.GetPredicate(), GenericStatement[T]{})
140+
}
141+
142+
*s = MakeStatement[T](s.GetType(), predicate, s.GetSubject()...)
143+
return nil
144+
}
145+
122146
func (s Statements) Export() []toto.Statement {
123147
statements := make([]toto.Statement, len(s))
124148
for i := range s {

oci/artefact.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/google/go-containerregistry/pkg/v1/tarball"
2424
typesv1 "github.com/google/go-containerregistry/pkg/v1/types"
2525

26+
"github.com/docker/labs-brown-tape/attest/manifest"
2627
attestTypes "github.com/docker/labs-brown-tape/attest/types"
2728
manifestTypes "github.com/docker/labs-brown-tape/manifest/types"
2829
)
@@ -223,6 +224,10 @@ func (c *Client) PushArtefact(ctx context.Context, destinationRef, sourceDir str
223224
}
224225
defer os.RemoveAll(tmpDir)
225226

227+
_, err = SemVerFromAttestations(ctx, sourceAttestations...)
228+
if err != nil {
229+
return "", err
230+
}
226231
tmpFile := filepath.Join(tmpDir, "artefact.tgz")
227232

228233
outputFile, err := os.OpenFile(tmpFile, os.O_RDWR|os.O_CREATE|os.O_EXCL, regularFileMode)
@@ -348,6 +353,20 @@ func (c *Client) PushArtefact(ctx context.Context, destinationRef, sourceDir str
348353
return tagAlias.String() + "@" + digest.String(), err
349354
}
350355

356+
func SemVerFromAttestations(ctx context.Context, sourceAttestations ...attestTypes.Statement) (string, error) {
357+
statements := attestTypes.FilterByPredicateType(manifest.ManifestDirPredicateType, sourceAttestations)
358+
if len(statements) == 0 {
359+
return "", fmt.Errorf("VCS provinance attestion (%q) not found", manifest.ManifestDirPredicateType)
360+
}
361+
if len(statements) > 1 {
362+
return "", fmt.Errorf("too many attestations of type %q found, expected 1", manifest.ManifestDirPredicateType)
363+
}
364+
365+
_ = manifest.MakeDirContentsStatementFrom(statements[0])
366+
367+
return "", nil
368+
}
369+
351370
func makeDescriptorWithPlatform() Descriptor {
352371
return Descriptor{
353372
Platform: &Platform{

0 commit comments

Comments
 (0)