From cb475076500a7c15ee6a3dc0fe898f402094f929 Mon Sep 17 00:00:00 2001 From: mrjoelkamp Date: Wed, 14 Aug 2024 14:54:21 -0500 Subject: [PATCH] chore: pr comments --- pkg/tuf/mock.go | 7 +++++-- pkg/tuf/tuf.go | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/tuf/mock.go b/pkg/tuf/mock.go index 5189483..9e0f870 100644 --- a/pkg/tuf/mock.go +++ b/pkg/tuf/mock.go @@ -4,6 +4,8 @@ import ( "io" "os" "path/filepath" + + "github.com/docker/attest/internal/util" ) type MockTufClient struct { @@ -25,7 +27,8 @@ func NewMockTufClient(srcPath string, dstPath string) *MockTufClient { } func (dc *MockTufClient) DownloadTarget(target string, filePath string) (file *TargetFile, err error) { - src, err := os.Open(filepath.Join(dc.srcPath, target)) + targetPath := filepath.Join(dc.srcPath, target) + src, err := os.Open(targetPath) if err != nil { return nil, err } @@ -56,7 +59,7 @@ func (dc *MockTufClient) DownloadTarget(target string, filePath string) (file *T return nil, err } - return &TargetFile{ActualFilePath: dstFilePath, Data: b}, nil + return &TargetFile{ActualFilePath: dstFilePath, TargetURI: targetPath, Data: b, Digest: util.SHA256Hex(b)}, nil } type MockVersionChecker struct { diff --git a/pkg/tuf/tuf.go b/pkg/tuf/tuf.go index c54eec0..71c949c 100644 --- a/pkg/tuf/tuf.go +++ b/pkg/tuf/tuf.go @@ -129,6 +129,8 @@ func NewClient(initialRoot []byte, tufPath, metadataSource, targetsSource string func (t *Client) generateTargetURI(target *metadata.TargetFiles, digest string) (string, error) { targetBaseURL := ensureTrailingSlash(t.cfg.RemoteTargetsURL) targetRemotePath := target.Path + // if PrefixTargetsWithHash is set, we need to prefix the target name with the hash and handle subdirectories + // similar logic to https://github.com/theupdateframework/go-tuf/blob/f95222bdd22d2ac4e5b8ed6fe912b645e213c3b5/metadata/updater/updater.go#L227-L247 if t.cfg.PrefixTargetsWithHash { baseName := filepath.Base(targetRemotePath) dirName, ok := strings.CutSuffix(targetRemotePath, "/"+baseName)