store

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuditAction

type AuditAction string

AuditAction represents the type of action being audited.

const (
	AuditActionJobCreated   AuditAction = "job_created"
	AuditActionJobTriggered AuditAction = "job_triggered"
	AuditActionJobCompleted AuditAction = "job_completed"
	AuditActionJobFailed    AuditAction = "job_failed"
	AuditActionJobCancelled AuditAction = "job_cancelled"
	AuditActionJobReordered AuditAction = "job_reordered"
	AuditActionUserLogin    AuditAction = "user_login"
	AuditActionUserLogout   AuditAction = "user_logout"
	AuditActionConfigReload AuditAction = "config_reload"
)

type AuditEntityType

type AuditEntityType string

AuditEntityType represents the type of entity being audited.

const (
	AuditEntityJob     AuditEntityType = "job"
	AuditEntityGroup   AuditEntityType = "group"
	AuditEntityRunner  AuditEntityType = "runner"
	AuditEntityUser    AuditEntityType = "user"
	AuditEntitySession AuditEntityType = "session"
	AuditEntitySystem  AuditEntityType = "system"
)

type AuditEntry

type AuditEntry struct {
	ID         string          `json:"id"`
	Action     AuditAction     `json:"action"`
	EntityType AuditEntityType `json:"entity_type"`
	EntityID   string          `json:"entity_id"`
	Actor      string          `json:"actor"`
	Details    string          `json:"details"`
	CreatedAt  time.Time       `json:"created_at"`
}

AuditEntry represents an audit log entry.

type AuditQueryOpts

type AuditQueryOpts struct {
	EntityType *AuditEntityType
	EntityID   *string
	Action     *AuditAction
	Actor      *string
	Since      *time.Time
	Until      *time.Time
	Limit      int
	Offset     int
}

AuditQueryOpts contains options for querying audit entries.

type AuthCode

type AuthCode struct {
	Code      string    `json:"code"`
	UserID    string    `json:"user_id"`
	ExpiresAt time.Time `json:"expires_at"`
	CreatedAt time.Time `json:"created_at"`
}

AuthCode represents a one-time authorization code for token exchange.

type AuthProvider

type AuthProvider string

AuthProvider represents the authentication provider for a user.

const (
	AuthProviderBasic  AuthProvider = "basic"
	AuthProviderGitHub AuthProvider = "github"
)

type Group

type Group struct {
	ID           string    `json:"id"`
	Name         string    `json:"name"`
	Description  string    `json:"description"`
	RunnerLabels []string  `json:"runner_labels"`
	Enabled      bool      `json:"enabled"`
	Paused       bool      `json:"paused"`
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
}

Group represents a runner pool.

type HistoryQueryOpts

type HistoryQueryOpts struct {
	GroupID  string
	Limit    int
	Before   *time.Time        // cursor: fetch jobs completed before this time
	Statuses []JobStatus       // filter by status (multi-select, empty = all history statuses)
	Labels   map[string]string // filter by template labels (AND logic)
}

HistoryQueryOpts contains options for querying job history.

type HistoryResult

type HistoryResult struct {
	Jobs       []*Job
	HasMore    bool
	NextCursor *time.Time // completed_at of the last job
	TotalCount int
}

HistoryResult contains paginated history results.

type HistoryStatsBucket

type HistoryStatsBucket struct {
	Timestamp time.Time `json:"timestamp"`
	Completed int       `json:"completed"`
	Failed    int       `json:"failed"`
	Cancelled int       `json:"cancelled"`
}

HistoryStatsBucket contains aggregated job counts for a time bucket.

type HistoryStatsOpts

type HistoryStatsOpts struct {
	GroupID string
	Start   time.Time
	End     time.Time
	Buckets int // number of time buckets to return
}

HistoryStatsOpts contains options for querying history statistics.

type HistoryStatsRange

type HistoryStatsRange struct {
	Start          time.Time     `json:"start"`
	End            time.Time     `json:"end"`
	BucketDuration time.Duration `json:"bucket_duration"`
}

HistoryStatsRange contains metadata about the time range.

type HistoryStatsResult

type HistoryStatsResult struct {
	Buckets []*HistoryStatsBucket `json:"buckets"`
	Range   HistoryStatsRange     `json:"range"`
	Totals  HistoryStatsTotals    `json:"totals"`
}

HistoryStatsResult contains aggregated history statistics.

type HistoryStatsTotals

type HistoryStatsTotals struct {
	Completed int `json:"completed"`
	Failed    int `json:"failed"`
	Cancelled int `json:"cancelled"`
}

HistoryStatsTotals contains total counts across all buckets.

type Job

