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
- func CreateToken(ctx context.Context, db *sql.DB, name, scope string) (string, error)
- func IsLoopback(host string) bool
- func Migrate(ctx context.Context, db *sql.DB) error
- func Open(databaseURL string) (*sql.DB, error)
- func Prune(ctx context.Context, db *sql.DB, retentionDays int) (int64, error)
- func RecordReport(ctx context.Context, db *sql.DB, report *ci.Report) (int64, error)
- func RevokeToken(ctx context.Context, db *sql.DB, name string) error
- func RunLambda(ctx context.Context, runtimeAPI string, handler http.Handler) error
- type AuthConfig
- type Authenticator
- type Config
- type Identity
- type Run
- type Server
- type TokenInfo
- type TriggerConfig
- type Workspace
Constants ¶
const ( RoleNone = "" RoleViewer = "viewer" RoleOperator = "operator" )
Roles a person can have.
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 ¶
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 ¶
IsLoopback reports whether host refers to this machine.
func Migrate ¶
Migrate brings the schema up to date. A lock makes it safe when several instances start at once.
func Open ¶
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 ¶
Prune deletes runs past the retention period, so that low-cost databases don't fill up.
func RecordReport ¶
RecordReport stores a report, and updates the workspace's current status.
func RevokeToken ¶
RevokeToken stops a token from 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 ¶
LoadConfig reads the configuration from BOG_SERVER_* environment variables.
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.
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.
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.