Skip to content

Commit

Permalink
Hack in CT support to GCP so we can copy rome
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCutter committed Dec 11, 2024
1 parent 6ab3df9 commit cbe1840
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions cmd/experimental/migrate/gcp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
}
}
Expand Down

0 comments on commit cbe1840

Please sign in to comment.