luci: Index | Files | Directories

package server

import ""

Package server implements an environment for running LUCI servers.


Package Files



var DefaultOAuthScopes = []string{

DefaultOAuthScopes is a list of OAuth scopes we want a local user to grant us when running the server locally.

type Options Uses

type Options struct {
    Prod             bool               // must be set when running in production
    HTTPAddr         string             // address to bind the main listening socket to
    AdminAddr        string             // address to bind the admin socket to
    RootSecretPath   string             // path to a JSON file with the root secret key
    SettingsPath     string             // path to a JSON file with app settings
    ClientAuth       clientauth.Options // base settings for client auth options
    TokenCacheDir    string             // where to cache auth tokens (optional)
    AuthDBPath       string             // if set, load AuthDB from a file
    CloudProject     string             // name of hosting Google Cloud Project
    TsMonAccount     string             // service account to flush metrics as
    TsMonServiceName string             // service name of tsmon target
    TsMonJobName     string             // job name of tsmon target
    // contains filtered or unexported fields

Options are exposed as command line flags.

func (*Options) Register Uses

func (o *Options) Register(f *flag.FlagSet)

Register registers the command line flags.

type Server Uses

type Server struct {
    Routes *router.Router // HTTP routes exposed via opts.HTTPAddr
    // contains filtered or unexported fields

Server is responsible for initializing and launching the serving environment.

Doesn't do TLS. Should be sitting behind a load balancer that terminates TLS.

func New Uses

func New(opts Options) *Server

New constructs a new server instance.

It hosts one or more HTTP servers and starts and stops them in unison. It is also responsible for preparing contexts for incoming requests.

func (*Server) Fatal Uses

func (s *Server) Fatal(err error)

Fatal logs the error and immediately shuts down the process with exit code 3.

No cleanup is performed. Deferred statements are not run. Not recoverable.

func (*Server) ListenAndServe Uses

func (s *Server) ListenAndServe() error

ListenAndServe launches the serving loop.

Blocks forever or until the server is stopped via Shutdown (from another goroutine or from a SIGTERM handler). Returns nil if the server was shutdown correctly or an error if it failed to start or unexpectedly died. The error is logged inside.

Should be called only once. Panics otherwise.

func (*Server) RegisterHTTP Uses

func (s *Server) RegisterHTTP(addr string) *router.Router

RegisterHTTP prepares an additional HTTP server.

Can be used to open more listening HTTP ports (in addition to opts.HTTPAddr and opts.AdminAddr). Returns a router that should be populated with routes exposed through the added server.

Should be called before ListenAndServe (panics otherwise).

func (*Server) RunInBackground Uses

func (s *Server) RunInBackground(activity string, f func(context.Context))

RunInBackground launches the given callback in a separate goroutine right before starting the serving loop.

If the server is already running, launches it right away. If the server fails to start, the goroutines will never be launched.

Should be used for background asynchronous activities like reloading configs.

All logs lines emitted by the callback are annotated with "activity" field which can be arbitrary, but by convention has format "<namespace>.<name>", where "luci" namespace is reserved for internal activities.

The callback receives a context with following services available:

* Logging.
* Process cache.
* Secrets.
* Access to app settings.
* Making authenticated calls.

The context passed to the callback is canceled when the server is shutting down. It is expected the goroutine will exit soon after the context is canceled.

func (*Server) Shutdown Uses

func (s *Server) Shutdown()

Shutdown gracefully stops the server if it was running.

Blocks until the server is stopped. Can be called multiple times.


analyticsPackage analytics provides a standard way to store the Google Analytics tracking ID.
authPackage auth implements authentication and authorization framework for HTTP servers.
auth/authdbPackage authdb contains definition of Authentication Database (aka AuthDB).
auth/authtestPackage authtest implements some interfaces used by auth package to simplify unit testing.
auth/delegationPackage delegation contains low-level API for working with delegation tokens.
auth/openidPackage openid implements OpenID Connect Login protocol (client side).
auth/servicePackage service implements a wrapper around API exposed by auth_service:
auth/signingPackage signing provides interfaces to sign arbitrary small blobs with RSA-SHA256 signature (PKCS1v15) and verify such signatures.
auth/signing/signingtestPackage signingtest implements signing.Signer interface using small random keys.
auth/xsrfPackage xsrf provides Cross Site Request Forgery prevention middleware.
cachingPackage caching implements common server object caches.
caching/cachingtestPackage cachingtest contains helpers for testing code that uses caching package.
caching/layeredPackage layered provides a two-layer cache for serializable objects.
middlewarePackage middleware defines base type for context-aware HTTP request handler.
portalPackage portal implements HTTP routes for portal pages.
portal/internal/assetsPackage assets is generated by
pprofPackage pprof is similar to net/http/pprof, except it supports auth.
routerPackage router provides an HTTP router with support for middleware and subrouters.
secretsPackage secrets provides an interface for a simple secret store: you ask it for a secret (a byte blob, identifies by some key), and it returns it to you (current version, as well as a bunch of previous versions).
secrets/testsecretsPackage testsecrets provides a dumb in-memory secret store to use in unit tests.
settingsPackage settings implements storage for infrequently changing global settings.
templatesPackage templates implements wrapper around html/template to provide lazy loading of templates and better integration with HTTP middleware framework.
tokensPackage tokens provides means to generate and validate base64 encoded tokens compatible with luci-py's components.auth implementation.
tsmonPackage tsmon adapts common/tsmon library to a server-side environment.
warmupPackage warmup allows to register hooks executed during the server warmup.

Package server imports 38 packages (graph). Updated 2019-07-23. Refresh now. Tools for package owners.