server

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MPL-2.0 Imports: 43 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package server implements the optional self-hosted Bogform dashboard. It records what pipelines did and can start a pipeline run. It doesn't run Bogform or hold cloud credentials.

Index

Constants

View Source
const (
	EventApplySucceeded = "apply_succeeded"
	EventApplyFailed    = "apply_failed"
	EventPlanFailed     = "plan_failed"
	EventDriftDetected  = "drift_detected"
	EventDriftResolved  = "drift_resolved"
)

Events that can send an alert.

View Source
const (
	RoleNone     = ""
	RoleViewer   = "viewer"
	RoleOperator = "operator"
)

Roles a person can have.

View Source
const PlaceholderSecret = "change-me"

PlaceholderSecret is the value that the deployment module gives new secrets, for an administrator to replace. It's refused here so that a forgotten step can't become a known key.

Variables

AllEvents lists every event, in the order the documentation describes them.

Functions

func CreateToken

func CreateToken(ctx context.Context, db *sql.DB, name, scope string) (string, error)

CreateToken stores a new ingest token and returns it. Only its hash is kept, so it can't be shown again. The scope limits which repositories it can report for, so a token leaked from one repository can't write records for another.

func IsLoopback

func IsLoopback(host string) bool

IsLoopback reports whether host refers to this machine.

func Migrate

func Migrate(ctx context.Context, db *sql.DB) error

Migrate brings the schema up to date. A lock makes it safe when several instances start at once.

func Open

func Open(databaseURL string) (*sql.DB, error)

Open connects to Postgres. Small limits suit serverless hosting, where each instance handles one request at a time and low-cost databases allow few connections.

func Prune

func Prune(ctx context.Context, db *sql.DB, retentionDays int) (int64, error)

Prune deletes runs past the retention period, so that low-cost databases don't fill up.

func RecordReport

func RecordReport(ctx context.Context, db *sql.DB, report *ci.Report) (int64, error)

RecordReport stores a report, and updates the workspace's current status.

func RevokeToken

func RevokeToken(ctx context.Context, db *sql.DB, name string) error

RevokeToken stops a token from working.

func RunLambda

func RunLambda(ctx context.Context, runtimeAPI string, handler http.Handler, afterResponse ...func()) error

RunLambda serves requests using AWS Lambda's runtime API, which is a small HTTP protocol. Speaking it directly avoids a dependency, and handler is the same one used by the standalone server. It returns only if the runtime API stops working. afterResponse runs once each response has been sent, before asking for the next event, which is the last chance for work in the background to finish before Lambda freezes the function.

func SignWebhook

func SignWebhook(secret string, timestamp int64, body []byte) string

SignWebhook returns the signature header's value for a body sent at timestamp.

func VerifyWebhook

func VerifyWebhook(secret, signature, timestamp string, body []byte, now time.Time, tolerance time.Duration) bool

VerifyWebhook checks a signature, and that it was made within tolerance of now.

Types

type Alert

type Alert struct {
	Event        string    `json:"event"`
	Summary      string    `json:"summary"`
	Platform     string    `json:"platform"`
	Repository   string    `json:"repository"`
	Directory    string    `json:"directory"`
	Workspace    string    `json:"workspace"`
	Kind         string    `json:"kind"`
	Status       string    `json:"status"`
	Counts       ci.Counts `json:"counts"`
	Branch       string    `json:"branch,omitempty"`
	Commit       string    `json:"commit,omitempty"`
	PullRequest  string    `json:"pull_request,omitempty"`
	Actor        string    `json:"actor,omitempty"`
	Trigger      string    `json:"trigger,omitempty"`
	Error        string    `json:"error,omitempty"`
	DashboardURL string    `json:"dashboard_url,omitempty"`
	PipelineURL  string    `json:"pipeline_url,omitempty"`
	FinishedAt   time.Time `json:"finished_at"`
}

Alert describes one event. It goes to webhooks as JSON, so its fields are part of a public format.

type AlertConfig

type AlertConfig struct {
	SlackWebhook  string
	TeamsWebhook  string
	EmailFrom     string
	EmailTo       []string
	WebhookURL    string
	WebhookSecret string
	// Events and Repositories limit which runs send alerts. Empty means all. Repositories are patterns
	// for path.Match, such as "acme/*".
	Events       []string
	Repositories []string
}

AlertConfig says where alerts go. Every destination is optional.