type Job struct {
	ID           string            `json:"id"`
	GroupID      string            `json:"group_id"`
	TemplateID   string            `json:"template_id"`
	Priority     int               `json:"priority"`
	Position     int               `json:"position"`
	Status       JobStatus         `json:"status"`
	Paused       bool              `json:"paused"`
	AutoRequeue  bool              `json:"auto_requeue"`
	RequeueLimit *int              `json:"requeue_limit"`
	RequeueCount int               `json:"requeue_count"`
	Inputs       map[string]string `json:"inputs"`
	CreatedBy    string            `json:"created_by"`
	TriggeredAt  *time.Time        `json:"triggered_at"`
	RunID        *int64            `json:"run_id"`
	RunURL       string            `json:"run_url"`
	RunnerID     *int64            `json:"runner_id"`
	RunnerName   string            `json:"runner_name"`
	CompletedAt  *time.Time        `json:"completed_at"`
	ErrorMessage string            `json:"error_message"`
	CreatedAt    time.Time         `json:"created_at"`
	UpdatedAt    time.Time         `json:"updated_at"`

	// Override fields (nil/empty means use template value).
	Name       *string           `json:"name,omitempty"`
	Owner      *string           `json:"owner,omitempty"`
	Repo       *string           `json:"repo,omitempty"`
	WorkflowID *string           `json:"workflow_id,omitempty"`
	Ref        *string           `json:"ref,omitempty"`
	Labels     map[string]string `json:"labels,omitempty"`
}

Job represents a queued or executed workflow dispatch.

type JobStatus

type JobStatus string

JobStatus represents the state of a job.

const (
	JobStatusPending   JobStatus = "pending"
	JobStatusTriggered JobStatus = "triggered"
	JobStatusRunning   JobStatus = "running"
	JobStatusCompleted JobStatus = "completed"
	JobStatusFailed    JobStatus = "failed"
	JobStatusCancelled JobStatus = "cancelled"
)

type JobTemplate

type JobTemplate struct {
	ID            string            `json:"id"`
	GroupID       string            `json:"group_id"`
	Name          string            `json:"name"`
	Owner         string            `json:"owner"`
	Repo          string            `json:"repo"`
	WorkflowID    string            `json:"workflow_id"`
	Ref           string            `json:"ref"`
	DefaultInputs map[string]string `json:"default_inputs"`
	Labels        map[string]string `json:"labels"`
	InConfig      bool              `json:"in_config"`
	SourceType    string            `json:"source_type"` // "inline", "file", or "url"
	SourcePath    string            `json:"source_path"` // filename or URL (empty for inline)
	CreatedAt     time.Time         `json:"created_at"`
	UpdatedAt     time.Time         `json:"updated_at"`
}

JobTemplate represents a workflow dispatch job configuration.

type OAuthState

type OAuthState struct {
	State     string    `json:"state"`
	ExpiresAt time.Time `json:"expires_at"`
	CreatedAt time.Time `json:"created_at"`
}

OAuthState represents a CSRF state token for OAuth flows.

type PostgresStore

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

PostgresStore implements Store using PostgreSQL.

func (*PostgresStore) CreateAuditEntry

func (s *PostgresStore) CreateAuditEntry(ctx context.Context, entry *AuditEntry) error

CreateAuditEntry creates a new audit log entry.

func (*PostgresStore) CreateAuthCode

func (s *PostgresStore) CreateAuthCode(ctx context.Context, code *AuthCode) error

CreateAuthCode creates a new one-time authorization code.

func (*PostgresStore) CreateGroup

func (s *PostgresStore) CreateGroup(ctx context.Context, group *Group) error

CreateGroup creates a new group.

func (*PostgresStore) CreateJob

func (s *PostgresStore) CreateJob(ctx context.Context, job *Job) error

CreateJob creates a new job.

func (*PostgresStore) CreateJobTemplate

func (s *PostgresStore) CreateJobTemplate(ctx context.Context, template *JobTemplate) error

CreateJobTemplate creates a new job template.

func (*PostgresStore) CreateOAuthState

func (s *PostgresStore) CreateOAuthState(ctx context.Context, state *OAuthState) error

CreateOAuthState creates a new OAuth state for CSRF protection.

func (*PostgresStore) CreateSession

func (s *PostgresStore) CreateSession(ctx context.Context, session *Session) error

CreateSession creates a new session.

func (*PostgresStore) CreateUser

func (s *PostgresStore) CreateUser(ctx context.Context, user *User) error

CreateUser creates a new user.

func (*PostgresStore) DeleteAuthCode

func (s *PostgresStore) DeleteAuthCode(ctx context.Context, code string) error

DeleteAuthCode deletes an authorization code.

func (*PostgresStore) DeleteExpiredAuthCodes

