serverinit

package
v0.0.0-...-4ba1123 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2024 License: Apache-2.0 Imports: 41 Imported by: 1

Documentation

Overview

Package serverinit is responsible for mapping from a Perkeep configuration file and instantiating HTTP Handlers for all the necessary endpoints.

Index

Constants

This section is empty.

Variables

View Source
var ErrCamliPath = errors.New("invalid Perkeep request path")

Functions

func WriteDefaultConfigFile

func WriteDefaultConfigFile(filePath string) error

WriteDefaultConfigFile generates a new default high-level server configuration file at filePath. The default indexer will use SQLite. If filePath already exists, it is overwritten.

Types

type Config

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

A Config is the wrapper around a Perkeep JSON configuration file. Files on disk can be in either high-level or low-level format, but the Load function always returns the Config in its low-level format (a.k.a. the "handler" format).

TODO(bradfitz): document and/or link to the low-level format; for now you can see the high-level config format at https://perkeep.org/pkg/types/serverconfig/#Config and the the low-level format by running "camtool dumpconfig".

func DefaultEnvConfig

func DefaultEnvConfig() (*Config, error)

DefaultEnvConfig returns the default configuration when running on a known environment. Currently this just includes Google Compute Engine. If the environment isn't known (nil, nil) is returned.

func Load

func Load(config []byte) (*Config, error)

Load returns a low-level "handler config" from the provided config. If the config doesn't contain a top-level JSON key of "handlerConfig" with boolean value true, the configuration is assumed to be a high-level "user config" file, and transformed into a low-level config.

func LoadFile

func LoadFile(filename string) (*Config, error)

LoadFile returns a low-level "handler config" from the provided filename. If the config file doesn't contain a top-level JSON key of "handlerConfig" with boolean value true, the configuration is assumed to be a high-level "user config" file, and transformed into a low-level config.

func (*Config) AppURL

func (c *Config) AppURL() map[string]string

AppURL returns a map of app name to app base URL for all the configured server apps.

func (*Config) BaseURL

func (c *Config) BaseURL() string

BaseURL returns the optional URL prefix listening the root of this server. It does not end in a trailing slash.

func (*Config) HTTPS

func (c *Config) HTTPS() bool

HTTPS reports whether this configuration wants to serve HTTPS.

func (*Config) HTTPSCert

func (c *Config) HTTPSCert() string

HTTPSCert returns the optional path to an HTTPS public key certificate file.

func (*Config) HTTPSKey

func (c *Config) HTTPSKey() string

HTTPSKey returns the optional path to an HTTPS private key file.

func (*Config) InstallHandlers

func (c *Config) InstallHandlers(hi HandlerInstaller, baseURL string) (shutdown io.Closer, err error)

InstallHandlers creates and registers all the HTTP Handlers needed by config into the provided HandlerInstaller and validates that the configuration is valid.

baseURL is required and specifies the root of this webserver, without trailing slash.

The returned shutdown value can be used to cleanly shut down the handlers.

func (*Config) IsTailscaleListener

func (c *Config) IsTailscaleListener() bool

IsTailscaleListener reports whether c is configured to run in Tailscale tsnet mode.

func (*Config) KeyRingAndId

func (c *Config) KeyRingAndId() (keyRing, keyId string, err error)

KeyRingAndId returns the GPG identity keyring path and the user's GPG keyID (TODO: length/case), if configured. TODO: which error value if not configured?

func (*Config) ListenAddr

func (c *Config) ListenAddr() string

ListenAddr returns the optional configured listen address in ":port" or "ip:port" form.

func (*Config) LowLevelJSONConfig deprecated

func (c *Config) LowLevelJSONConfig() map[string]interface{}

LowLevelJSONConfig returns the config's underlying low-level JSON form for debugging.

Deprecated: this is provided for debugging only and will be going away as the move to TOML-based configuration progresses. Do not depend on this.

func (*Config) SetKeepGoing

func (c *Config) SetKeepGoing(v bool)

SetKeepGoing changes each configured prefix to set "keepGoing" to true. This indicates that validation, reindexing, or recovery behavior should not cause the process to end.

func (*Config) SetReindex

func (c *Config) SetReindex(v bool)

func (*Config) StartApps

func (c *Config) StartApps() error

StartApps starts all the server applications that were configured during InstallHandlers. It should only be called after perkeepd has started serving, since these apps might request some configuration from Perkeep to finish initializing.

func (*Config) UIPath

func (c *Config) UIPath() string

UIPath returns the relative path to the server's user interface handler, if the UI is configured. Otherwise it returns the empty string. It is not valid until after a call to InstallHandlers

If non-empty, the returned value will both begin and end with a slash.

func (*Config) UploadPublicKey

func (c *Config) UploadPublicKey(ctx context.Context) error

UploadPublicKey uploads the public key blob with the sign handler that was configured during InstallHandlers.

type HandlerInstaller

type HandlerInstaller interface {
	Handle(path string, h http.Handler)
}

A HandlerInstaller is anything that can register an HTTP Handler at a prefix path. Both *http.ServeMux and perkeep.org/pkg/webserver.Server implement HandlerInstaller.

Jump to

Keyboard shortcuts

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