Route every remote manifest read through downloadManifestByKey
internal/vaultik/verify.go and internal/vaultik/info.go each built the metadata/<remote-key>/manifest.json.zst path and decoded the manifest inline, duplicating downloadManifestByKey. Both now call the helper. The manifest is currently stored compressed but unencrypted, which is what will let `snapshot list` enumerate the destination store on a host holding no private key. Whether to encrypt it is still open (#81), and a single reader means that decision has one call site to change rather than four. Refs #81
This commit is contained in:
@@ -9,7 +9,6 @@ import (
|
|||||||
|
|
||||||
"github.com/dustin/go-humanize"
|
"github.com/dustin/go-humanize"
|
||||||
"sneak.berlin/go/vaultik/internal/log"
|
"sneak.berlin/go/vaultik/internal/log"
|
||||||
"sneak.berlin/go/vaultik/internal/snapshot"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ShowInfo displays system and configuration information
|
// ShowInfo displays system and configuration information
|
||||||
@@ -312,20 +311,12 @@ func (v *Vaultik) collectReferencedBlobsFromManifests(
|
|||||||
referencedBlobs := make(map[string]int64)
|
referencedBlobs := make(map[string]int64)
|
||||||
|
|
||||||
for _, snapshotID := range snapshotIDs {
|
for _, snapshotID := range snapshotIDs {
|
||||||
manifestKey := fmt.Sprintf("metadata/%s/manifest.json.zst", snapshotID)
|
// snapshotIDs here are remote keys, taken straight from the
|
||||||
|
// metadata/ listing. downloadManifestByKey is the single reader
|
||||||
reader, err := v.Storage.Get(v.ctx, manifestKey)
|
// for remote manifests; see its doc comment.
|
||||||
|
manifest, err := v.downloadManifestByKey(snapshotID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn("Failed to get manifest", "snapshot", snapshotID, "error", err)
|
log.Warn("Failed to read manifest", "snapshot", snapshotID, "error", err)
|
||||||
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
manifest, err := snapshot.DecodeManifest(reader)
|
|
||||||
_ = reader.Close()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Warn("Failed to decode manifest", "snapshot", snapshotID, "error", err)
|
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,30 +141,21 @@ func (v *Vaultik) loadVerificationData(
|
|||||||
// All remote paths use the hashed key derived from the human ID.
|
// All remote paths use the hashed key derived from the human ID.
|
||||||
remoteKey := snapshot.RemoteSnapshotKey(snapshotID)
|
remoteKey := snapshot.RemoteSnapshotKey(snapshotID)
|
||||||
|
|
||||||
// Download manifest
|
// Download manifest. downloadManifestByKey is the single reader for
|
||||||
manifestPath := fmt.Sprintf("metadata/%s/manifest.json.zst", remoteKey)
|
// remote manifests; see its doc comment.
|
||||||
log.Info("Downloading manifest", "path", manifestPath)
|
log.Info("Downloading manifest", "remote_key", remoteKey)
|
||||||
|
|
||||||
if !opts.JSON {
|
if !opts.JSON {
|
||||||
v.stdoutf("Downloading manifest...\n")
|
v.stdoutf("Downloading manifest...\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
manifestReader, err := v.Storage.Get(v.ctx, manifestPath)
|
manifest, err := v.downloadManifestByKey(remoteKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, v.deepVerifyFailure(result, opts,
|
return nil, nil, nil, v.deepVerifyFailure(result, opts,
|
||||||
fmt.Sprintf("failed to download manifest: %v", err),
|
fmt.Sprintf("failed to download manifest: %v", err),
|
||||||
fmt.Errorf("failed to download manifest: %w", err))
|
fmt.Errorf("failed to download manifest: %w", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() { _ = manifestReader.Close() }()
|
|
||||||
|
|
||||||
manifest, err := snapshot.DecodeManifest(manifestReader)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, nil, v.deepVerifyFailure(result, opts,
|
|
||||||
fmt.Sprintf("failed to decode manifest: %v", err),
|
|
||||||
fmt.Errorf("failed to decode manifest: %w", err))
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Info("Manifest loaded",
|
log.Info("Manifest loaded",
|
||||||
"manifest_blob_count", manifest.BlobCount,
|
"manifest_blob_count", manifest.BlobCount,
|
||||||
"manifest_total_size", ubytes(manifest.TotalCompressedSize))
|
"manifest_total_size", ubytes(manifest.TotalCompressedSize))
|
||||||
|
|||||||
Reference in New Issue
Block a user