func (s *PostgresStore) DeleteExpiredAuthCodes(ctx context.Context) error

DeleteExpiredAuthCodes deletes all expired authorization codes.

func (*PostgresStore) DeleteExpiredOAuthStates

func (s *PostgresStore) DeleteExpiredOAuthStates(ctx context.Context) error

DeleteExpiredOAuthStates deletes all expired OAuth states.

func (*PostgresStore) DeleteExpiredSessions

func (s *PostgresStore) DeleteExpiredSessions(ctx context.Context) error

DeleteExpiredSessions deletes all expired sessions.

func (*PostgresStore) DeleteGroup

func (s *PostgresStore) DeleteGroup(ctx context.Context, id string) error

DeleteGroup deletes a group by ID.

func (*PostgresStore) DeleteJob

func (s *PostgresStore) DeleteJob(ctx context.Context, id string) error

DeleteJob deletes a job by ID.

func (*PostgresStore) DeleteJobTemplate

func (s *PostgresStore) DeleteJobTemplate(ctx context.Context, id string) error

DeleteJobTemplate deletes a job template by ID.

func (*PostgresStore) DeleteJobTemplatesByGroup

func (s *PostgresStore) DeleteJobTemplatesByGroup(ctx context.Context, groupID string) error

DeleteJobTemplatesByGroup deletes all job templates for a group.

func (*PostgresStore) DeleteOAuthState

func (s *PostgresStore) DeleteOAuthState(ctx context.Context, state string) error

DeleteOAuthState deletes an OAuth state.

func (*PostgresStore) DeleteOldJobs

func (s *PostgresStore) DeleteOldJobs(ctx context.Context, olderThan time.Time) (int64, error)

DeleteOldJobs deletes completed, failed, or cancelled jobs older than the given time.

func (*PostgresStore) DeleteRunner

func (s *PostgresStore) DeleteRunner(ctx context.Context, id int64) error

DeleteRunner deletes a runner by ID.

func (*PostgresStore) DeleteSession

func (s *PostgresStore) DeleteSession(ctx context.Context, id string) error

DeleteSession deletes a session by ID.

func (*PostgresStore) DeleteStaleRunners

func (s *PostgresStore) DeleteStaleRunners(ctx context.Context, olderThan time.Time) error

DeleteStaleRunners deletes runners not seen since the given time.

func (*PostgresStore) DeleteUser

func (s *PostgresStore) DeleteUser(ctx context.Context, id string) error

DeleteUser deletes a user by ID.

func (*PostgresStore) DeleteUserSessions

func (s *PostgresStore) DeleteUserSessions(ctx context.Context, userID string) error

DeleteUserSessions deletes all sessions for a user.

func (*PostgresStore) GetAuthCode

func (s *PostgresStore) GetAuthCode(ctx context.Context, code string) (*AuthCode, error)

GetAuthCode retrieves an authorization code by its value.

func (*PostgresStore) GetGroup

func (s *PostgresStore) GetGroup(ctx context.Context, id string) (*Group, error)

GetGroup retrieves a group by ID.

func (*PostgresStore) GetHistoryStats

func (s *PostgresStore) GetHistoryStats(ctx context.Context, opts HistoryStatsOpts) (*HistoryStatsResult, error)

GetHistoryStats retrieves aggregated job statistics for a time range.

func (*PostgresStore) GetHistoryTimeBounds

func (s *PostgresStore) GetHistoryTimeBounds(ctx context.Context, groupID string) (oldest, newest *time.Time, err error)

GetHistoryTimeBounds returns the oldest and newest completed_at times for history jobs.

func (*PostgresStore) GetJob

func (s *PostgresStore) GetJob(ctx context.Context, id string) (*Job, error)

GetJob retrieves a job by ID.

func (*PostgresStore) GetJobTemplate

func (s *PostgresStore) GetJobTemplate(ctx context.Context, id string) (*JobTemplate, error)

GetJobTemplate retrieves a job template by ID.

func (*PostgresStore) GetMaxPosition

func (s *PostgresStore) GetMaxPosition(ctx context.Context, groupID string) (int, error)

GetMaxPosition returns the maximum position for jobs in a group.

func (*PostgresStore) GetNextPendingJob

func (s *PostgresStore) GetNextPendingJob(ctx context.Context, groupID string) (*Job, error)

GetNextPendingJob retrieves the next pending job for a group (lowest position). Paused jobs are excluded from selection.

func (*PostgresStore) GetOAuthState

func (s *PostgresStore) GetOAuthState(ctx context.Context, state string) (*OAuthState, error)

GetOAuthState retrieves an OAuth state by its value.

func (*PostgresStore) GetRunner

