sql

package
v0.0.28 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: MPL-2.0 Imports: 28 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 CreateModule added in v0.0.23

func CreateModule(ctx context.Context, db otf.Database, mod *otf.Module) error

func CreateTestOrganization added in v0.0.27

func CreateTestOrganization(t *testing.T, db otf.DB) *otf.Organization

func CreateTestWorkspace added in v0.0.27

func CreateTestWorkspace(t *testing.T, db otf.DB, org *otf.Organization, opts ...otf.NewTestWorkspaceOption) *otf.Workspace

func CreateWorkspaceRepo added in v0.0.23

func CreateWorkspaceRepo(ctx context.Context, db otf.Database, workspaceID string, repo otf.WorkspaceRepo) error

func DeleteModule added in v0.0.23

func DeleteModule(ctx context.Context, db otf.Database, id string) error

func DeleteWorkspaceRepo added in v0.0.23

func DeleteWorkspaceRepo(ctx context.Context, db otf.Database, workspaceID string) error

func Error added in v0.0.23

func Error(err error) error

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

func UUID added in v0.0.19

func UUID(s uuid.UUID) pgtype.UUID

UUID converts a google-go-uuid into a postgres non-null UUID

Types

type DB added in v0.0.12

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

DB provides access to the postgres db

func New

func New(ctx context.Context, opts Options) (*DB, error)

New constructs a new DB

func NewTestDB added in v0.0.23

func NewTestDB(t *testing.T, overrides ...newTestDBOption) *DB

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) CreateModule added in v0.0.19

func (db *DB) CreateModule(ctx context.Context, mod *otf.Module) error

func (*DB) CreateModuleVersion added in v0.0.19

func (db *DB) CreateModuleVersion(ctx context.Context, version *otf.ModuleVersion) 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) 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) CreateVCSProvider added in v0.0.16

func (db *DB) CreateVCSProvider(ctx context.Context, provider *otf.VCSProvider) error

CreateVCSProvider inserts an agent token, associating it with an organization

func (*DB) CreateWorkspace added in v0.0.12

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

func (*DB) CreateWorkspaceRepo added in v0.0.19

func (db *DB) CreateWorkspaceRepo(ctx context.Context, workspaceID string, repo otf.WorkspaceRepo) (*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) DeleteModule added in v0.0.19

func (db *DB) DeleteModule(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) DeleteTeam added in v0.0.12

func (db *DB) DeleteTeam(ctx context.Context, teamID 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) DeleteVCSProvider added in v0.0.16

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

DeleteVCSProvider deletes an agent token.

func (*DB) DeleteWorkspace added in v0.0.12

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

func (*DB) DeleteWorkspaceRepo added in v0.0.19

func (db *DB) DeleteWorkspaceRepo(ctx context.Context, workspaceID string) (*otf.Workspace, error)

func (*DB) DownloadModuleVersion added in v0.0.19

func (db *DB) DownloadModuleVersion(ctx context.Context, opts otf.DownloadModuleOptions) ([]byte, error)

func (*DB) GetAgentTokenByID added in v0.0.19

func (db *DB) GetAgentTokenByID(ctx context.Context, id string) (*otf.AgentToken, error)

func (*DB) GetAgentTokenByToken added in v0.0.19

func (db *DB) GetAgentTokenByToken(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) GetModule added in v0.0.19

func (db *DB) GetModule(ctx context.Context, opts otf.GetModuleOptions) (*otf.Module, error)

func (*DB) GetModuleByID added in v0.0.19

func (db *DB) GetModuleByID(ctx context.Context, id string) (*otf.Module, error)

func (*DB) GetModuleByWebhookID added in v0.0.19

func (db *DB) GetModuleByWebhookID(ctx context.Context, id uuid.UUID) (*otf.Module, error)

func (*DB) GetOrganization added in v0.0.12

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

func (*DB) GetOrganizationByID added in v0.0.19

func (db *DB) GetOrganizationByID(ctx context.Context, id 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) 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 by name

func (*DB) GetTeamByID added in v0.0.19

func (db *DB) GetTeamByID(ctx context.Context, id string) (*otf.Team, error)

GetTeamByID retrieves a team from the DB by ID.

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) GetVCSProvider added in v0.0.16

func (db *DB) GetVCSProvider(ctx context.Context, id string) (*otf.VCSProvider, error)

func (*DB) GetWorkspace added in v0.0.12

func (db *DB) GetWorkspace(ctx context.Context, workspaceID string) (*otf.Workspace, error)

func (*DB) GetWorkspaceByName added in v0.0.21

func (db *DB) GetWorkspaceByName(ctx context.Context, organization, workspace string) (*otf.Workspace, 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) ListModules added in v0.0.19

func (db *DB) ListModules(ctx context.Context, opts otf.ListModulesOptions) ([]*otf.Module, error)

func (*DB) ListOrganizations added in v0.0.12

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

func (*DB) ListOrganizationsByUser added in v0.0.21

func (db *DB) ListOrganizationsByUser(ctx context.Context, userID string) ([]*otf.Organization, 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) ListTeamMembers added in v0.0.19

func (db *DB) ListTeamMembers(ctx context.Context, teamID string) ([]*otf.User, 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) ListVCSProviders added in v0.0.16

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

func (*DB) ListWorkspacePermissions added in v0.0.12

func (db *DB) ListWorkspacePermissions(ctx context.Context, workspaceID string) ([]*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) ListWorkspacesByWebhookID added in v0.0.19

func (db *DB) ListWorkspacesByWebhookID(ctx context.Context, id uuid.UUID) ([]*otf.Workspace, error)

func (*DB) LockWorkspace added in v0.0.12

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

LockWorkspace locks the specified workspace.

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) (*otf.Workspace, 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, workspaceID, team string, role rbac.Role) error

func (*DB) Transaction added in v0.0.23

func (db *DB) Transaction(ctx context.Context, callback func(otf.Database) error) error

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

func (*DB) Tx added in v0.0.12

func (db *DB) Tx(ctx context.Context, callback func(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, workspaceID string, 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, workspaceID, team string) error

func (*DB) UpdateModuleStatus added in v0.0.19

func (db *DB) UpdateModuleStatus(ctx context.Context, opts otf.UpdateModuleStatusOptions) error

func (*DB) UpdateModuleVersionStatus added in v0.0.19

func (db *DB) UpdateModuleVersionStatus(ctx context.Context, opts otf.UpdateModuleVersionStatusOptions) (*otf.ModuleVersion, 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, teamID string, fn func(*otf.Team) error) (*otf.Team, error)

func (*DB) UpdateWorkspace added in v0.0.12

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

func (*DB) UpdateWorkspaceRepo added in v0.0.16

func (db *DB) UpdateWorkspaceRepo(ctx context.Context, workspaceID string, repo otf.WorkspaceRepo) (*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) UploadModuleVersion added in v0.0.19

func (db *DB) UploadModuleVersion(ctx context.Context, opts otf.UploadModuleVersionOptions) 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 Options added in v0.0.19

type Options struct {
	Logger          logr.Logger
	ConnString      string
	Cache           otf.Cache
	CleanupInterval time.Duration
	CloudService    cloud.Service
}

Options for constructing a DB

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.

type Tx added in v0.0.23

type Tx interface {
	Transaction(ctx context.Context, callback func(otf.Database) error) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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