Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves #522 set Created date to time of execution #2108

Merged
merged 6 commits into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pkg/oci/mutate/signatures.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
package mutate

import (
"log"
"time"

v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/empty"
"github.com/google/go-containerregistry/pkg/v1/mutate"
Expand All @@ -36,10 +39,21 @@ func AppendSignatures(base oci.Signatures, sigs ...oci.Signature) (oci.Signature
Annotations: ann,
})
}

img, err := mutate.Append(base, adds...)

imgCfg, _ := img.ConfigFile()

// Set the Created date to time of execution
if imgCfg.Created.Time.IsZero() {
log.Println("Signed Entry Date was Zero, Setting to current time")
Lerentis marked this conversation as resolved.
Show resolved Hide resolved
img, _ = mutate.CreatedAt(img, v1.Time{Time: time.Now()})
}

Lerentis marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, err
}

return &sigAppender{
Image: img,
base: base,
Expand Down
11 changes: 11 additions & 0 deletions pkg/oci/static/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package static

import (
"io"
"log"
"time"

v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/empty"
Expand All @@ -41,6 +43,15 @@ func NewFile(payload []byte, opts ...Option) (oci.File, error) {
img, err := mutate.Append(base, mutate.Addendum{
Layer: layer,
})

Lerentis marked this conversation as resolved.
Show resolved Hide resolved
imgCfg, _ := img.ConfigFile()

// Set the Created date to time of execution
if imgCfg.Created.Time.IsZero() {
log.Println("Signed Entry Date was Zero, Setting to current time")
img, err = mutate.CreatedAt(img, v1.Time{Time: time.Now()})
}

Lerentis marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, err
}
Expand Down