sumweb

package standard library
go1.13.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 6, 2020 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Overview

Package sumweb implements the HTTP protocols for serving or accessing a go.sum database.

Index

Constants

This section is empty.

Variables

View Source
var ErrGONOSUMDB = errors.New("skipped (listed in GONOSUMDB)")

ErrGONOSUMDB is returned by Lookup for paths that match a pattern listed in the GONOSUMDB list (set by SetGONOSUMDB, usually from the environment variable).

View Source
var ErrSecurity = errors.New("security error: misbehaving server")

ErrSecurity is returned by Conn operations that invoke Client.SecurityError.

View Source
var ErrWriteConflict = errors.New("write conflict")

ErrWriteConflict signals a write conflict during Client.WriteConfig.

View Source
var Paths = []string{
	"/lookup/",
	"/latest",
	"/tile/",
}

Paths are the URL paths for which Handler should be invoked.

Typically a server will do:

handler := &sumweb.Handler{Server: srv}
for _, path := range sumweb.Paths {
	http.HandleFunc(path, handler)
}

Functions

This section is empty.

Types

type Client

type Client interface {
	// ReadRemote reads and returns the content served at the given path
	// on the remote database server. The path begins with "/lookup" or "/tile/".
	// It is the implementation's responsibility to turn that path into a full URL
	// and make the HTTP request. ReadRemote should return an error for
	// any non-200 HTTP response status.
	ReadRemote(path string) ([]byte, error)

	// ReadConfig reads and returns the content of the named configuration file.
	// There are only a fixed set of configuration files.
	//
	// "key" returns a file containing the verifier key for the server.
	//
	// serverName + "/latest" returns a file containing the latest known
	// signed tree from the server. It is read and written (using WriteConfig).
	// To signal that the client wishes to start with an "empty" signed tree,
	// ReadConfig can return a successful empty result (0 bytes of data).
	ReadConfig(file string) ([]byte, error)

	// WriteConfig updates the content of the named configuration file,
	// changing it from the old []byte to the new []byte.
	// If the old []byte does not match the stored configuration,
	// WriteConfig must return ErrWriteConflict.
	// Otherwise, WriteConfig should atomically replace old with new.
	WriteConfig(file string, old, new []byte) error

	// ReadCache reads and returns the content of the named cache file.
	// Any returned error will be treated as equivalent to the file not existing.
	// There can be arbitrarily many cache files, such as:
	//	serverName/lookup/pkg@version
	//	serverName/tile/8/1/x123/456
	ReadCache(file string) ([]byte, error)

	// WriteCache writes the named cache file.
	WriteCache(file string, data []byte)

	// Log prints the given log message (such as with log.Print)
	Log(msg string)

	// SecurityError prints the given security error log message.
	// The Conn returns ErrSecurity from any operation that invokes SecurityError,
	// but the return value is mainly for testing. In a real program,
	// SecurityError should typically print the message and call log.Fatal or os.Exit.
	SecurityError(msg string)
}

A Client provides the external operations (file caching, HTTP fetches, and so on) needed to implement the HTTP client Conn. The methods must be safe for concurrent use by multiple goroutines.

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

A Conn is a client connection to a go.sum database. All the methods are safe for simultaneous use by multiple goroutines.

func NewConn

func NewConn(client Client) *Conn

NewConn returns a new Conn using the given Client.

func (*Conn) Lookup

func (c *Conn) Lookup(path, vers string) (lines []string, err error)

Lookup returns the go.sum lines for the given module path and version. The version may end in a /go.mod suffix, in which case Lookup returns the go.sum lines for the module's go.mod-only hash.

func (*Conn) SetGONOSUMDB

func (c *Conn) SetGONOSUMDB(list string)

SetGONOSUMDB sets the list of comma-separated GONOSUMDB patterns for the Conn. For any module path matching one of the patterns, Lookup will return ErrGONOSUMDB. Any call to SetGONOSUMDB must happen before the first call to Lookup.

func (*Conn) SetTileHeight

func (c *Conn) SetTileHeight(height int)

SetTileHeight sets the tile height for the Conn. Any call to SetTileHeight must happen before the first call to Lookup. If SetTileHeight is not called, the Conn defaults to tile height 8.

type Handler

type Handler struct {
	Server Server
}

A Handler is the go.sum database server handler, which should be invoked to serve the paths listed in Paths. The calling code is responsible for initializing Server.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Server

type Server interface {
	// NewContext returns the context to use for the request r.
	NewContext(r *http.Request) (context.Context, error)

	// Signed returns the signed hash of the latest tree.
	Signed(ctx context.Context) ([]byte, error)

	// ReadRecords returns the content for the n records id through id+n-1.
	ReadRecords(ctx context.Context, id, n int64) ([][]byte, error)

	// Lookup looks up a record by its associated key ("module@version"),
	// returning the record ID.
	Lookup(ctx context.Context, key string) (int64, error)

	// ReadTileData reads the content of tile t.
	// It is only invoked for hash tiles (t.L ≥ 0).
	ReadTileData(ctx context.Context, t tlog.Tile) ([]byte, error)
}

A Server provides the external operations (underlying database access and so on) needed to implement the HTTP server Handler.

type TestServer

type TestServer struct {
	// contains filtered or unexported fields
}

A TestServer is an in-memory implementation of Server for testing.

func NewTestServer

func NewTestServer(signer string, gosum func(path, vers string) ([]byte, error)) *TestServer

NewTestServer constructs a new TestServer that will sign its tree with the given signer key (see cmd/go/internal/note) and fetch new records as needed by calling gosum.

func (*TestServer) Lookup

func (s *TestServer) Lookup(ctx context.Context, key string) (int64, error)

func (*TestServer) NewContext

func (s *TestServer) NewContext(r *http.Request) (context.Context, error)

func (*TestServer) ReadRecords

func (s *TestServer) ReadRecords(ctx context.Context, id, n int64) ([][]byte, error)

func (*TestServer) ReadTileData

func (s *TestServer) ReadTileData(ctx context.Context, t tlog.Tile) ([]byte, error)

func (*TestServer) Signed

func (s *TestServer) Signed(ctx context.Context) ([]byte, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL