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
- Variables
- 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
- func SignWebhook(secret string, timestamp int64, body []byte) string
- func VerifyWebhook(secret, signature, timestamp string, body []byte, now time.Time, ...) bool
- type Alert
- type AlertConfig
- type AuthConfig
- type Authenticator
- type Config
- type Identity
- type RepositoryOverview
- type Run
- type RunSummary
- type Server
- type TokenInfo
- type TriggerConfig
- type Workspace
- type WorkspaceOverview
Constants ¶
const ( EventApplySucceeded = "apply_succeeded" EventApplyFailed = "apply_failed" EventPlanFailed = "plan_failed" EventDriftDetected = "drift_detected" EventDriftResolved = "drift_resolved" )
Events that can send an alert.
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 ¶
var AllEvents = []string{EventApplySucceeded, EventApplyFailed, EventPlanFailed, EventDriftDetected, EventDriftResolved}
AllEvents lists every event, in the order the documentation describes them.
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.
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 ¶
SignWebhook returns the signature header's value for a body sent at timestamp.
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 ¶
LoadConfig reads the configuration from BOG_SERVER_* environment variables.
type RepositoryOverview ¶
type RepositoryOverview = dashboard.RepositoryOverview
The overview's types are shared with "bogform ui".
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.
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 WorkspaceOverview ¶
type WorkspaceOverview = dashboard.WorkspaceOverview
The overview's types are shared with "bogform ui".