From c82463102ecc065d29c6303e10dfd8f0d1329603 Mon Sep 17 00:00:00 2001 From: Al Cutter Date: Wed, 11 Dec 2024 17:03:29 +0000 Subject: [PATCH] Hack in CT support to GCP so we can copy rome --- cmd/experimental/migrate/gcp/main.go | 31 ++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/cmd/experimental/migrate/gcp/main.go b/cmd/experimental/migrate/gcp/main.go index d9d02b25..375aabd7 100644 --- a/cmd/experimental/migrate/gcp/main.go +++ b/cmd/experimental/migrate/gcp/main.go @@ -19,8 +19,14 @@ package main import ( "context" "flag" + "fmt" + "io" + "net/http" "net/url" + "strings" + tessera "github.com/transparency-dev/trillian-tessera" + "github.com/transparency-dev/trillian-tessera/api/layout" "github.com/transparency-dev/trillian-tessera/client" "github.com/transparency-dev/trillian-tessera/cmd/experimental/migrate/internal/migrate" "github.com/transparency-dev/trillian-tessera/storage/gcp" @@ -47,15 +53,36 @@ func main() { if err != nil { klog.Exitf("Failed to create HTTP fetcher: %v", err) } + // HACK CT: + readEntryBundle := func(ctx context.Context, i uint64, p uint8) ([]byte, error) { + up := strings.Replace(layout.EntriesPath(i, p), "entries", "data", 1) + reqURL, err := url.JoinPath(*sourceURL, up) + if err != nil { + return nil, err + } + req, err := http.NewRequestWithContext(ctx, "GET", reqURL, nil) + if err != nil { + return nil, err + } + rsp, err := http.DefaultClient.Do(req) + if err != nil { + return nil, err + } + defer rsp.Body.Close() + if rsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf("GET %q: %v", req.URL.Path, rsp.Status) + } + return io.ReadAll(rsp.Body) + } // Create our Tessera storage backend: gcpCfg := storageConfigFromFlags() - st, err := gcp.NewMigrationTarget(ctx, gcpCfg) + st, err := gcp.NewMigrationTarget(ctx, gcpCfg, tessera.WithCTLayout()) if err != nil { klog.Exitf("Failed to create new GCP storage: %v", err) } - if err := migrate.Migrate(context.Background(), *stateDB, src.ReadCheckpoint, src.ReadTile, src.ReadEntryBundle, st); err != nil { + if err := migrate.Migrate(context.Background(), *stateDB, src.ReadCheckpoint, src.ReadTile, readEntryBundle, st); err != nil { klog.Exitf("Migrate failed: %v", err) } }