Skip to content

Commit

Permalink
GCP: temporary hack to proxy read requests to GCS (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCutter authored Jul 17, 2024
1 parent 842b908 commit d613ec4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cmd/example-gcp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"io"
"net/http"
"os"
"strings"

tessera "github.com/transparency-dev/trillian-tessera"
"github.com/transparency-dev/trillian-tessera/storage/gcp"
Expand Down Expand Up @@ -72,6 +73,21 @@ func main() {
_, _ = w.Write([]byte(fmt.Sprintf("%d", idx)))
})

// TODO: remove this proxy
serveGCS := func(w http.ResponseWriter, r *http.Request) {
resource := strings.TrimLeft(r.URL.Path, "/")
b, err := storage.Get(r.Context(), resource)
if err != nil {
klog.V(1).Infof("Get: %v", err)
w.WriteHeader(http.StatusBadRequest)
_, _ = w.Write([]byte(fmt.Sprintf("Get: %v", err)))
return
}
_, _ = w.Write(b)
}
http.HandleFunc("GET /checkpoint", serveGCS)
http.HandleFunc("GET /tile/", serveGCS)

if err := http.ListenAndServe(*listen, http.DefaultServeMux); err != nil {
klog.Exitf("ListenAndServe: %v", err)
}
Expand Down
10 changes: 10 additions & 0 deletions storage/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,17 @@ func (s *Storage) Add(ctx context.Context, e tessera.Entry) (uint64, error) {
return s.queue.Add(ctx, e)()
}

// Get returns the requested object.
//
// This is indended to be used to proxy read requests through the personality for debug/testing purposes.
func (s *Storage) Get(ctx context.Context, path string) ([]byte, error) {
d, _, err := s.objStore.getObject(ctx, path)
return d, err
}

// setTile idempotently stores the provided tile at the location implied by the given level, index, and treeSize.
//
// The location to which the tile is written is defined by the tile layout spec.
func (s *Storage) setTile(ctx context.Context, level, index, logSize uint64, tile *api.HashTile) error {
data, err := tile.MarshalText()
if err != nil {
Expand Down

0 comments on commit d613ec4

Please sign in to comment.