server

package
v1.14.0-alpha1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MPL-2.0 Imports: 38 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 (
	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

This section is empty.

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

Types

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
}

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 Run

type Run struct {
	ID             int64       `json:"id"`
	WorkspaceID    int64       `json:"workspace_id"`
	Repository     string      `json:"repository,omitempty"`
	Directory      string      `json:"directory,omitempty"`
	WorkspaceName  string      `json:"workspace,omitempty"`
	Kind           string      `json:"kind"`
	Status         string      `json:"status"`
	Branch         string      `json:"branch"`
	Commit         string      `json:"commit"`
	PullRequest    string      `json:"pull_request,omitempty"`
	RunURL         string      `json:"run_url,omitempty"`
	BogformVersion string      `json:"bogform_version"`
	Counts         ci.Counts   `json:"counts"`
	Changes        []ci.Change `json:"changes,omitempty"`
	OutputsChanged []string    `json:"outputs_changed,omitempty"`
	Error          string      `json:"error,omitempty"`
	StartedAt      time.Time   `json:"started_at"`
	FinishedAt     time.Time   `json:"finished_at"`
}

Run is the record of one pipeline run.

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.

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 struct {
	ID           int64      `json:"id"`
	Platform     string     `json:"platform"`
	Repository   string     `json:"repository"`
	Directory    string     `json:"directory"`
	Name         string     `json:"workspace"`
	DefaultRef   string     `json:"default_ref,omitempty"`
	LastStatus   string     `json:"last_status"`
	LastKind     string     `json:"last_kind"`
	LastRunAt    time.Time  `json:"last_run_at"`
	LastApplyAt  *time.Time `json:"last_apply_at,omitempty"`
	DriftStatus  string     `json:"drift_status,omitempty"`
	DriftCheckAt *time.Time `json:"drift_checked_at,omitempty"`
}

Workspace is one configuration directory and workspace in one repository.

Jump to

Keyboard shortcuts

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