Skip to content
Open
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
2 changes: 0 additions & 2 deletions sumdb/cmd/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
var (
listen = flag.String("listen", ":8089", "Address to set up HTTP server listening on")
witnessSigs = flag.Uint("witnesses", 0, "Number of witness signatures required on a checkpoint. Setting this will pull checkpoints from the transparency-dev prod distributor.")
indexFile = flag.String("index", "", "Local path to an index.html file to serve at the log root /index.html")
)

func main() {
Expand All @@ -37,7 +36,6 @@ func main() {

proxy := sumdb.NewProxy(sumdb.ProxyOpts{
WitnessSigs: *witnessSigs,
IndexFile: *indexFile,
})
klog.Infof("tlog-tiles API listening on %s", *listen)
if err := http.ListenAndServe(*listen, proxy); err != nil {
Expand Down
17 changes: 6 additions & 11 deletions sumdb/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"io"

"k8s.io/klog/v2"
woodpeckerweb "github.com/transparency-dev/incubator/woodpecker-web"
)

const (
Expand All @@ -48,10 +49,6 @@ type ProxyOpts struct {
// distributor.
// https://github.com/transparency-dev/distributor/
WitnessSigs uint

// IndexFile is the local path to an index.html file to serve at the log root /index.html.
// If empty, nothing is served at /index.html.
IndexFile string
}

func newReverseProxy(opts ProxyOpts) *httputil.ReverseProxy {
Expand Down Expand Up @@ -118,21 +115,19 @@ func newReverseProxy(opts ProxyOpts) *httputil.ReverseProxy {
return proxy
}

// NewProxy returns an http.Handler that proxies to the appropriate SumDB upstream.
// If IndexFile is set in ProxyOpts, it also serves this file at /index.html.
func NewProxy(opts ProxyOpts) http.Handler {
proxy := newReverseProxy(opts)

if opts.IndexFile == "" {
return proxy
}

prefix, _ := strings.CutSuffix(opts.PathPrefix, "/")

return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
inPath := strings.TrimPrefix(r.URL.Path, prefix)
if inPath == "/index.html" || inPath == "/" {
http.ServeFile(w, r, opts.IndexFile)
w.Header().Set("Content-Type", "text/html")
w.WriteHeader(http.StatusOK)
if _, err := w.Write(woodpeckerweb.IndexHTML); err != nil {
klog.Warningf("failed to write index HTML: %v", err)
}
return
}
proxy.ServeHTTP(w, r)
Expand Down
21 changes: 19 additions & 2 deletions vindex/cmd/logandmap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import (
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
"golang.org/x/mod/sumdb/note"
"k8s.io/klog/v2"
woodpeckerweb "github.com/transparency-dev/incubator/woodpecker-web"
)

var (
Expand Down Expand Up @@ -311,8 +312,8 @@ func submitEntries(ctx context.Context, appender *tessera.Appender) {
func runWebServer(vi *vindex.VerifiableIndex, inLogDir, outLogDir string) (func(context.Context) error, error) {
srv := web.NewServer(vi.Lookup)

ilfs := http.FileServer(http.Dir(inLogDir))
olfs := http.FileServer(http.Dir(outLogDir))
ilfs := serveLogWithWoodpecker(inLogDir, woodpeckerweb.IndexHTML)
olfs := serveLogWithWoodpecker(outLogDir, woodpeckerweb.IndexHTML)
r := mux.NewRouter()
r.PathPrefix("/inputlog/").Handler(http.StripPrefix("/inputlog/", ilfs))
r.PathPrefix("/outputlog/").Handler(http.StripPrefix("/outputlog/", olfs))
Expand Down Expand Up @@ -405,3 +406,19 @@ func mapFnFromFlags() vindex.MapFn {
}
return mapFn
}

func serveLogWithWoodpecker(logDir string, woodpeckerHTML []byte) http.Handler {
fs := http.FileServer(http.Dir(logDir))
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/" || r.URL.Path == "/index.html" {
w.Header().Set("Content-Type", "text/html")
w.WriteHeader(http.StatusOK)
if _, err := w.Write(woodpeckerHTML); err != nil {
klog.Warningf("failed to write index HTML: %v", err)
}
return
}
fs.ServeHTTP(w, r)
})
}

6 changes: 4 additions & 2 deletions vindex/cmd/sumdbindex/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,11 @@ func run(ctx context.Context) error {
if err != nil {
return err
}
sumProxy := sumdb.NewProxy(sumdb.ProxyOpts{
sumProxyOpts := sumdb.ProxyOpts{
PathPrefix: "/inputlog/",
WitnessSigs: *witnessSigs,
})
}
sumProxy := sumdb.NewProxy(sumProxyOpts)

outputLog, outputCloser := outputLogOrDie(ctx, outputLogDir)
defer func() {
Expand Down Expand Up @@ -300,3 +301,4 @@ func mapFn(data []byte) [][32]byte {

return [][32]byte{sha256.Sum256(data[:modEnd])}
}

Loading
Loading