Documentation
¶
Overview ¶
Package server is the flightbay-desk HTTP server: the JSON API behind the web UI, the embedded UI itself, the fake kube-apiserver mounted at /k8s/ and a real terminal over a websocket.
Index ¶
- Constants
- func IsGitURL(s string) bool
- func KeysDir() string
- func KubeContexts(kubeconfig string) (ctxs []kubeContext, current string, files []string, err error)
- type LiveAccess
- type LiveAccessResult
- type LiveRequest
- type Rel
- type ReviewSession
- type ScanRequest
- type Server
- func (s *Server) BaselineFailed(path string, err error)
- func (s *Server) BaselineLoading(path string)
- func (s *Server) Close()
- func (s *Server) Handler() http.Handler
- func (s *Server) KubeHandler() http.Handler
- func (s *Server) KubeconfigPath() string
- func (s *Server) Prepare() error
- func (s *Server) RCFile() string
- func (s *Server) SetBaseline(ws *store.Workspace, path string)
- func (s *Server) ShellEnv() []string
- type StartAction
- type StartServer
- type TimelineItem
Constants ¶
const CookieName = "flightbay_token"
CookieName prefixes the cookie that holds the per-process session token in the browser. Browsers scope cookies by host, not port, so the listening port is appended: two desks open on 127.0.0.1 at once keep separate sessions.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type LiveAccess ¶
type LiveAccess struct {
Clusters []LiveAccessResult `json:"clusters,omitempty"`
ClusterScoped bool `json:"clusterScoped"`
ClusterScopedWhy string `json:"clusterScopedWhy,omitempty"`
Diagnostics bool `json:"diagnostics"`
DiagnosticsWhy string `json:"diagnosticsWhy,omitempty"`
}
LiveAccess is what the context's credentials allow of the live options. A reason is set when the option is not allowed.
type LiveAccessResult ¶ added in v0.4.1
type LiveAccessResult struct {
Context string `json:"context"`
LiveAccess
Error string `json:"error,omitempty"`
}
type LiveRequest ¶
type LiveRequest struct {
Contexts []string `json:"contexts,omitempty"`
Kubeconfigs []string `json:"kubeconfigs,omitempty"`
Kubeconfig string `json:"kubeconfig,omitempty"`
Context string `json:"context"`
Namespaces string `json:"namespaces,omitempty"` // comma separated, globs allowed; empty = all
ExcludeNamespaces string `json:"excludeNamespaces,omitempty"` // comma separated, globs allowed
ClusterScoped bool `json:"clusterScoped,omitempty"` // --cluster-scoped
Diagnostics bool `json:"diagnostics,omitempty"` // --diagnostics
}
LiveRequest is the Live card's form.
type Rel ¶
type Rel struct {
Relation string `json:"relation"`
Cluster string `json:"cluster"`
Group string `json:"group"`
Resource string `json:"resource"`
Kind string `json:"kind"`
Namespace string `json:"namespace"`
Name string `json:"name"`
}
Rel is a relationship shown in the object inspector.
type ReviewSession ¶
type ReviewSession struct {
Source string // the original bundle file
Out string // where the export goes
Options review.Options // identities, signer, recipients, trusted keys, tool
Plan review.Plan // starting plan (reviewer name)
Landing bool // open the UI on the Review and send page (--review)
// SignerPath is the key file exports are signed with, when known.
SignerPath string
// Frozen is set for a live mirror: when it was frozen into Source.
Frozen time.Time
// contains filtered or unexported fields
}
ReviewSession is review mode (flightbay review): the customer decides what to share and exports a trimmed, signed bundle.
type ScanRequest ¶
type ScanRequest struct {
Source string `json:"source"` // a local directory or a Git URL
Values []string `json:"values,omitempty"`
Set []string `json:"set,omitempty"`
Overlay string `json:"overlay,omitempty"`
Env string `json:"env,omitempty"`
Namespace string `json:"namespace,omitempty"`
Release string `json:"release,omitempty"`
}
ScanRequest is the Repo card's form.
type Server ¶
type Server struct {
WS *store.Workspace
Token string
WorkDir string
BaseURL string // e.g. http://127.0.0.1:8484, used in the kubeconfig
Terminal bool
Shell string
DeskBinary string // path to flightbay-desk, used by the fbq/fbfind helpers
Reload func() error // re-reads the bundle to load deferred categories; nil if unsupported
// KubeURL and KubeCA point kubeconfigs at the TLS listener serving the
// snapshot API. kubectl only sends kubeconfig tokens over TLS.
KubeURL string
KubeCA []byte
// LoadBaseline starts loading an earlier bundle for the Compare view in
// the background and calls SetBaseline (or BaselineFailed) when done. It
// returns an error only if loading cannot start. nil disables loading
// baselines from the UI.
LoadBaseline func(path string) error
// BundlePath is the bundle file the workspace was opened from ("" for a
// stream). Its directory is searched for baseline candidates.
BundlePath string
// BaselineDirs are extra directories to search for baseline candidates.
BaselineDirs []string
// Identities decrypt bundle headers when listing baseline candidates.
Identities []age.Identity
// Review is set in review mode (flightbay review).
Review *ReviewSession
// RefreshDiagnostics re-runs diagnostics for one pod of a live
// workspace and returns how many files were captured; nil when the
// workspace is not live or diagnostics were not allowed.
RefreshDiagnostics func(ctx context.Context, namespace, pod string) (int, error)
RefreshClusterDiagnostics func(ctx context.Context, cluster, namespace, pod string) (int, error)
// SaveBundle writes the live mirror as a bundle and returns its path;
// nil when the workspace is not live.
SaveBundle func() (string, error)
// FreezeBundle writes the live mirror as a bundle into dir and returns
// its path; Review and send exports from that frozen copy. nil when the
// workspace is not live.
FreezeBundle func(dir string) (string, error)
// ExportDir is where reviewed bundles of a live mirror are written.
ExportDir string
// Signer signs reviewed exports of a live mirror (--sign); the Review
// and send page can choose or create another.
Signer *sign.PrivateKey
// AmbientKubeconfig is used only by explicit wizard dry-run/apply actions,
// never by the read-only snapshot API or live mirror transport.
AmbientKubeconfig string
AmbientStateDir string
// contains filtered or unexported fields
}
Server serves one workspace.
func (*Server) BaselineFailed ¶
BaselineFailed records that loading path as the baseline failed.
func (*Server) BaselineLoading ¶
BaselineLoading records that path is being loaded as the baseline.
func (*Server) KubeHandler ¶
KubeHandler serves the snapshot API at the root, for the TLS listener.
func (*Server) KubeconfigPath ¶
KubeconfigPath is where Prepare writes the kubeconfig.
func (*Server) Prepare ¶
Prepare writes the kubeconfig and the shell helpers into the work directory.
func (*Server) SetBaseline ¶
SetBaseline attaches an earlier bundle to compare the workspace against. A result for a path that is no longer the one being loaded is dropped, so picking a second bundle while the first loads keeps the second.
type StartAction ¶
type StartAction struct {
Kind string `json:"kind"` // "open", "review" or "live"
Path string `json:"path,omitempty"` // the bundle, for open and review
Identity string `json:"identity,omitempty"` // an age identity file for an encrypted bundle
Live *LiveRequest `json:"live,omitempty"`
// Scanned is set when Path is a bundle the start page just scanned.
Scanned bool `json:"scanned,omitempty"`
}
StartAction is what the start page hands over to.
type StartServer ¶
type StartServer struct {
Token string
WorkDir string // uploads, clones and scanned bundles go here; the next desk uses it as its workspace
// Dirs are searched for recent bundles (default: the working directory
// and ~/Downloads). WorkDir/uploads is always searched.
Dirs []string
// Identities open encrypted bundles given with -i when the start page
// was launched.
Identities []age.Identity
// MaxUpload caps an uploaded bundle, in bytes (default 8 GiB).
MaxUpload int64
// Version goes into the header of scanned bundles.
Version string
// LivePlan returns the dry-run plan and RBAC for a live request,
// as flightbay-desk live --dry-run --json prints it.
LivePlan func(ctx context.Context, req LiveRequest) (json.RawMessage, error)
// LiveAccess asks the cluster whether the context's credentials can read
// cluster-scoped objects and port-forward, so the start page can turn
// those options on by default and off, with the reason, when they cannot.
LiveAccess func(ctx context.Context, req LiveRequest) (LiveAccess, error)
// Launch hands over to the desk for an action. It is called after the
// response has been sent and does not return on success.
Launch func(a StartAction) error
// contains filtered or unexported fields
}
StartServer serves the start page: what flightbay ui shows when it is given nothing to open. There is no workspace yet, so none of the workspace APIs exist here. When the user picks something, Launch replaces this process with the desk for it, on the same address and with the same token.
func (*StartServer) Handler ¶
func (s *StartServer) Handler() http.Handler
Handler serves the start page, its static files, /docs and /api/start/.
type TimelineItem ¶
type TimelineItem struct {
Time time.Time `json:"time"`
Cluster string `json:"cluster"`
Namespace string `json:"namespace,omitempty"`
Kind string `json:"kind"` // event, termination, rollout, error-spike
Severity string `json:"severity"`
Title string `json:"title"`
Detail string `json:"detail,omitempty"`
Object *Rel `json:"object,omitempty"`
LogQuery string `json:"logQuery,omitempty"`
From time.Time `json:"from,omitempty"`
To time.Time `json:"to,omitempty"`
}
TimelineItem is one entry on the incident timeline.