Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
errordeveloper committed Oct 10, 2023
1 parent 8620e45 commit f926dad
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
8 changes: 8 additions & 0 deletions attest/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ func MakeDirContentsStatement(dir string, entries *types.PathCheckSummaryCollect
}
}

func MakeDirContentsStatementFrom(statement types.Statement) DirContents {
dirContents := DirContents{
GenericStatement: attestTypes.GenericStatement[SourceDirectory]{},
}
dirContents.ConvertFrom(statement)
return dirContents
}

func (a SourceDirectory) Compare(b SourceDirectory) types.Cmp {
if cmp := cmp.Compare(a.Path, b.Path); cmp != 0 {
return &cmp
Expand Down
24 changes: 24 additions & 0 deletions attest/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,30 @@ func Export(s ExportableStatement) toto.Statement {
}
}

func FilterByPredicateType(t string, s Statements) Statements {
results := Statements{}
for i := range s {
if s[i].GetType() == t {
results = append(results, s[i])
}
}
return results
}

type StamentConverter[T any] struct {
Statement
}

func (s *GenericStatement[T]) ConvertFrom(statement Statement) error {
predicate, ok := s.GetPredicate().(ComparablePredicate[T])
if !ok {
return fmt.Errorf("cannot convert statement with predicte of type %T into %T", s.GetPredicate(), GenericStatement[T]{})
}

*s = MakeStatement[T](s.GetType(), predicate, s.GetSubject()...)
return nil
}

func (s Statements) Export() []toto.Statement {
statements := make([]toto.Statement, len(s))
for i := range s {
Expand Down
19 changes: 19 additions & 0 deletions oci/artefact.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/google/go-containerregistry/pkg/v1/tarball"
typesv1 "github.com/google/go-containerregistry/pkg/v1/types"

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

_, err = SemVerFromAttestations(ctx, sourceAttestations...)
if err != nil {
return "", err
}
tmpFile := filepath.Join(tmpDir, "artefact.tgz")

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

func SemVerFromAttestations(ctx context.Context, sourceAttestations ...attestTypes.Statement) (string, error) {
statements := attestTypes.FilterByPredicateType(manifest.ManifestDirPredicateType, sourceAttestations)
if len(statements) == 0 {
return "", fmt.Errorf("VCS provinance attestion (%q) not found", manifest.ManifestDirPredicateType)
}
if len(statements) > 1 {
return "", fmt.Errorf("too many attestations of type %q found, expected 1", manifest.ManifestDirPredicateType)
}

_ = manifest.MakeDirContentsStatementFrom(statements[0])

return "", nil
}

func makeDescriptorWithPlatform() Descriptor {
return Descriptor{
Platform: &Platform{
Expand Down

0 comments on commit f926dad

Please sign in to comment.