sql

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2022 License: MPL-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package sql implements persistent storage using the sql database.

Index

Constants

View Source
const EventsChannelName = "events"
View Source
const TestDatabaseURL = "OTF_TEST_DATABASE_URL"

Variables

View Source
var DefaultSessionCleanupInterval = 5 * time.Minute

Functions

func String added in v0.0.12

func String(s string) pgtype.Text

String converts a go-string into a postgres non-null string

func Timestamptz added in v0.0.12

func Timestamptz(t time.Time) pgtype.Timestamptz

Timestamptz converts a go-time into a postgres non-null timestamptz

Types

type DB added in v0.0.12

type DB struct {
	pggen.Querier
	// contains filtered or unexported fields
}

DB provides access to the postgres db

func New

func New(logger logr.Logger, path string, cache otf.Cache, cleanupInterval time.Duration) (*DB, error)

New constructs a new DB

TODO: pass in context

func (*DB) AddOrganizationMembership added in v0.0.12

func (db *DB) AddOrganizationMembership(ctx context.Context, id, orgID string) error

func (*DB) AddTeamMembership added in v0.0.12

func (db *DB) AddTeamMembership(ctx context.Context, userID, teamID string) error

func (*DB) Close added in v0.0.12

func (db *DB) Close()

Close closes the DB's connections. If the DB has wrapped a transaction then this method has no effect.

func (*DB) CreateAgentToken added in v0.0.12

func (db *DB) CreateAgentToken(ctx context.Context, token *otf.AgentToken) error

CreateAgentToken inserts an agent token, associating it with an organization

func (*DB) CreateApplyReport added in v0.0.12

func (db *DB) CreateApplyReport(ctx context.Context, runID string, report otf.ResourceReport) error

func (*DB) CreateConfigurationVersion added in v0.0.12

func (db *DB) CreateConfigurationVersion(ctx context.Context, cv *otf.ConfigurationVersion) error

func (*DB) CreateOrganization added in v0.0.12

func (db *DB) CreateOrganization(ctx context.Context, org *otf.Organization) error

CreateOrganization persists an Organization to the DB.

func (*DB) CreatePlanReport added in v0.0.12

func (db *DB) CreatePlanReport(ctx context.Context, runID string, report otf.ResourceReport) error

func (*DB) CreateRun added in v0.0.12

func (db *DB) CreateRun(ctx context.Context, run *otf.Run) error

CreateRun persists a Run to the DB.

func (*DB) CreateSession added in v0.0.12

func (db *DB) CreateSession(ctx context.Context, session *otf.Session) error

CreateSession inserts the session, associating it with the user.

func (*DB) CreateStateVersion added in v0.0.12

func (db *DB) CreateStateVersion(ctx context.Context, workspaceID string, sv *otf.StateVersion) error

CreateStateVersion persists a StateVersion to the DB.

func (*DB) CreateTeam added in v0.0.12

func (db *DB) CreateTeam(ctx context.Context, team *otf.Team) error

CreateTeam persists a team to the DB.

func (*DB) CreateToken added in v0.0.12

func (db *DB) CreateToken(ctx context.Context, token *otf.Token) error

CreateToken inserts the token, associating it with the user.

func (*DB) CreateUser added in v0.0.12

func (db *DB) CreateUser(ctx context.Context, user *otf.User) error

CreateUser persists a User to the DB.

func (*DB) CreateWorkspace added in v0.0.12

func (db *DB) CreateWorkspace(ctx context.Context, ws *otf.Workspace) error

func (*DB) DeleteAgentToken added in v0.0.12

func (db *DB) DeleteAgentToken(ctx context.Context, id string) error

DeleteAgentToken deletes an agent token.

func (*DB) DeleteConfigurationVersion added in v0.0.12

func (db *DB) DeleteConfigurationVersion(ctx context.Context, id string) error

func (*DB) DeleteOrganization added in v0.0.12

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

func (*DB) DeleteRun added in v0.0.12

func (db *DB) DeleteRun(ctx context.Context, id string) error

DeleteRun deletes a run from the DB