func (s *PostgresStore) GetRunner(ctx context.Context, id int64) (*Runner, error)

GetRunner retrieves a runner by ID.

func (*PostgresStore) GetRunnerByName

func (s *PostgresStore) GetRunnerByName(ctx context.Context, name string) (*Runner, error)

GetRunnerByName retrieves a runner by name.

func (*PostgresStore) GetSession

func (s *PostgresStore) GetSession(ctx context.Context, id string) (*Session, error)

GetSession retrieves a session by ID.

func (*PostgresStore) GetSessionByToken

func (s *PostgresStore) GetSessionByToken(ctx context.Context, tokenHash string) (*Session, error)

GetSessionByToken retrieves a session by token hash.

func (*PostgresStore) GetUser

func (s *PostgresStore) GetUser(ctx context.Context, id string) (*User, error)

GetUser retrieves a user by ID.

func (*PostgresStore) GetUserByGitHubID

func (s *PostgresStore) GetUserByGitHubID(ctx context.Context, githubID string) (*User, error)

GetUserByGitHubID retrieves a user by GitHub ID.

func (*PostgresStore) GetUserByUsername

func (s *PostgresStore) GetUserByUsername(ctx context.Context, username string) (*User, error)

GetUserByUsername retrieves a user by username.

func (*PostgresStore) HasAnyJobs

func (s *PostgresStore) HasAnyJobs(ctx context.Context, templateID string) (bool, error)

HasAnyJobs checks if a template has any jobs (regardless of status).

func (*PostgresStore) ListAuditEntries

func (s *PostgresStore) ListAuditEntries(
	ctx context.Context, opts AuditQueryOpts,
) ([]*AuditEntry, int, error)

ListAuditEntries retrieves audit entries with filtering and pagination.

func (*PostgresStore) ListGroups

func (s *PostgresStore) ListGroups(ctx context.Context) ([]*Group, error)

ListGroups retrieves all groups.

func (*PostgresStore) ListJobHistory

func (s *PostgresStore) ListJobHistory(ctx context.Context, opts HistoryQueryOpts) (*HistoryResult, error)

ListJobHistory retrieves paginated job history with cursor-based pagination.

func (*PostgresStore) ListJobTemplatesByGroup

func (s *PostgresStore) ListJobTemplatesByGroup(ctx context.Context, groupID string) ([]*JobTemplate, error)

ListJobTemplatesByGroup retrieves all job templates for a group.

func (*PostgresStore) ListJobsByGroup

func (s *PostgresStore) ListJobsByGroup(
	ctx context.Context, groupID string, statuses ...JobStatus,
) ([]*Job, error)

ListJobsByGroup retrieves jobs for a group, optionally filtered by status.

func (*PostgresStore) ListJobsByStatus

func (s *PostgresStore) ListJobsByStatus(ctx context.Context, statuses ...JobStatus) ([]*Job, error)

ListJobsByStatus retrieves all jobs with the given statuses.

func (*PostgresStore) ListRunners

func (s *PostgresStore) ListRunners(ctx context.Context) ([]*Runner, error)

ListRunners retrieves all runners.

func (*PostgresStore) ListRunnersByLabels

func (s *PostgresStore) ListRunnersByLabels(ctx context.Context, labels []string) ([]*Runner, error)

ListRunnersByLabels retrieves runners that have all the specified labels.

func (*PostgresStore) Migrate

func (s *PostgresStore) Migrate(ctx context.Context) error

Migrate runs database migrations.

func (*PostgresStore) Ping

func (s *PostgresStore) Ping(ctx context.Context) error

Ping checks database connectivity.

func (*PostgresStore) ReorderJobs

func (s *PostgresStore) ReorderJobs(ctx context.Context, groupID string, jobIDs []string) error

ReorderJobs updates job positions based on the provided order.

func (*PostgresStore) Start

func (s *PostgresStore) Start(ctx context.Context) error

Start opens the database connection.

func (*PostgresStore) Stop

func (s *PostgresStore) Stop() error

Stop closes the database connection.

func (*PostgresStore) UpdateGroup

func (s *PostgresStore) UpdateGroup(ctx context.Context, group *Group) error

UpdateGroup updates an existing group.

func (*PostgresStore) UpdateJob

func (s *PostgresStore) UpdateJob(ctx context.Context, job *Job) error

UpdateJob updates an existing job.

func (*PostgresStore) UpdateJobTemplate

func (s *PostgresStore) UpdateJobTemplate(ctx context.Context, template *JobTemplate) error

UpdateJobTemplate updates an existing job template.

func (*PostgresStore) UpdateTemplateInConfig

func (s *PostgresStore) UpdateTemplateInConfig(ctx context.Context, id string, inConfig bool) error

