Documentation
¶
Overview ¶
Package sql implements persistent storage using the sql database.
Index ¶
- Constants
- Variables
- func String(s string) pgtype.Text
- func Timestamptz(t time.Time) pgtype.Timestamptz
- type DB
- func (db *DB) AddOrganizationMembership(ctx context.Context, id, orgID string) error
- func (db *DB) AddTeamMembership(ctx context.Context, userID, teamID string) error
- func (db *DB) Close()
- func (db *DB) CreateAgentToken(ctx context.Context, token *otf.AgentToken) error
- func (db *DB) CreateApplyReport(ctx context.Context, runID string, report otf.ResourceReport) error
- func (db *DB) CreateConfigurationVersion(ctx context.Context, cv *otf.ConfigurationVersion) error
- func (db *DB) CreateOrganization(ctx context.Context, org *otf.Organization) error
- func (db *DB) CreatePlanReport(ctx context.Context, runID string, report otf.ResourceReport) error
- func (db *DB) CreateRun(ctx context.Context, run *otf.Run) error
- func (db *DB) CreateSession(ctx context.Context, session *otf.Session) error
- func (db *DB) CreateStateVersion(ctx context.Context, workspaceID string, sv *otf.StateVersion) error
- func (db *DB) CreateTeam(ctx context.Context, team *otf.Team) error
- func (db *DB) CreateToken(ctx context.Context, token *otf.Token) error
- func (db *DB) CreateUser(ctx context.Context, user *otf.User) error
- func (db *DB) CreateWorkspace(ctx context.Context, ws *otf.Workspace) error
- func (db *DB) DeleteAgentToken(ctx context.Context, id string) error
- func (db *DB) DeleteConfigurationVersion(ctx context.Context, id string) error
- func (db *DB) DeleteOrganization(ctx context.Context, name string) error
- func (db *DB) DeleteRun(ctx context.Context, id string) error
- func (db *DB) DeleteSession(ctx context.Context, token string) error
- func (db *DB) DeleteStateVersion(ctx context.Context, id string) error
- func (db *DB) DeleteTeam(ctx context.Context, name, organization string) error
- func (db *DB) DeleteToken(ctx context.Context, id string) error
- func (db *DB) DeleteUser(ctx context.Context, spec otf.UserSpec) error
- func (db *DB) DeleteWorkspace(ctx context.Context, spec otf.WorkspaceSpec) error
- func (db *DB) GetAgentToken(ctx context.Context, token string) (*otf.AgentToken, error)
- func (db *DB) GetChunk(ctx context.Context, opts otf.GetChunkOptions) (otf.Chunk, error)
- func (db *DB) GetChunkByID(ctx context.Context, chunkID int) (otf.PersistedChunk, error)
- func (db *DB) GetConfig(ctx context.Context, id string) ([]byte, error)
- func (db *DB) GetConfigurationVersion(ctx context.Context, opts otf.ConfigurationVersionGetOptions) (*otf.ConfigurationVersion, error)
- func (db *DB) GetLockFile(ctx context.Context, runID string) ([]byte, error)
- func (db *DB) GetOrganization(ctx context.Context, name string) (*otf.Organization, error)
- func (db *DB) GetOrganizationNameByWorkspaceID(ctx context.Context, workspaceID string) (string, error)
- func (db *DB) GetPlanFile(ctx context.Context, runID string, format otf.PlanFormat) ([]byte, error)
- func (db *DB) GetRun(ctx context.Context, runID string) (*otf.Run, error)
- func (db *DB) GetSessionByToken(ctx context.Context, token string) (*otf.Session, error)
- func (db *DB) GetState(ctx context.Context, id string) ([]byte, error)
- func (db *DB) GetStateVersion(ctx context.Context, opts otf.StateVersionGetOptions) (*otf.StateVersion, error)
- func (db *DB) GetTeam(ctx context.Context, name, organization string) (*otf.Team, error)
- func (db *DB) GetUser(ctx context.Context, spec otf.UserSpec) (*otf.User, error)
- func (db *DB) GetWorkspace(ctx context.Context, spec otf.WorkspaceSpec) (*otf.Workspace, error)
- func (db *DB) GetWorkspaceID(ctx context.Context, spec otf.WorkspaceSpec) (string, error)
- func (db *DB) GetWorkspaceIDByCVID(ctx context.Context, cvID string) (string, error)
- func (db *DB) GetWorkspaceIDByRunID(ctx context.Context, runID string) (string, error)
- func (db *DB) GetWorkspaceIDByStateVersionID(ctx context.Context, svID string) (string, error)
- func (db *DB) ListAgentTokens(ctx context.Context, organizationName string) ([]*otf.AgentToken, error)
- func (db *DB) ListConfigurationVersions(ctx context.Context, workspaceID string, ...) (*otf.ConfigurationVersionList, error)
- func (db *DB) ListOrganizations(ctx context.Context, opts otf.OrganizationListOptions) (*otf.OrganizationList, error)
- func (db *DB) ListRuns(ctx context.Context, opts otf.RunListOptions) (*otf.RunList, error)
- func (db *DB) ListSessions(ctx context.Context, userID string) ([]*otf.Session, error)
- func (db *DB) ListStateVersions(ctx context.Context, opts otf.StateVersionListOptions) (*otf.StateVersionList, error)
- func (db *DB) ListTeams(ctx context.Context, organization string) ([]*otf.Team, error)
- func (db *DB) ListTokens(ctx context.Context, userID string) ([]*otf.Token, error)
- func (db *DB) ListUsers(ctx context.Context, opts otf.UserListOptions) ([]*otf.User, error)
- func (db *DB) ListWorkspacePermissions(ctx context.Context, spec otf.WorkspaceSpec) ([]*otf.WorkspacePermission, error)
- func (db *DB) ListWorkspaces(ctx context.Context, opts otf.WorkspaceListOptions) (*otf.WorkspaceList, error)
- func (db *DB) ListWorkspacesByUserID(ctx context.Context, userID string, organization string, opts otf.ListOptions) (*otf.WorkspaceList, error)
- func (db *DB) LockWorkspace(ctx context.Context, spec otf.WorkspaceSpec, opts otf.WorkspaceLockOptions) (*otf.Workspace, error)
- func (db *DB) Pool() *pgxpool.Pool
- func (db *DB) PutChunk(ctx context.Context, chunk otf.Chunk) (otf.PersistedChunk, error)
- func (db *DB) RemoveOrganizationMembership(ctx context.Context, id, orgID string) error
- func (db *DB) RemoveTeamMembership(ctx context.Context, userID, teamID string) error
- func (db *DB) SetCurrentRun(ctx context.Context, workspaceID, runID string) error
- func (db *DB) SetLockFile(ctx context.Context, runID string, lockFile []byte) error
- func (db *DB) SetPlanFile(ctx context.Context, runID string, file []byte, format otf.PlanFormat) error
- func (db *DB) SetWorkspacePermission(ctx context.Context, spec otf.WorkspaceSpec, team string, ...) error
- func (db *DB) Tx(ctx context.Context, callback func(tx otf.DB) error) error
- func (db *DB) UnlockWorkspace(ctx context.Context, spec otf.WorkspaceSpec, opts otf.WorkspaceUnlockOptions) (*otf.Workspace, error)
- func (db *DB) UnsetWorkspacePermission(ctx context.Context, spec otf.WorkspaceSpec, team string) error
- func (db *DB) UpdateOrganization(ctx context.Context, name string, fn func(*otf.Organization) error) (*otf.Organization, error)
- func (db *DB) UpdateStatus(ctx context.Context, runID string, fn func(*otf.Run) error) (*otf.Run, error)
- func (db *DB) UpdateTeam(ctx context.Context, name, organization string, fn func(*otf.Team) error) (*otf.Team, error)
- func (db *DB) UpdateWorkspace(ctx context.Context, spec otf.WorkspaceSpec, fn func(*otf.Workspace) error) (*otf.Workspace, error)
- func (db *DB) UploadConfigurationVersion(ctx context.Context, id string, ...) error
- func (db *DB) WaitAndLock(ctx context.Context, id int64, cb func(otf.DB) error) error
- type NewPubSubOption
- type PubSub
Constants ¶
const EventsChannelName = "events"
const TestDatabaseURL = "OTF_TEST_DATABASE_URL"
Variables ¶
var DefaultSessionCleanupInterval = 5 * time.Minute
Functions ¶
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
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) AddTeamMembership ¶ added in v0.0.12
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
CreateAgentToken inserts an agent token, associating it with an organization
func (*DB) CreateApplyReport ¶ added in v0.0.12
func (*DB) CreateConfigurationVersion ¶ added in v0.0.12
func (*DB) CreateOrganization ¶ added in v0.0.12
CreateOrganization persists an Organization to the DB.
func (*DB) CreatePlanReport ¶ added in v0.0.12
func (*DB) CreateSession ¶ added in v0.0.12
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
CreateTeam persists a team to the DB.
func (*DB) CreateToken ¶ added in v0.0.12
CreateToken inserts the token, associating it with the user.
func (*DB) CreateUser ¶ added in v0.0.12
CreateUser persists a User to the DB.
func (*DB) CreateWorkspace ¶ added in v0.0.12
func (*DB) DeleteAgentToken ¶ added in v0.0.12
DeleteAgentToken deletes an agent token.
func (*DB) DeleteConfigurationVersion ¶ added in v0.0.12
func (*DB) DeleteOrganization ¶ added in v0.0.12
func (*DB) DeleteSession ¶ added in v0.0.12
DeleteSession deletes a user's session from the DB.
func (*DB) DeleteStateVersion ¶ added in v0.0.12
DeleteStateVersion deletes a state version from the DB
func (*DB) DeleteTeam ¶ added in v0.0.12
DeleteTeam deletes a team from the DB.
func (*DB) DeleteToken ¶ added in v0.0.12
DeleteToken deletes a user's token from the DB.
func (*DB) DeleteUser ¶ added in v0.0.12
DeleteUser deletes a user from the DB.
func (*DB) DeleteWorkspace ¶ added in v0.0.12
DeleteWorkspace deletes a specific workspace, along with its child records (runs etc).
func (*DB) GetAgentToken ¶ added in v0.0.12
func (*DB) GetChunkByID ¶ added in v0.0.12
GetChunkByID retrieves a plan log chunk from the DB using its unique chunk ID.
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
GetLockFile retrieves the lock file for the run
func (*DB) GetOrganization ¶ added in v0.0.12
func (*DB) GetOrganizationNameByWorkspaceID ¶ added in v0.0.12
func (*DB) GetPlanFile ¶ added in v0.0.12
GetPlanFile retrieves a plan file for the run
func (*DB) GetSessionByToken ¶ added in v0.0.12
func (*DB) GetStateVersion ¶ added in v0.0.12
func (db *DB) GetStateVersion(ctx context.Context, opts otf.StateVersionGetOptions) (*otf.StateVersion, error)
func (*DB) GetUser ¶ added in v0.0.12
GetUser retrieves a user from the DB, along with its sessions.
func (*DB) GetWorkspace ¶ added in v0.0.12
func (*DB) GetWorkspaceID ¶ added in v0.0.12
func (*DB) GetWorkspaceIDByCVID ¶ added in v0.0.12
func (*DB) GetWorkspaceIDByRunID ¶ added in v0.0.12
func (*DB) GetWorkspaceIDByStateVersionID ¶ added in v0.0.12
func (*DB) ListAgentTokens ¶ added in v0.0.12
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) ListSessions ¶ added in v0.0.12
func (*DB) ListStateVersions ¶ added in v0.0.12
func (db *DB) ListStateVersions(ctx context.Context, opts otf.StateVersionListOptions) (*otf.StateVersionList, error)
func (*DB) ListTokens ¶ added in v0.0.12
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) RemoveOrganizationMembership ¶ added in v0.0.12
func (*DB) RemoveTeamMembership ¶ added in v0.0.12
func (*DB) SetCurrentRun ¶ added in v0.0.12
SetCurrentRun sets the ID of the current run for the specified workspace.
func (*DB) SetLockFile ¶ added in v0.0.12
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
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) 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) UpdateWorkspace ¶ added in v0.0.12
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
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
PubSub implements a distributed 'pub-sub' service for events, using postgres as a central broker
func (*PubSub) Publish ¶ added in v0.0.12
Publish sends an event to subscribers, via postgres to subscribers on other machines, and via the local broker to subscribers within the same process.