server

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2021 License: MIT Imports: 35 Imported by: 1

Documentation

Overview

Package server provides a Charm Cloud server with HTTP and SSH protocols.

Index

Constants

This section is empty.

Variables

This section is empty.

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(publicKey []byte) (func(http.Handler) http.Handler, error)

JWTMiddleware creates a new middleware function that will validate JWT tokesn based on the supplied public key.

func RequestLimitMiddleware

func RequestLimitMiddleware() func(http.Handler) http.Handler

Types

type Config

type Config struct {
	Host        string `env:"CHARM_SERVER_HOST" default:"localhost"`
	SSHPort     int    `env:"CHARM_SERVER_SSH_PORT" default:"35353"`
	HTTPPort    int    `env:"CHARM_SERVER_HTTP_PORT" default:"35354"`
	HTTPScheme  string `env:"CHARM_SERVER_HTTP_SCHEME" default:"http"`
	StatsPort   int    `env:"CHARM_SERVER_STATS_PORT" default:"35355"`
	HealthPort  string `env:"CHARM_SERVER_HEALTH_PORT" default:"35356"`
	DataDir     string `env:"CHARM_SERVER_DATA_DIR" default:"./data"`
	TLSKeyFile  string `env:"CHARM_SERVER_TLS_KEY_FILE" default:""`
	TLSCertFile string `env:"CHARM_SERVER_TLS_CERT_FILE" default:""`
	TLSConfig   *tls.Config
	PublicKey   []byte
	PrivateKey  []byte
	DB          db.DB
	FileStore   storage.FileStore
	Stats       stats.Stats
}

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) WithDB

func (cfg *Config) WithDB(db db.DB) *Config

WithDB returns a Config with the provided DB interface implementation.

func (*Config) WithFileStore

func (cfg *Config) WithFileStore(fs storage.FileStore) *Config

WithFileStore returns a Config with the provided FileStore implementation.

func (*Config) WithKeys

func (cfg *Config) WithKeys(publicKey []byte, privateKey []byte) *Config

WithKeys returns a Config with the provided public and private keys for the SSH server and JWT signing.

func (*Config) WithStats

func (cfg *Config) WithStats(s stats.Stats) *Config

WithStats returns a Config with the provided Stats 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) Start

func (s *HTTPServer) Start()

Start starts the HTTP server on the port specified in the Config.

type SSHLinker

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

SSHLinker implments proto.LinkTransport for the Charm SSH server.

func (*SSHLinker) Error

func (sl *SSHLinker) Error(l *charm.Link)

Error implements the proto.LinkTransport interface for the SSHLinker.

func (*SSHLinker) LinkedDifferentUser

func (sl *SSHLinker) LinkedDifferentUser(l *charm.Link)

LinkedDifferentUser implements the proto.LinkTransport interface for the SSHLinker.

func (*SSHLinker) LinkedSameUser

func (sl *SSHLinker) LinkedSameUser(l *charm.Link)

LinkedSameUser implements the proto.LinkTransport interface for the SSHLinker.

func (*SSHLinker) RequestDenied

func (sl *SSHLinker) RequestDenied(l *charm.Link)

RequestDenied implements the proto.LinkTransport interface for the SSHLinker.

func (*SSHLinker) RequestInvalidToken

func (sl *SSHLinker) RequestInvalidToken(l *charm.Link)

RequestInvalidToken implements the proto.LinkTransport interface for the SSHLinker.

func (*SSHLinker) RequestStart

func (sl *SSHLinker) RequestStart(l *charm.Link)

RequestStart implements the proto.LinkTransport interface for the SSHLinker.

func (*SSHLinker) RequestValidToken

func (sl *SSHLinker) RequestValidToken(l *charm.Link)

RequestValidToken implements the proto.LinkTransport interface for the SSHLinker.

func (*SSHLinker) Requested

func (sl *SSHLinker) Requested(l *charm.Link) (bool, error)

Requested implements the proto.LinkTransport interface for the SSHLinker.

func (*SSHLinker) Success

func (sl *SSHLinker) Success(l *charm.Link)

Success implements the proto.LinkTransport interface for the SSHLinker.

func (*SSHLinker) TimedOut

func (sl *SSHLinker) TimedOut(l *charm.Link)

TimedOut implements the proto.LinkTransport interface for the SSHLinker.

func (*SSHLinker) TokenCreated

func (sl *SSHLinker) TokenCreated(token charm.Token)

TokenCreated implements the proto.LinkTransport interface for the SSHLinker.

func (*SSHLinker) TokenSent

func (sl *SSHLinker) TokenSent(l *charm.Link)

TokenSent implements the proto.LinkTransport interface for the SSHLinker.

func (*SSHLinker) User

func (sl *SSHLinker) User() *charm.User

User 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

func NewSSHServer(cfg *Config) (*SSHServer, error)

NewSSHServer creates a new SSHServer from the provided Config.

func (*SSHServer) DeleteLinkRequest

func (me *SSHServer) DeleteLinkRequest(tok charm.Token)

DeleteLinkRequest implements the proto.LinkTransport interface for the SSHLinker.

func (*SSHServer) LinkGen

func (me *SSHServer) LinkGen(lt charm.LinkTransport) error

LinkGen implements the proto.LinkTransport interface for the SSHLinker.

func (*SSHServer) LinkRequest

func (me *SSHServer) LinkRequest(lt charm.LinkTransport, key string, token string, ip string) error

LinkRequest implements the proto.LinkTransport interface for the SSHLinker.

func (*SSHServer) NewToken

func (me *SSHServer) NewToken() charm.Token

NewToken creates and returns a new Token.

func (*SSHServer) Start

func (me *SSHServer) Start()

Start serves the SSH protocol on the configured port.

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 NewServer

func NewServer(cfg *Config) (*Server, error)

NewServer returns a *Server with the specified Config.

func (*Server) Start

func (srv *Server) Start()

Start starts the HTTP, SSH and stats HTTP servers for the Charm Cloud.

type Session

type Session struct {
	ssh.Session
}

Session represents a Charm User's SSH session.

type SessionHandler

type SessionHandler func(s Session)

SessionHandler defines a function that handles a session for a given SSH command.

Directories

Path Synopsis
db

Jump to

Keyboard shortcuts

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