Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCP: temporary hack to proxy read requests to GCS #70

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Classic denial of any responsibility here :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably your fault, to be fair. :)

_, _ = 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
Loading