UpdateTemplateInConfig updates the in_config status of a job template.

func (*PostgresStore) UpdateUser

func (s *PostgresStore) UpdateUser(ctx context.Context, user *User) error

UpdateUser updates an existing user.

func (*PostgresStore) UpsertRunner

func (s *PostgresStore) UpsertRunner(ctx context.Context, runner *Runner) error

UpsertRunner creates or updates a runner.

type Role

type Role string

Role represents a user's access level.

const (
	RoleReadOnly Role = "readonly"
	RoleAdmin    Role = "admin"
)

type Runner

type Runner struct {
	ID         int64        `json:"id"`
	Name       string       `json:"name"`
	Labels     []string     `json:"labels"`
	Status     RunnerStatus `json:"status"`
	Busy       bool         `json:"busy"`
	OS         string       `json:"os"`
	LastSeenAt time.Time    `json:"last_seen_at"`
	CreatedAt  time.Time    `json:"created_at"`
	UpdatedAt  time.Time    `json:"updated_at"`
}

Runner represents a GitHub Actions runner.

type RunnerStatus

type RunnerStatus string

RunnerStatus represents the status of a GitHub Actions runner.

const (
	RunnerStatusOnline  RunnerStatus = "online"
	RunnerStatusOffline RunnerStatus = "offline"
)

type SQLiteStore

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

SQLiteStore implements Store using SQLite.

func (*SQLiteStore) CreateAuditEntry

func (s *SQLiteStore) CreateAuditEntry(ctx context.Context, entry *AuditEntry) error

CreateAuditEntry creates a new audit log entry.

func (*SQLiteStore) CreateAuthCode

func (s *SQLiteStore) CreateAuthCode(ctx context.Context, code *AuthCode) error

CreateAuthCode creates a new one-time auth code for token exchange.

func (*SQLiteStore) CreateGroup

func (s *SQLiteStore) CreateGroup(ctx context.Context, group *Group) error

CreateGroup creates a new group.

func (*SQLiteStore) CreateJob

func (s *SQLiteStore) CreateJob(ctx context.Context, job *Job) error

CreateJob creates a new job.

func (*SQLiteStore) CreateJobTemplate

func (s *SQLiteStore) CreateJobTemplate(ctx context.Context, template *JobTemplate) error

CreateJobTemplate creates a new job template.

func (*SQLiteStore) CreateOAuthState

func (s *SQLiteStore) CreateOAuthState(ctx context.Context, state *OAuthState) error

CreateOAuthState creates a new OAuth state for CSRF protection.

func (*SQLiteStore) CreateSession

func (s *SQLiteStore) CreateSession(ctx context.Context, session *Session) error

CreateSession creates a new session.

func (*SQLiteStore) CreateUser

func (s *SQLiteStore) CreateUser(ctx context.Context, user *User) error

CreateUser creates a new user.

func (*SQLiteStore) DeleteAuthCode

func (s *SQLiteStore) DeleteAuthCode(ctx context.Context, code string) error

DeleteAuthCode deletes an auth code.

func (*SQLiteStore) DeleteExpiredAuthCodes

func (s *SQLiteStore) DeleteExpiredAuthCodes(ctx context.Context) error

DeleteExpiredAuthCodes deletes all expired auth codes.

func (*SQLiteStore) DeleteExpiredOAuthStates

func (s *SQLiteStore) DeleteExpiredOAuthStates(ctx context.Context) error

DeleteExpiredOAuthStates deletes all expired OAuth states.

func (*SQLiteStore) DeleteExpiredSessions

func (s *SQLiteStore) DeleteExpiredSessions(ctx context.Context) error

DeleteExpiredSessions deletes all expired sessions.

func (*SQLiteStore) DeleteGroup

func (s *SQLiteStore) DeleteGroup(ctx context.Context, id string) error

DeleteGroup deletes a group by ID.

func (*SQLiteStore) DeleteJob

func (s *SQLiteStore) DeleteJob(ctx context.Context, id string) error

DeleteJob deletes a job by ID.

func (*SQLiteStore) DeleteJobTemplate

func (s *SQLiteStore) DeleteJobTemplate(ctx context.Context, id string) error

DeleteJobTemplate deletes a job template by ID.

func (*SQLiteStore) DeleteJobTemplatesByGroup

func (s *SQLiteStore) DeleteJobTemplatesByGroup(ctx context.Context, groupID string) error

DeleteJobTemplatesByGroup deletes all job templates for a group.

func (*SQLiteStore) DeleteOAuthState

func (s *SQLiteStore) DeleteOAuthState(ctx context.Context, state string) error

DeleteOAuthState deletes an OAuth state.