func (*DB) DeleteSession added in v0.0.12

func (db *DB) DeleteSession(ctx context.Context, token string) error

DeleteSession deletes a user's session from the DB.

func (*DB) DeleteStateVersion added in v0.0.12

func (db *DB) DeleteStateVersion(ctx context.Context, id string) error

DeleteStateVersion deletes a state version from the DB

func (*DB) DeleteTeam added in v0.0.12

func (db *DB) DeleteTeam(ctx context.Context, name, organization string) error

DeleteTeam deletes a team from the DB.

func (*DB) DeleteToken added in v0.0.12

func (db *DB) DeleteToken(ctx context.Context, id string) error

DeleteToken deletes a user's token from the DB.

func (*DB) DeleteUser added in v0.0.12

func (db *DB) DeleteUser(ctx context.Context, spec otf.UserSpec) error

DeleteUser deletes a user from the DB.

func (*DB) DeleteWorkspace added in v0.0.12

func (db *DB) DeleteWorkspace(ctx context.Context, spec otf.WorkspaceSpec) error

DeleteWorkspace deletes a specific workspace, along with its child records (runs etc).

func (*DB) GetAgentToken added in v0.0.12

func (db *DB) GetAgentToken(ctx context.Context, token string) (*otf.AgentToken, error)

func (*DB) GetChunk added in v0.0.12

func (db *DB) GetChunk(ctx context.Context, opts otf.GetChunkOptions) (otf.Chunk, error)

GetChunk retrieves a log chunk from the DB.

func (*DB) GetChunkByID added in v0.0.12

func (db *DB) GetChunkByID(ctx context.Context, chunkID int) (otf.PersistedChunk, error)

GetChunkByID retrieves a plan log chunk from the DB using its unique chunk ID.

func (*DB) GetConfig added in v0.0.12

func (db *DB) GetConfig(ctx context.Context, id string) ([]byte, error)

func (*DB) GetConfigurationVersion added in v0.0.12

func (db *DB) GetConfigurationVersion(ctx context.Context, opts otf.ConfigurationVersionGetOptions) (*otf.ConfigurationVersion, error)

func (*DB) GetLockFile added in v0.0.12

func (db *DB) GetLockFile(ctx context.Context, runID string) ([]byte, error)

GetLockFile retrieves the lock file for the run

func (*DB) GetOrganization added in v0.0.12

func (db *DB) GetOrganization(ctx context.Context, name string) (*otf.Organization, error)

func (*DB) GetOrganizationNameByWorkspaceID added in v0.0.12

func (db *DB) GetOrganizationNameByWorkspaceID(ctx context.Context, workspaceID string) (string, error)

func (*DB) GetPlanFile added in v0.0.12

func (db *DB) GetPlanFile(ctx context.Context, runID string, format otf.PlanFormat) ([]byte, error)

GetPlanFile retrieves a plan file for the run

func (*DB) GetRun added in v0.0.12

func (db *DB) GetRun(ctx context.Context, runID string) (*otf.Run, error)

GetRun retrieves a run using the get options

func (*DB) GetSessionByToken added in v0.0.12

func (db *DB) GetSessionByToken(ctx context.Context, token string) (*otf.Session, error)

func (*DB) GetState added in v0.0.12

func (db *DB) GetState(ctx context.Context, id string) ([]byte, error)

func (*DB) GetStateVersion added in v0.0.12

func (db *DB) GetStateVersion(ctx context.Context, opts otf.StateVersionGetOptions) (*otf.StateVersion, error)

func (*DB) GetTeam added in v0.0.12

func (db *DB) GetTeam(ctx context.Context, name, organization string) (*otf.Team, error)

GetTeam retrieves a team from the DB

func (*DB) GetUser added in v0.0.12

func (db *DB) GetUser(ctx context.Context, spec otf.UserSpec) (*otf.User, error)

GetUser retrieves a user from the DB, along with its sessions.

func (*DB) GetWorkspace added in v0.0.12

func (db *DB) GetWorkspace(ctx context.Context, spec otf.WorkspaceSpec) (*otf.Workspace, error)