type AuthConfig

type AuthConfig struct {
	// Provider is "oidc" or "github".
	Provider     string
	Issuer       string
	ClientID     string
	ClientSecret string
	// TrustEmail accepts an email claim that the provider doesn't mark as verified. Only use it with a
	// single-organization provider that controls its users' addresses.
	TrustEmail bool
	// GitHubURL and GitHubAPIURL are for GitHub Enterprise Server.
	GitHubURL    string
	GitHubAPIURL string
}

AuthConfig selects how people sign in.

type Authenticator

type Authenticator interface {
	// AuthCodeURL returns where to send the browser.
	AuthCodeURL(ctx context.Context, redirectURL, state, nonce, verifier string) (string, error)
	// Exchange completes the sign-in using the code that the provider returned.
	Exchange(ctx context.Context, redirectURL, code, nonce, verifier string) (Identity, error)
}

Authenticator is a way of signing people in.

type Config

type Config struct {
	PublicURL   string
	DatabaseURL string
	SessionKey  []byte
	// OriginSecret, if set, must be on every request. CloudFront adds it, so that requests can't
	// bypass CloudFront by going straight to the function's URL.
	OriginSecret  string
	StaticDir     string
	AutoMigrate   bool
	RetentionDays int

	Auth AuthConfig

	// Who can sign in. Each entry is an email address, or a domain such as "@example.com".
	Viewers   []string
	Operators []string

	// DevUser signs everyone in as this email address. It's only allowed on a loopback address.
	DevUser string

	Triggers TriggerConfig

	Alerts AlertConfig
}

Config is the server's configuration. See LoadConfig for how each value is set.

func LoadConfig

func LoadConfig(env func(string) string) (Config, error)

LoadConfig reads the configuration from BOG_SERVER_* environment variables.

func (Config) RoleFor

func (c Config) RoleFor(email string) string

RoleFor returns a person's role. It's checked on every request, so removing someone from the configuration takes effect immediately, even if they have a session.

func (Config) Validate

func (c Config) Validate() error

Validate reports problems that would stop the server from working safely.

type Identity

type Identity struct {
	Email string
	Name  string
}

Identity is a person who has proved who they are.

type RepositoryOverview

type RepositoryOverview = dashboard.RepositoryOverview

The overview's types are shared with "bogform ui".

type Run

type Run = dashboard.Run

Run is the record of one pipeline run.

type RunSummary

type RunSummary = dashboard.RunSummary

The overview's types are shared with "bogform ui".

type Server

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

Server handles the dashboard's HTTP requests.

func New

func New(cfg Config, db *sql.DB) *Server

New creates a Server.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the HTTP handler for all routes.

func (*Server) Wait

func (s *Server) Wait()

Wait blocks until alerts that are still being sent have finished. On AWS Lambda, call it after each response, because the function is frozen between requests.

type TokenInfo

type TokenInfo struct {
	ID         int64      `json:"id"`
	Name       string     `json:"name"`
	Scope      string     `json:"repository_scope"`
	CreatedAt  time.Time  `json:"created_at"`
	LastUsedAt *time.Time `json:"last_used_at,omitempty"`
	RevokedAt  *time.Time `json:"revoked_at,omitempty"`
}

TokenInfo describes an ingest token.

func ListTokens

func ListTokens(ctx context.Context, db *sql.DB) ([]TokenInfo, error)

ListTokens returns all ingest tokens, without their values, which aren't stored.

type TriggerConfig

type TriggerConfig struct {
	// Ref is the branch that pipelines are started on. It's configured here rather than learned from
	// reports, because anyone who can send a report could otherwise choose what an operator's click runs.
	Ref            string
	GitHubToken    string
	GitHubAPIURL   string
	GitHubWorkflow string
	GitLabToken    string
	GitLabAPIURL   string
	BitbucketToken string
	BitbucketURL   string
	AzureToken     string
	AzureOrgURL    string
	// AzurePipelines maps a repository name to "project/pipelineID".
	AzurePipelines map[string]string
}

TriggerConfig holds what the server needs to start pipeline runs.

type Workspace

type Workspace = dashboard.Workspace

Workspace is one configuration directory and workspace in one repository.

type WorkspaceOverview

type WorkspaceOverview = dashboard.WorkspaceOverview

The overview's types are shared with "bogform ui".

Jump to

Keyboard shortcuts

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