func (*SQLiteStore) DeleteOldJobs

func (s *SQLiteStore) DeleteOldJobs(ctx context.Context, olderThan time.Time) (int64, error)

DeleteOldJobs deletes completed, failed, or cancelled jobs older than the given time.

func (*SQLiteStore) DeleteRunner

func (s *SQLiteStore) DeleteRunner(ctx context.Context, id int64) error

DeleteRunner deletes a runner by ID.

func (*SQLiteStore) DeleteSession

func (s *SQLiteStore) DeleteSession(ctx context.Context, id string) error

DeleteSession deletes a session by ID.

func (*SQLiteStore) DeleteStaleRunners

func (s *SQLiteStore) DeleteStaleRunners(ctx context.Context, olderThan time.Time) error

DeleteStaleRunners deletes runners not seen since the given time.

func (*SQLiteStore) DeleteUser

func (s *SQLiteStore) DeleteUser(ctx context.Context, id string) error

DeleteUser deletes a user by ID.

func (*SQLiteStore) DeleteUserSessions

func (s *SQLiteStore) DeleteUserSessions(ctx context.Context, userID string) error

DeleteUserSessions deletes all sessions for a user.

func (*SQLiteStore) GetAuthCode

func (s *SQLiteStore) GetAuthCode(ctx context.Context, code string) (*AuthCode, error)

GetAuthCode retrieves an auth code by its value.

func (*SQLiteStore) GetGroup

func (s *SQLiteStore) GetGroup(ctx context.Context, id string) (*Group, error)

GetGroup retrieves a group by ID.

func (*SQLiteStore) GetHistoryStats

func (s *SQLiteStore) GetHistoryStats(ctx context.Context, opts HistoryStatsOpts) (*HistoryStatsResult, error)

GetHistoryStats retrieves aggregated job statistics for a time range.

func (*SQLiteStore) GetHistoryTimeBounds

func (s *SQLiteStore) GetHistoryTimeBounds(ctx context.Context, groupID string) (oldest, newest *time.Time, err error)

GetHistoryTimeBounds returns the oldest and newest completed_at times for history jobs.

func (*SQLiteStore) GetJob

func (s *SQLiteStore) GetJob(ctx context.Context, id string) (*Job, error)

GetJob retrieves a job by ID.

func (*SQLiteStore) GetJobTemplate

func (s *SQLiteStore) GetJobTemplate(ctx context.Context, id string) (*JobTemplate, error)

GetJobTemplate retrieves a job template by ID.

func (*SQLiteStore) GetMaxPosition

func (s *SQLiteStore) GetMaxPosition(ctx context.Context, groupID string) (int, error)

GetMaxPosition returns the maximum position for jobs in a group.

func (*SQLiteStore) GetNextPendingJob

func (s *SQLiteStore) GetNextPendingJob(ctx context.Context, groupID string) (*Job, error)

GetNextPendingJob retrieves the next pending job for a group (lowest position). Paused jobs are excluded from selection.

func (*SQLiteStore) GetOAuthState

func (s *SQLiteStore) GetOAuthState(ctx context.Context, state string) (*OAuthState, error)

GetOAuthState retrieves an OAuth state by its value.

func (*SQLiteStore) GetRunner

func (s *SQLiteStore) GetRunner(ctx context.Context, id int64) (*Runner, error)

GetRunner retrieves a runner by ID.

func (*SQLiteStore) GetRunnerByName

func (s *SQLiteStore) GetRunnerByName(ctx context.Context, name string) (*Runner, error)

GetRunnerByName retrieves a runner by name.

func (*SQLiteStore) GetSession

func (s *SQLiteStore) GetSession(ctx context.Context, id string) (*Session, error)

GetSession retrieves a session by ID.

func (*SQLiteStore) GetSessionByToken

func (s *SQLiteStore) GetSessionByToken(ctx context.Context, tokenHash string) (*Session, error)

GetSessionByToken retrieves a session by token hash.

func (*SQLiteStore) GetUser

func (s *SQLiteStore) GetUser(ctx context.Context, id string) (*User, error)

GetUser retrieves a user by ID.

func (*SQLiteStore) GetUserByGitHubID

func (s *SQLiteStore) GetUserByGitHubID(ctx context.Context, githubID string) (*User, error)

GetUserByGitHubID retrieves a user by GitHub ID.

func (*SQLiteStore) GetUserByUsername

func (s *SQLiteStore) GetUserByUsername(ctx context.Context, username string) (*User, error)

GetUserByUsername retrieves a user by username.

func (*SQLiteStore) HasAnyJobs

func (s *SQLiteStore) HasAnyJobs(ctx context.Context, templateID string) (bool, error)