func (*DB) GetWorkspaceID added in v0.0.12

func (db *DB) GetWorkspaceID(ctx context.Context, spec otf.WorkspaceSpec) (string, error)

func (*DB) GetWorkspaceIDByCVID added in v0.0.12

func (db *DB) GetWorkspaceIDByCVID(ctx context.Context, cvID string) (string, error)

func (*DB) GetWorkspaceIDByRunID added in v0.0.12

func (db *DB) GetWorkspaceIDByRunID(ctx context.Context, runID string) (string, error)

func (*DB) GetWorkspaceIDByStateVersionID added in v0.0.12

func (db *DB) GetWorkspaceIDByStateVersionID(ctx context.Context, svID string) (string, error)

func (*DB) ListAgentTokens added in v0.0.12

func (db *DB) ListAgentTokens(ctx context.Context, organizationName string) ([]*otf.AgentToken, error)

func (*DB) ListConfigurationVersions added in v0.0.12

func (db *DB) ListConfigurationVersions(ctx context.Context, workspaceID string, opts otf.ConfigurationVersionListOptions) (*otf.ConfigurationVersionList, error)

func (*DB) ListOrganizations added in v0.0.12

func (db *DB) ListOrganizations(ctx context.Context, opts otf.OrganizationListOptions) (*otf.OrganizationList, error)

func (*DB) ListRuns added in v0.0.12

func (db *DB) ListRuns(ctx context.Context, opts otf.RunListOptions) (*otf.RunList, error)

func (*DB) ListSessions added in v0.0.12

func (db *DB) ListSessions(ctx context.Context, userID string) ([]*otf.Session, error)

func (*DB) ListStateVersions added in v0.0.12

func (db *DB) ListStateVersions(ctx context.Context, opts otf.StateVersionListOptions) (*otf.StateVersionList, error)

func (*DB) ListTeams added in v0.0.12

func (db *DB) ListTeams(ctx context.Context, organization string) ([]*otf.Team, error)

func (*DB) ListTokens added in v0.0.12

func (db *DB) ListTokens(ctx context.Context, userID string) ([]*otf.Token, error)

func (*DB) ListUsers added in v0.0.12

func (db *DB) ListUsers(ctx context.Context, opts otf.UserListOptions) ([]*otf.User, error)

func (*DB) ListWorkspacePermissions added in v0.0.12

func (db *DB) ListWorkspacePermissions(ctx context.Context, spec otf.WorkspaceSpec) ([]*otf.WorkspacePermission, error)

func (*DB) ListWorkspaces added in v0.0.12

func (db *DB) ListWorkspaces(ctx context.Context, opts otf.WorkspaceListOptions) (*otf.WorkspaceList, error)

func (*DB) ListWorkspacesByUserID added in v0.0.12

func (db *DB) ListWorkspacesByUserID(ctx context.Context, userID string, organization string, opts otf.ListOptions) (*otf.WorkspaceList, error)

func (*DB) LockWorkspace added in v0.0.12

func (db *DB) LockWorkspace(ctx context.Context, spec otf.WorkspaceSpec, opts otf.WorkspaceLockOptions) (*otf.Workspace, error)

LockWorkspace locks the specified workspace.

func (*DB) Pool added in v0.0.12

func (db *DB) Pool() *pgxpool.Pool

func (*DB) PutChunk added in v0.0.12

func (db *DB) PutChunk(ctx context.Context, chunk otf.Chunk) (otf.PersistedChunk, error)

PutChunk persists a log chunk to the DB.

func (*DB) RemoveOrganizationMembership added in v0.0.12

func (db *DB) RemoveOrganizationMembership(ctx context.Context, id, orgID string) error

func (*DB) RemoveTeamMembership added in v0.0.12

func (db *DB) RemoveTeamMembership(ctx context.Context, userID, teamID string) error

func (*DB) SetCurrentRun added in v0.0.12

func (db *DB) SetCurrentRun(ctx context.Context, workspaceID, runID string) error

SetCurrentRun sets the ID of the current run for the specified workspace.

