Documentation
¶
Overview ¶
Package app implements services, co-ordinating between the layers of the project.
Index ¶
- type Application
- func (a *Application) ApplyRun(ctx context.Context, runID string, opts otf.RunApplyOptions) error
- func (a *Application) CancelRun(ctx context.Context, runID string, opts otf.RunCancelOptions) error
- func (a *Application) CreateAgentToken(ctx context.Context, opts otf.AgentTokenCreateOptions) (*otf.AgentToken, error)
- func (a *Application) CreateConfigurationVersion(ctx context.Context, workspaceID string, ...) (*otf.ConfigurationVersion, error)
- func (a *Application) CreateOrganization(ctx context.Context, opts otf.OrganizationCreateOptions) (*otf.Organization, error)
- func (a *Application) CreateRun(ctx context.Context, spec otf.WorkspaceSpec, opts otf.RunCreateOptions) (*otf.Run, error)
- func (a *Application) CreateSession(ctx context.Context, userID, address string) (*otf.Session, error)
- func (a *Application) CreateStateVersion(ctx context.Context, workspaceID string, opts otf.StateVersionCreateOptions) (*otf.StateVersion, error)
- func (a *Application) CreateTeam(ctx context.Context, name, organization string) (*otf.Team, error)
- func (a *Application) CreateToken(ctx context.Context, userID string, opts *otf.TokenCreateOptions) (*otf.Token, error)
- func (a *Application) CreateUser(ctx context.Context, username string) (*otf.User, error)
- func (a *Application) CreateWorkspace(ctx context.Context, opts otf.WorkspaceCreateOptions) (*otf.Workspace, error)
- func (a *Application) CurrentStateVersion(ctx context.Context, workspaceID string) (*otf.StateVersion, error)
- func (a *Application) DeleteAgentToken(ctx context.Context, id string, organizationName string) error
- func (a *Application) DeleteOrganization(ctx context.Context, name string) error
- func (a *Application) DeleteRun(ctx context.Context, runID string) error
- func (a *Application) DeleteSession(ctx context.Context, token string) error
- func (a *Application) DeleteToken(ctx context.Context, userID string, tokenID string) error
- func (a *Application) DeleteWorkspace(ctx context.Context, spec otf.WorkspaceSpec) error
- func (a *Application) DiscardRun(ctx context.Context, runID string, opts otf.RunDiscardOptions) error
- func (a *Application) DownloadConfig(ctx context.Context, cvID string) ([]byte, error)
- func (a *Application) DownloadState(ctx context.Context, svID string) ([]byte, error)
- func (a *Application) EnqueuePlan(ctx context.Context, runID string) (*otf.Run, error)
- func (a *Application) EnsureCreatedOrganization(ctx context.Context, opts otf.OrganizationCreateOptions) (*otf.Organization, error)
- func (a *Application) EnsureCreatedTeam(ctx context.Context, name, organization string) (*otf.Team, error)
- func (a *Application) EnsureCreatedUser(ctx context.Context, username string) (*otf.User, error)
- func (a *Application) FinishPhase(ctx context.Context, runID string, phase otf.PhaseType, ...) (*otf.Run, error)
- func (a *Application) ForceCancelRun(ctx context.Context, runID string, opts otf.RunForceCancelOptions) error
- func (a *Application) GetAgentToken(ctx context.Context, token string) (*otf.AgentToken, error)
- func (a *Application) GetChunk(ctx context.Context, opts otf.GetChunkOptions) (otf.Chunk, error)
- func (a *Application) GetConfigurationVersion(ctx context.Context, cvID string) (*otf.ConfigurationVersion, error)
- func (a *Application) GetEntitlements(ctx context.Context, organizationName string) (*otf.Entitlements, error)
- func (a *Application) GetLatestConfigurationVersion(ctx context.Context, workspaceID string) (*otf.ConfigurationVersion, error)
- func (a *Application) GetLockFile(ctx context.Context, runID string) ([]byte, error)
- func (a *Application) GetOrganization(ctx context.Context, name string) (*otf.Organization, error)
- func (a *Application) GetPlanFile(ctx context.Context, runID string, format otf.PlanFormat) ([]byte, error)
- func (a *Application) GetRun(ctx context.Context, runID string) (*otf.Run, error)
- func (a *Application) GetSessionByToken(ctx context.Context, token string) (*otf.Session, error)
- func (a *Application) GetStateVersion(ctx context.Context, svID string) (*otf.StateVersion, error)
- func (a *Application) GetTeam(ctx context.Context, name, organization string) (*otf.Team, error)
- func (a *Application) GetUser(ctx context.Context, spec otf.UserSpec) (*otf.User, error)
- func (a *Application) GetWorkspace(ctx context.Context, spec otf.WorkspaceSpec) (*otf.Workspace, error)
- func (a *Application) ListAgentTokens(ctx context.Context, organizationName string) ([]*otf.AgentToken, error)
- func (a *Application) ListConfigurationVersions(ctx context.Context, workspaceID string, ...) (*otf.ConfigurationVersionList, error)
- func (a *Application) ListOrganizations(ctx context.Context, opts otf.OrganizationListOptions) (*otf.OrganizationList, error)
- func (a *Application) ListRuns(ctx context.Context, opts otf.RunListOptions) (*otf.RunList, error)
- func (a *Application) ListSessions(ctx context.Context, userID string) ([]*otf.Session, error)
- func (a *Application) ListStateVersions(ctx context.Context, opts otf.StateVersionListOptions) (*otf.StateVersionList, error)
- func (a *Application) ListTeams(ctx context.Context, organization string) ([]*otf.Team, error)
- func (a *Application) ListTokens(ctx context.Context, userID string) ([]*otf.Token, error)
- func (a *Application) ListUsers(ctx context.Context, opts otf.UserListOptions) ([]*otf.User, error)
- func (a *Application) ListWorkspacePermissions(ctx context.Context, spec otf.WorkspaceSpec) ([]*otf.WorkspacePermission, error)
- func (a *Application) ListWorkspaces(ctx context.Context, opts otf.WorkspaceListOptions) (*otf.WorkspaceList, error)
- func (a *Application) LockWorkspace(ctx context.Context, spec otf.WorkspaceSpec, opts otf.WorkspaceLockOptions) (*otf.Workspace, error)
- func (a *Application) PutChunk(ctx context.Context, chunk otf.Chunk) error
- func (a *Application) SetCurrentRun(ctx context.Context, workspaceID, runID string) error
- func (a *Application) SetWorkspacePermission(ctx context.Context, spec otf.WorkspaceSpec, team string, ...) error
- func (a *Application) StartPhase(ctx context.Context, runID string, phase otf.PhaseType, ...) (*otf.Run, error)
- func (a *Application) SyncUserMemberships(ctx context.Context, user *otf.User, orgs []*otf.Organization, ...) (*otf.User, error)
- func (a *Application) Tail(ctx context.Context, opts otf.GetChunkOptions) (<-chan otf.Chunk, error)
- func (a *Application) Tx(ctx context.Context, tx func(a *Application) error) error
- func (a *Application) UnlockWorkspace(ctx context.Context, spec otf.WorkspaceSpec, opts otf.WorkspaceUnlockOptions) (*otf.Workspace, error)
- func (a *Application) UnsetWorkspacePermission(ctx context.Context, spec otf.WorkspaceSpec, team string) error
- func (a *Application) UpdateOrganization(ctx context.Context, name string, opts *otf.OrganizationUpdateOptions) (*otf.Organization, error)
- func (a *Application) UpdateTeam(ctx context.Context, name, organization string, opts otf.TeamUpdateOptions) (*otf.Team, error)
- func (a *Application) UpdateWorkspace(ctx context.Context, spec otf.WorkspaceSpec, opts otf.WorkspaceUpdateOptions) (*otf.Workspace, error)
- func (a *Application) UploadConfig(ctx context.Context, cvID string, config []byte) error
- func (a *Application) UploadLockFile(ctx context.Context, runID string, plan []byte) error
- func (a *Application) UploadPlanFile(ctx context.Context, runID string, plan []byte, format otf.PlanFormat) error
- func (a *Application) Watch(ctx context.Context, opts otf.WatchOptions) (<-chan otf.Event, error)
- func (a *Application) WatchLogs(ctx context.Context, opts otf.WatchLogsOptions) (<-chan otf.Chunk, error)
- func (a *Application) WithLock(ctx context.Context, id int64, cb func(otf.Application) error) error
- type Authorizer
- type Mapper
- type WorkspaceResource
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Application ¶ added in v0.0.12
type Application struct { *otf.RunFactory *otf.WorkspaceFactory Mapper otf.PubSubService logr.Logger Authorizer // contains filtered or unexported fields }
Application encompasses services for interacting between components of the otf server
func NewApplication ¶ added in v0.0.12
func NewApplication(ctx context.Context, logger logr.Logger, db otf.DB, cache *bigcache.BigCache, pubsub otf.PubSubService) (*Application, error)
NewApplication constructs an application, initialising various services and daemons.
func (*Application) ApplyRun ¶ added in v0.0.12
func (a *Application) ApplyRun(ctx context.Context, runID string, opts otf.RunApplyOptions) error
ApplyRun enqueues an apply for the run.
func (*Application) CancelRun ¶ added in v0.0.12
func (a *Application) CancelRun(ctx context.Context, runID string, opts otf.RunCancelOptions) error
CancelRun a run. If a run is in progress then a cancelation signal will be sent out.
func (*Application) CreateAgentToken ¶ added in v0.0.12
func (a *Application) CreateAgentToken(ctx context.Context, opts otf.AgentTokenCreateOptions) (*otf.AgentToken, error)
func (*Application) CreateConfigurationVersion ¶ added in v0.0.12
func (a *Application) CreateConfigurationVersion(ctx context.Context, workspaceID string, opts otf.ConfigurationVersionCreateOptions) (*otf.ConfigurationVersion, error)
func (*Application) CreateOrganization ¶ added in v0.0.12
func (a *Application) CreateOrganization(ctx context.Context, opts otf.OrganizationCreateOptions) (*otf.Organization, error)
CreateOrganization creates an organization. Needs admin permission.
func (*Application) CreateRun ¶ added in v0.0.12
func (a *Application) CreateRun(ctx context.Context, spec otf.WorkspaceSpec, opts otf.RunCreateOptions) (*otf.Run, error)
CreateRun constructs and persists a new run object to the db, before scheduling the run.
func (*Application) CreateSession ¶ added in v0.0.12
func (a *Application) CreateSession(ctx context.Context, userID, address string) (*otf.Session, error)
CreateSession creates and persists a user session.
func (*Application) CreateStateVersion ¶ added in v0.0.12
func (a *Application) CreateStateVersion(ctx context.Context, workspaceID string, opts otf.StateVersionCreateOptions) (*otf.StateVersion, error)
func (*Application) CreateTeam ¶ added in v0.0.12
func (*Application) CreateToken ¶ added in v0.0.12
func (a *Application) CreateToken(ctx context.Context, userID string, opts *otf.TokenCreateOptions) (*otf.Token, error)
CreateToken creates a user token. Only users can create a user token, and they can only create a token for themselves.
func (*Application) CreateUser ¶ added in v0.0.12
func (*Application) CreateWorkspace ¶ added in v0.0.12
func (a *Application) CreateWorkspace(ctx context.Context, opts otf.WorkspaceCreateOptions) (*otf.Workspace, error)
func (*Application) CurrentStateVersion ¶ added in v0.0.12
func (a *Application) CurrentStateVersion(ctx context.Context, workspaceID string) (*otf.StateVersion, error)
func (*Application) DeleteAgentToken ¶ added in v0.0.12
func (*Application) DeleteOrganization ¶ added in v0.0.12
func (a *Application) DeleteOrganization(ctx context.Context, name string) error
func (*Application) DeleteRun ¶ added in v0.0.12
func (a *Application) DeleteRun(ctx context.Context, runID string) error
DeleteRun deletes a run.
func (*Application) DeleteSession ¶ added in v0.0.12
func (a *Application) DeleteSession(ctx context.Context, token string) error
func (*Application) DeleteToken ¶ added in v0.0.12
func (*Application) DeleteWorkspace ¶ added in v0.0.12
func (a *Application) DeleteWorkspace(ctx context.Context, spec otf.WorkspaceSpec) error
func (*Application) DiscardRun ¶ added in v0.0.12
func (a *Application) DiscardRun(ctx context.Context, runID string, opts otf.RunDiscardOptions) error
DiscardRun the run.
func (*Application) DownloadConfig ¶ added in v0.0.12
func (*Application) DownloadState ¶ added in v0.0.12
DownloadState retrieves base64-encoded terraform state from the db
func (*Application) EnqueuePlan ¶ added in v0.0.12
EnqueuePlan enqueues a plan for the run.
NOTE: this is an internal action, invoked by the scheduler.
func (*Application) EnsureCreatedOrganization ¶ added in v0.0.12
func (a *Application) EnsureCreatedOrganization(ctx context.Context, opts otf.OrganizationCreateOptions) (*otf.Organization, error)
EnsureCreatedOrganization idempotently creates an organization. Needs admin permission.
TODO: merge this into CreatedOrganization and add an option to toggle idempotency
func (*Application) EnsureCreatedTeam ¶ added in v0.0.12
func (a *Application) EnsureCreatedTeam(ctx context.Context, name, organization string) (*otf.Team, error)
EnsureCreatedTeam retrieves the team or creates the team if it doesn't exist.
func (*Application) EnsureCreatedUser ¶ added in v0.0.12
EnsureCreatedUser retrieves the user or creates the user if they don't exist.
func (*Application) FinishPhase ¶ added in v0.0.12
func (a *Application) FinishPhase(ctx context.Context, runID string, phase otf.PhaseType, opts otf.PhaseFinishOptions) (*otf.Run, error)
FinishPhase finishes a phase. Creates a report of changes before updating the status of the run.
func (*Application) ForceCancelRun ¶ added in v0.0.12
func (a *Application) ForceCancelRun(ctx context.Context, runID string, opts otf.RunForceCancelOptions) error
ForceCancelRun forcefully cancels a run.
func (*Application) GetAgentToken ¶ added in v0.0.12
func (a *Application) GetAgentToken(ctx context.Context, token string) (*otf.AgentToken, error)
GetAgentToken retrieves the agent token metadata corresponding to the given token.
func (*Application) GetChunk ¶ added in v0.0.12
func (a *Application) GetChunk(ctx context.Context, opts otf.GetChunkOptions) (otf.Chunk, error)
GetChunk reads a chunk of logs for a phase.
NOTE: unauthenticated - access granted only via signed URL
func (*Application) GetConfigurationVersion ¶ added in v0.0.12
func (a *Application) GetConfigurationVersion(ctx context.Context, cvID string) (*otf.ConfigurationVersion, error)
func (*Application) GetEntitlements ¶ added in v0.0.12
func (a *Application) GetEntitlements(ctx context.Context, organizationName string) (*otf.Entitlements, error)
func (*Application) GetLatestConfigurationVersion ¶ added in v0.0.12
func (a *Application) GetLatestConfigurationVersion(ctx context.Context, workspaceID string) (*otf.ConfigurationVersion, error)
func (*Application) GetLockFile ¶ added in v0.0.12
GetLockFile returns the lock file for the run.
func (*Application) GetOrganization ¶ added in v0.0.12
func (a *Application) GetOrganization(ctx context.Context, name string) (*otf.Organization, error)
GetOrganization retrieves an organization by name.
func (*Application) GetPlanFile ¶ added in v0.0.12
func (a *Application) GetPlanFile(ctx context.Context, runID string, format otf.PlanFormat) ([]byte, error)
GetPlanFile returns the plan file for the run.
func (*Application) GetSessionByToken ¶ added in v0.0.12
func (*Application) GetStateVersion ¶ added in v0.0.12
func (a *Application) GetStateVersion(ctx context.Context, svID string) (*otf.StateVersion, error)
func (*Application) GetTeam ¶ added in v0.0.12
GetTeam retrieves a team in an organization. If the caller is an unprivileged user i.e. not an owner nor a site admin then they are only permitted to retrieve a team they are a member of.
func (*Application) GetWorkspace ¶ added in v0.0.12
func (a *Application) GetWorkspace(ctx context.Context, spec otf.WorkspaceSpec) (*otf.Workspace, error)
func (*Application) ListAgentTokens ¶ added in v0.0.12
func (a *Application) ListAgentTokens(ctx context.Context, organizationName string) ([]*otf.AgentToken, error)
func (*Application) ListConfigurationVersions ¶ added in v0.0.12
func (a *Application) ListConfigurationVersions(ctx context.Context, workspaceID string, opts otf.ConfigurationVersionListOptions) (*otf.ConfigurationVersionList, error)
func (*Application) ListOrganizations ¶ added in v0.0.12
func (a *Application) ListOrganizations(ctx context.Context, opts otf.OrganizationListOptions) (*otf.OrganizationList, error)
ListOrganizations lists organizations. If the caller is a normal user then only list their organizations; otherwise list all.
func (*Application) ListRuns ¶ added in v0.0.12
func (a *Application) ListRuns(ctx context.Context, opts otf.RunListOptions) (*otf.RunList, error)
ListRuns retrieves multiple run objs. Use opts to filter and paginate the list.
func (*Application) ListSessions ¶ added in v0.0.12
func (*Application) ListStateVersions ¶ added in v0.0.12
func (a *Application) ListStateVersions(ctx context.Context, opts otf.StateVersionListOptions) (*otf.StateVersionList, error)
func (*Application) ListTeams ¶ added in v0.0.12
ListTeams lists teams in the organization. If the caller is an unprivileged user i.e. not an owner nor a site admin then only their teams are listed.
func (*Application) ListTokens ¶ added in v0.0.12
func (*Application) ListUsers ¶ added in v0.0.12
func (a *Application) ListUsers(ctx context.Context, opts otf.UserListOptions) ([]*otf.User, error)
ListUsers lists users with various filters.
func (*Application) ListWorkspacePermissions ¶ added in v0.0.12
func (a *Application) ListWorkspacePermissions(ctx context.Context, spec otf.WorkspaceSpec) ([]*otf.WorkspacePermission, error)
func (*Application) ListWorkspaces ¶ added in v0.0.12
func (a *Application) ListWorkspaces(ctx context.Context, opts otf.WorkspaceListOptions) (*otf.WorkspaceList, error)
func (*Application) LockWorkspace ¶ added in v0.0.12
func (a *Application) LockWorkspace(ctx context.Context, spec otf.WorkspaceSpec, opts otf.WorkspaceLockOptions) (*otf.Workspace, error)
func (*Application) SetCurrentRun ¶ added in v0.0.12
func (a *Application) SetCurrentRun(ctx context.Context, workspaceID, runID string) error
SetCurrentRun sets the current run for the workspace
func (*Application) SetWorkspacePermission ¶ added in v0.0.12
func (a *Application) SetWorkspacePermission(ctx context.Context, spec otf.WorkspaceSpec, team string, role otf.WorkspaceRole) error
func (*Application) StartPhase ¶ added in v0.0.12
func (a *Application) StartPhase(ctx context.Context, runID string, phase otf.PhaseType, _ otf.PhaseStartOptions) (*otf.Run, error)
StartPhase starts a run phase.
func (*Application) SyncUserMemberships ¶ added in v0.0.12
func (*Application) Tail ¶ added in v0.0.12
func (a *Application) Tail(ctx context.Context, opts otf.GetChunkOptions) (<-chan otf.Chunk, error)
Tail logs for a phase. Offset specifies the number of bytes into the logs from which to start tailing.
func (*Application) Tx ¶ added in v0.0.12
func (a *Application) Tx(ctx context.Context, tx func(a *Application) error) error
Tx provides a callback in which all db interactions are wrapped within a transaction. Useful for ensuring multiple service calls succeed together.
func (*Application) UnlockWorkspace ¶ added in v0.0.12
func (a *Application) UnlockWorkspace(ctx context.Context, spec otf.WorkspaceSpec, opts otf.WorkspaceUnlockOptions) (*otf.Workspace, error)
func (*Application) UnsetWorkspacePermission ¶ added in v0.0.12
func (a *Application) UnsetWorkspacePermission(ctx context.Context, spec otf.WorkspaceSpec, team string) error
func (*Application) UpdateOrganization ¶ added in v0.0.12
func (a *Application) UpdateOrganization(ctx context.Context, name string, opts *otf.OrganizationUpdateOptions) (*otf.Organization, error)
func (*Application) UpdateTeam ¶ added in v0.0.12
func (a *Application) UpdateTeam(ctx context.Context, name, organization string, opts otf.TeamUpdateOptions) (*otf.Team, error)
func (*Application) UpdateWorkspace ¶ added in v0.0.12
func (a *Application) UpdateWorkspace(ctx context.Context, spec otf.WorkspaceSpec, opts otf.WorkspaceUpdateOptions) (*otf.Workspace, error)
func (*Application) UploadConfig ¶ added in v0.0.12
UploadConfig saves a configuration tarball to the db
NOTE: unauthenticated - access granted only via signed URL
func (*Application) UploadLockFile ¶ added in v0.0.12
UploadLockFile persists the lock file for a run.
func (*Application) UploadPlanFile ¶ added in v0.0.12
func (a *Application) UploadPlanFile(ctx context.Context, runID string, plan []byte, format otf.PlanFormat) error
UploadPlanFile persists a run's plan file. The plan format should be either be binary or json.
func (*Application) Watch ¶ added in v0.0.12
func (a *Application) Watch(ctx context.Context, opts otf.WatchOptions) (<-chan otf.Event, error)
Watch provides authenticated access to a stream of events.
TODO: apply watch options
func (*Application) WatchLogs ¶ added in v0.0.12
func (a *Application) WatchLogs(ctx context.Context, opts otf.WatchLogsOptions) (<-chan otf.Chunk, error)
WatchLogs provides a subscription to phase logs.
NOTE: unauthenticated. External access to this endpoint should only be made via signed URLs.
func (*Application) WithLock ¶ added in v0.0.12
func (a *Application) WithLock(ctx context.Context, id int64, cb func(otf.Application) error) error
WithLock provides a callback in which the application's database connection possesses a lock with the given ID, with the guarantee that that lock is exclusive, i.e. no other connection has a lock with the same ID. If a lock with the given ID is already present then this method will block until it is released.
type Authorizer ¶ added in v0.0.12
type Authorizer interface { CanAccessSite(ctx context.Context, action otf.Action) (otf.Subject, error) CanAccessOrganization(ctx context.Context, action otf.Action, name string) (otf.Subject, error) CanAccessWorkspace(ctx context.Context, action otf.Action, spec otf.WorkspaceSpec) (otf.Subject, error) CanAccessWorkspaceByID(ctx context.Context, action otf.Action, workspaceID string) (otf.Subject, error) CanAccessRun(ctx context.Context, action otf.Action, runID string) (otf.Subject, error) CanAccessStateVersion(ctx context.Context, action otf.Action, svID string) (otf.Subject, error) CanAccessConfigurationVersion(ctx context.Context, action otf.Action, cvID string) (otf.Subject, error) }
Authorizer is capable of granting or denying access to resources based on the subject contained within the context.
type Mapper ¶ added in v0.0.12
type Mapper interface { Start(context.Context) error LookupWorkspaceID(spec otf.WorkspaceSpec) string }
Mapper maintains mappings between various resource identifiers, which are used by upstream layers to make decisions and efficiently lookup resources.
type WorkspaceResource ¶ added in v0.0.12
WorkspaceResource is a resource that belongs to a workspace and organization, or is a workspace