Files
attest/tuf/example_registry_test.go

40 lines
852 B
Go
Raw Normal View History

2024-05-02 13:42:35 -05:00
package tuf_test
2024-05-02 13:35:57 -05:00
import (
"context"
2024-05-02 13:35:57 -05:00
"os"
"path/filepath"
"github.com/docker/attest/tuf"
2024-05-02 13:35:57 -05:00
"github.com/theupdateframework/go-tuf/v2/metadata"
)
func ExampleNewClient_registry() {
2024-05-02 13:35:57 -05:00
// create a tuf client
home, err := os.UserHomeDir()
if err != nil {
panic(err)
}
tufOutputPath := filepath.Join(home, ".docker", "tuf")
opts := tuf.NewDockerDefaultClientOptions(tufOutputPath)
registryClient, err := tuf.NewClient(context.Background(), opts)
2024-05-02 13:35:57 -05:00
if err != nil {
panic(err)
}
// get trusted tuf metadata
trustedMetadata := registryClient.GetMetadata()
// top-level target files
targets := trustedMetadata.Targets[metadata.TARGETS].Signed.Targets
for _, t := range targets {
// download target files
_, err := registryClient.DownloadTarget(t.Path, filepath.Join(tufOutputPath, "download"))
2024-05-02 13:35:57 -05:00
if err != nil {
panic(err)
}
}
}