func (*DB) SetLockFile added in v0.0.12

func (db *DB) SetLockFile(ctx context.Context, runID string, lockFile []byte) error

SetLockFile sets the lock file for the run

func (*DB) SetPlanFile added in v0.0.12

func (db *DB) SetPlanFile(ctx context.Context, runID string, file []byte, format otf.PlanFormat) error

SetPlanFile writes a plan file to the db

func (*DB) SetWorkspacePermission added in v0.0.12

func (db *DB) SetWorkspacePermission(ctx context.Context, spec otf.WorkspaceSpec, team string, role otf.WorkspaceRole) error

func (*DB) Tx added in v0.0.12

func (db *DB) Tx(ctx context.Context, callback func(tx otf.DB) error) error

Tx provides the caller with a callback in which all operations are conducted within a transaction.

func (*DB) UnlockWorkspace added in v0.0.12

func (db *DB) UnlockWorkspace(ctx context.Context, spec otf.WorkspaceSpec, opts otf.WorkspaceUnlockOptions) (*otf.Workspace, error)

UnlockWorkspace unlocks the specified workspace; the caller has the opportunity to check the current locker passed into the provided callback. If an error is returned the unlock will not go ahead.

func (*DB) UnsetWorkspacePermission added in v0.0.12

func (db *DB) UnsetWorkspacePermission(ctx context.Context, spec otf.WorkspaceSpec, team string) error

func (*DB) UpdateOrganization added in v0.0.12

func (db *DB) UpdateOrganization(ctx context.Context, name string, fn func(*otf.Organization) error) (*otf.Organization, error)

UpdateOrganization persists an updated Organization to the DB. The existing org is fetched from the DB, the supplied func is invoked on the org, and the updated org is persisted back to the DB.

func (*DB) UpdateStatus added in v0.0.12

func (db *DB) UpdateStatus(ctx context.Context, runID string, fn func(*otf.Run) error) (*otf.Run, error)

UpdateStatus updates the run status as well as its plan and/or apply.

func (*DB) UpdateTeam added in v0.0.12

func (db *DB) UpdateTeam(ctx context.Context, name, organization string, fn func(*otf.Team) error) (*otf.Team, error)

func (*DB) UpdateWorkspace added in v0.0.12

func (db *DB) UpdateWorkspace(ctx context.Context, spec otf.WorkspaceSpec, fn func(*otf.Workspace) error) (*otf.Workspace, error)

func (*DB) UploadConfigurationVersion added in v0.0.12

func (db *DB) UploadConfigurationVersion(ctx context.Context, id string, fn func(*otf.ConfigurationVersion, otf.ConfigUploader) error) error

func (*DB) WaitAndLock added in v0.0.12

func (db *DB) WaitAndLock(ctx context.Context, id int64, cb func(otf.DB) error) error

type NewPubSubOption added in v0.0.12

type NewPubSubOption func(*PubSub)

func ChannelName added in v0.0.12

func ChannelName(name string) NewPubSubOption

func PID added in v0.0.12

func PID(pid string) NewPubSubOption

type PubSub added in v0.0.12

type PubSub struct {
	logr.Logger
	// contains filtered or unexported fields
}

PubSub implements a distributed 'pub-sub' service for events, using postgres as a central broker

func NewPubSub added in v0.0.12

func NewPubSub(logger logr.Logger, db *DB, opts ...NewPubSubOption) (*PubSub, error)

func (*PubSub) Publish added in v0.0.12

func (ps *PubSub) Publish(event otf.Event)

Publish sends an event to subscribers, via postgres to subscribers on other machines, and via the local broker to subscribers within the same process.

func (*PubSub) Start added in v0.0.12

func (ps *PubSub) Start(ctx context.Context) error

Start the pubsub daemon; listen to notifications from postgres and forward to local pubsub broker.

func (*PubSub) Subscribe added in v0.0.12

func (ps *PubSub) Subscribe(ctx context.Context, name string) (<-chan otf.Event, error)

Subscribe subscribes the caller to a stream of events.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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