HasAnyJobs checks if a template has any jobs (regardless of status).

func (*SQLiteStore) ListAuditEntries

func (s *SQLiteStore) ListAuditEntries(
	ctx context.Context, opts AuditQueryOpts,
) ([]*AuditEntry, int, error)

ListAuditEntries retrieves audit entries with filtering and pagination.

func (*SQLiteStore) ListGroups

func (s *SQLiteStore) ListGroups(ctx context.Context) ([]*Group, error)

ListGroups retrieves all groups.

func (*SQLiteStore) ListJobHistory

func (s *SQLiteStore) ListJobHistory(ctx context.Context, opts HistoryQueryOpts) (*HistoryResult, error)

ListJobHistory retrieves paginated job history with cursor-based pagination.

func (*SQLiteStore) ListJobTemplatesByGroup

func (s *SQLiteStore) ListJobTemplatesByGroup(ctx context.Context, groupID string) ([]*JobTemplate, error)

ListJobTemplatesByGroup retrieves all job templates for a group.

func (*SQLiteStore) ListJobsByGroup

func (s *SQLiteStore) ListJobsByGroup(
	ctx context.Context, groupID string, statuses ...JobStatus,
) ([]*Job, error)

ListJobsByGroup retrieves jobs for a group, optionally filtered by status.

func (*SQLiteStore) ListJobsByStatus

func (s *SQLiteStore) ListJobsByStatus(ctx context.Context, statuses ...JobStatus) ([]*Job, error)

ListJobsByStatus retrieves all jobs with the given statuses.

func (*SQLiteStore) ListRunners

func (s *SQLiteStore) ListRunners(ctx context.Context) ([]*Runner, error)

ListRunners retrieves all runners.

func (*SQLiteStore) ListRunnersByLabels

func (s *SQLiteStore) ListRunnersByLabels(ctx context.Context, labels []string) ([]*Runner, error)

ListRunnersByLabels retrieves runners that have all the specified labels.

func (*SQLiteStore) Migrate

func (s *SQLiteStore) Migrate(ctx context.Context) error

Migrate runs database migrations.

func (*SQLiteStore) Ping

func (s *SQLiteStore) Ping(ctx context.Context) error

Ping checks database connectivity.

func (*SQLiteStore) ReorderJobs

func (s *SQLiteStore) ReorderJobs(ctx context.Context, groupID string, jobIDs []string) error

ReorderJobs updates job positions based on the provided order.

func (*SQLiteStore) Start

func (s *SQLiteStore) Start(ctx context.Context) error

Start opens the database connection.

func (*SQLiteStore) Stop

func (s *SQLiteStore) Stop() error

Stop closes the database connection.

func (*SQLiteStore) UpdateGroup

func (s *SQLiteStore) UpdateGroup(ctx context.Context, group *Group) error

UpdateGroup updates an existing group.

func (*SQLiteStore) UpdateJob

func (s *SQLiteStore) UpdateJob(ctx context.Context, job *Job) error

UpdateJob updates an existing job.

func (*SQLiteStore) UpdateJobTemplate

func (s *SQLiteStore) UpdateJobTemplate(ctx context.Context, template *JobTemplate) error

UpdateJobTemplate updates an existing job template.

func (*SQLiteStore) UpdateTemplateInConfig

func (s *SQLiteStore) UpdateTemplateInConfig(ctx context.Context, id string, inConfig bool) error

UpdateTemplateInConfig updates the in_config status of a job template.

func (*SQLiteStore) UpdateUser

func (s *SQLiteStore) UpdateUser(ctx context.Context, user *User) error

UpdateUser updates an existing user.

func (*SQLiteStore) UpsertRunner

func (s *SQLiteStore) UpsertRunner(ctx context.Context, runner *Runner) error

UpsertRunner creates or updates a runner.

type Session

type Session struct {
	ID        string    `json:"id"`
	UserID    string    `json:"user_id"`
	TokenHash string    `json:"-"`
	ExpiresAt time.Time `json:"expires_at"`
	CreatedAt time.Time `json:"created_at"`
}

Session represents an active user session.

type Store

