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 59aba29 commit 39dc0d1
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 @@ -44,15 +50,36 @@ func main() {
klog.Exitf("Invalid --source_url %q: %v", *sourceURL, err)
}
src, err := client.NewHTTPFetcher(srcURL, nil)

Check failure on line 52 in cmd/experimental/migrate/gcp/main.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to err (ineffassign)
// 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 39dc0d1

Please sign in to comment.