Documentation ¶
Overview ¶
Package server provides a Charm Cloud server with HTTP and SSH protocols.
Index ¶
- Variables
- func CharmUserMiddleware(s *HTTPServer) func(http.Handler) http.Handler
- func JWTMiddleware(pk crypto.PublicKey, iss string, aud []string) (func(http.Handler) http.Handler, error)
- func PublicPrefixesMiddleware(prefixes []string) func(http.Handler) http.Handler
- func RequestLimitMiddleware() func(http.Handler) http.Handler
- type Config
- func (cfg *Config) WithDB(db db.DB) *Config
- func (cfg *Config) WithErrorLogger(l *glog.Logger) *Config
- func (cfg *Config) WithFileStore(fs storage.FileStore) *Config
- func (cfg *Config) WithKeys(publicKey []byte, privateKey []byte) *Config
- func (cfg *Config) WithLinkQueue(q charm.LinkQueue) *Config
- func (cfg *Config) WithStats(s stats.Stats) *Config
- func (cfg *Config) WithTLSConfig(c *tls.Config) *Config
- type HTTPServer
- type JSONWebKeyPair
- type SSHLinker
- func (sl *SSHLinker) Error(l *charm.Link)
- func (sl *SSHLinker) LinkedDifferentUser(l *charm.Link)
- func (sl *SSHLinker) LinkedSameUser(l *charm.Link)
- func (sl *SSHLinker) RequestDenied(l *charm.Link)
- func (sl *SSHLinker) RequestInvalidToken(l *charm.Link)
- func (sl *SSHLinker) RequestStart(l *charm.Link)
- func (sl *SSHLinker) RequestValidToken(l *charm.Link)
- func (sl *SSHLinker) Requested(l *charm.Link) (bool, error)
- func (sl *SSHLinker) Success(l *charm.Link)
- func (sl *SSHLinker) TimedOut(l *charm.Link)
- func (sl *SSHLinker) TokenCreated(token charm.Token)
- func (sl *SSHLinker) TokenSent(_ *charm.Link)
- func (sl *SSHLinker) User() *charm.User
- type SSHServer
- type Server
- type Session
- type SessionHandler
Constants ¶
This section is empty.
Variables ¶
var MaxFSRequestSize int64 = 1024 * 1024 * 1024 // 1GB
MaxFSRequestSize is the maximum size of a request body for fs endpoints.
Functions ¶
func CharmUserMiddleware ¶
func CharmUserMiddleware(s *HTTPServer) func(http.Handler) http.Handler
CharmUserMiddleware looks up and authenticates a Charm user based on the provided JWT in the request.
func JWTMiddleware ¶
func JWTMiddleware(pk crypto.PublicKey, iss string, aud []string) (func(http.Handler) http.Handler, error)
JWTMiddleware creates a new middleware function that will validate JWT tokens based on the supplied public key.
func PublicPrefixesMiddleware ¶ added in v0.10.0
PublicPrefixesMiddleware allows for the specification of non-authed URL prefixes. These won't be checked for JWT bearers or Charm user accounts.
Types ¶
type Config ¶
type Config struct { BindAddr string `env:"CHARM_SERVER_BIND_ADDRESS" envDefault:""` Host string `env:"CHARM_SERVER_HOST" envDefault:"localhost"` SSHPort int `env:"CHARM_SERVER_SSH_PORT" envDefault:"35353"` HTTPPort int `env:"CHARM_SERVER_HTTP_PORT" envDefault:"35354"` StatsPort int `env:"CHARM_SERVER_STATS_PORT" envDefault:"35355"` HealthPort int `env:"CHARM_SERVER_HEALTH_PORT" envDefault:"35356"` DataDir string `env:"CHARM_SERVER_DATA_DIR" envDefault:"data"` UseTLS bool `env:"CHARM_SERVER_USE_TLS" envDefault:"false"` TLSKeyFile string `env:"CHARM_SERVER_TLS_KEY_FILE"` TLSCertFile string `env:"CHARM_SERVER_TLS_CERT_FILE"` PublicURL string `env:"CHARM_SERVER_PUBLIC_URL"` EnableMetrics bool `env:"CHARM_SERVER_ENABLE_METRICS" envDefault:"false"` UserMaxStorage int64 `env:"CHARM_SERVER_USER_MAX_STORAGE" envDefault:"0"` PublicKey []byte PrivateKey []byte DB db.DB FileStore storage.FileStore Stats stats.Stats // contains filtered or unexported fields }
Config is the configuration for the Charm server.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a Config with the values populated with the defaults or specified environment variables.
func (*Config) WithErrorLogger ¶ added in v0.10.0
WithErrorLogger returns a Config with the provided error log for the server.
func (*Config) WithFileStore ¶
WithFileStore returns a Config with the provided FileStore implementation.
func (*Config) WithKeys ¶
WithKeys returns a Config with the provided public and private keys for the SSH server and JWT signing.
func (*Config) WithLinkQueue ¶ added in v0.10.0
WithLinkQueue returns a Config with the provided LinkQueue implementation.
type HTTPServer ¶
type HTTPServer struct {
// contains filtered or unexported fields
}
HTTPServer is the HTTP server for the Charm Cloud backend.
func NewHTTPServer ¶
func NewHTTPServer(cfg *Config) (*HTTPServer, error)
NewHTTPServer returns a new *HTTPServer with the specified Config.
func (*HTTPServer) Shutdown ¶ added in v0.10.0
func (s *HTTPServer) Shutdown(ctx context.Context) error
Shutdown gracefully shut down the HTTP and health servers.
func (*HTTPServer) Start ¶
func (s *HTTPServer) Start() error
Start start the HTTP and health servers on the ports specified in the Config.
type JSONWebKeyPair ¶ added in v0.10.0
type JSONWebKeyPair struct { PrivateKey *ed25519.PrivateKey JWK jose.JSONWebKey }
JSONWebKeyPair holds the ED25519 private key and JSON Web Key used in JWT operations.
func NewJSONWebKeyPair ¶ added in v0.10.0
func NewJSONWebKeyPair(pk *ed25519.PrivateKey) JSONWebKeyPair
NewJSONWebKeyPair creates a new JSONWebKeyPair from a given ED25519 private key.
type SSHLinker ¶
type SSHLinker struct {
// contains filtered or unexported fields
}
SSHLinker implments proto.LinkTransport for the Charm SSH server.
func (*SSHLinker) LinkedDifferentUser ¶
LinkedDifferentUser implements the proto.LinkTransport interface for the SSHLinker.
func (*SSHLinker) LinkedSameUser ¶
LinkedSameUser implements the proto.LinkTransport interface for the SSHLinker.
func (*SSHLinker) RequestDenied ¶
RequestDenied implements the proto.LinkTransport interface for the SSHLinker.
func (*SSHLinker) RequestInvalidToken ¶
RequestInvalidToken implements the proto.LinkTransport interface for the SSHLinker.
func (*SSHLinker) RequestStart ¶
RequestStart implements the proto.LinkTransport interface for the SSHLinker.
func (*SSHLinker) RequestValidToken ¶
RequestValidToken implements the proto.LinkTransport interface for the SSHLinker.
func (*SSHLinker) Requested ¶
Requested implements the proto.LinkTransport interface for the SSHLinker.
func (*SSHLinker) TimedOut ¶
TimedOut implements the proto.LinkTransport interface for the SSHLinker.
func (*SSHLinker) TokenCreated ¶
TokenCreated implements the proto.LinkTransport interface for the SSHLinker.
type SSHServer ¶
type SSHServer struct {
// contains filtered or unexported fields
}
SSHServer serves the SSH protocol and handles requests to authenticate and link Charm user accounts.
func NewSSHServer ¶
NewSSHServer creates a new SSHServer from the provided Config.
func (*SSHServer) LinkGen ¶
func (me *SSHServer) LinkGen(lt charm.LinkTransport) error
LinkGen implements the proto.LinkTransport interface for the SSHLinker.
func (*SSHServer) LinkRequest ¶
LinkRequest implements the proto.LinkTransport interface for the SSHLinker.
type Server ¶
type Server struct { Config *Config // contains filtered or unexported fields }
Server contains the SSH and HTTP servers required to host the Charm Cloud.
func (*Server) Close ¶ added in v0.11.0
Close immediately closes all active net.Listeners for the HTTP, HTTP health and SSH servers.
type SessionHandler ¶
type SessionHandler func(s Session)
SessionHandler defines a function that handles a session for a given SSH command.