type Store interface {
	// Lifecycle.
	Start(ctx context.Context) error
	Stop() error

	// Health check.
	Ping(ctx context.Context) error

	// Groups.
	CreateGroup(ctx context.Context, group *Group) error
	GetGroup(ctx context.Context, id string) (*Group, error)
	ListGroups(ctx context.Context) ([]*Group, error)
	UpdateGroup(ctx context.Context, group *Group) error
	DeleteGroup(ctx context.Context, id string) error

	// Job Templates.
	CreateJobTemplate(ctx context.Context, template *JobTemplate) error
	GetJobTemplate(ctx context.Context, id string) (*JobTemplate, error)
	ListJobTemplatesByGroup(ctx context.Context, groupID string) ([]*JobTemplate, error)
	UpdateJobTemplate(ctx context.Context, template *JobTemplate) error
	DeleteJobTemplate(ctx context.Context, id string) error
	DeleteJobTemplatesByGroup(ctx context.Context, groupID string) error
	UpdateTemplateInConfig(ctx context.Context, id string, inConfig bool) error
	HasAnyJobs(ctx context.Context, templateID string) (bool, error)

	// Jobs.
	CreateJob(ctx context.Context, job *Job) error
	GetJob(ctx context.Context, id string) (*Job, error)
	ListJobsByGroup(ctx context.Context, groupID string, statuses ...JobStatus) ([]*Job, error)
	ListJobsByStatus(ctx context.Context, statuses ...JobStatus) ([]*Job, error)
	ListJobHistory(ctx context.Context, opts HistoryQueryOpts) (*HistoryResult, error)
	GetHistoryStats(ctx context.Context, opts HistoryStatsOpts) (*HistoryStatsResult, error)
	GetHistoryTimeBounds(ctx context.Context, groupID string) (oldest, newest *time.Time, err error)
	UpdateJob(ctx context.Context, job *Job) error
	DeleteJob(ctx context.Context, id string) error
	DeleteOldJobs(ctx context.Context, olderThan time.Time) (int64, error)
	ReorderJobs(ctx context.Context, groupID string, jobIDs []string) error
	GetNextPendingJob(ctx context.Context, groupID string) (*Job, error)
	GetMaxPosition(ctx context.Context, groupID string) (int, error)

	// Runners.
	UpsertRunner(ctx context.Context, runner *Runner) error
	GetRunner(ctx context.Context, id int64) (*Runner, error)
	GetRunnerByName(ctx context.Context, name string) (*Runner, error)
	ListRunners(ctx context.Context) ([]*Runner, error)
	ListRunnersByLabels(ctx context.Context, labels []string) ([]*Runner, error)
	DeleteRunner(ctx context.Context, id int64) error
	DeleteStaleRunners(ctx context.Context, olderThan time.Time) error

	// Users.
	CreateUser(ctx context.Context, user *User) error
	GetUser(ctx context.Context, id string) (*User, error)
	GetUserByUsername(ctx context.Context, username string) (*User, error)
	GetUserByGitHubID(ctx context.Context, githubID string) (*User, error)
	UpdateUser(ctx context.Context, user *User) error
	DeleteUser(ctx context.Context, id string) error

	// Sessions.
	CreateSession(ctx context.Context, session *Session) error
	GetSession(ctx context.Context, id string) (*Session, error)
	GetSessionByToken(ctx context.Context, tokenHash string) (*Session, error)
	DeleteSession(ctx context.Context, id string) error
	DeleteExpiredSessions(ctx context.Context) error
	DeleteUserSessions(ctx context.Context, userID string) error

	// OAuth States (CSRF protection).
	CreateOAuthState(ctx context.Context, state *OAuthState) error
	GetOAuthState(ctx context.Context, state string) (*OAuthState, error)
	DeleteOAuthState(ctx context.Context, state string) error
	DeleteExpiredOAuthStates(ctx context.Context) error

	// Auth Codes (one-time exchange codes).
	CreateAuthCode(ctx context.Context, code *AuthCode) error
	GetAuthCode(ctx context.Context, code string) (*AuthCode, error)
	DeleteAuthCode(ctx context.Context, code string) error
	DeleteExpiredAuthCodes(ctx context.Context) error

	// Audit.
	CreateAuditEntry(ctx context.Context, entry *AuditEntry) error
	ListAuditEntries(ctx context.Context, opts AuditQueryOpts) ([]*AuditEntry, int, error)

	// Migrations.
	Migrate(ctx context.Context) error
}

Store defines the interface for database operations.

func NewPostgresStore

func NewPostgresStore(log logrus.FieldLogger, dsn string) Store

NewPostgresStore creates a new PostgreSQL store.

func NewSQLiteStore

func NewSQLiteStore(log logrus.FieldLogger, path string) Store

NewSQLiteStore creates a new SQLite store.

type User

type User struct {
	ID           string       `json:"id"`
	Username     string       `json:"username"`
	PasswordHash string       `json:"-"`
	Role         Role         `json:"role"`
	AuthProvider AuthProvider `json:"auth_provider"`
	GitHubID     string       `json:"github_id,omitempty"`
	CreatedAt    time.Time    `json:"created_at"`
	UpdatedAt    time.Time    `json:"updated_at"`
}

User represents a user account.

Jump to

Keyboard shortcuts

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