persistence

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2023 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package persistence provides an implementation of datalayer.go DataLayer interface. This particular implementation is for Postgres and uses the models in pkg/models/models.go. The migrations are in migrations/[0-9]_create_acyl_models_up.sql.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSONTime added in v0.7.5

func JSONTime(t time.Time) string

func PGClient

func PGClient(config *config.PGConfig) (*sqlx.DB, error)

PGClient returns a Postgres DB client.

Types

type APIKeyDataLayer added in v0.8.0

type APIKeyDataLayer interface {
	CreateAPIKey(ctx context.Context, permissionLevel models.PermissionLevel, description, githubUser string) (uuid.UUID, error)
	GetAPIKeyByToken(ctx context.Context, token uuid.UUID) (*models.APIKey, error)
	GetAPIKeyByID(ctx context.Context, id uuid.UUID) (*models.APIKey, error)
	GetAPIKeysByGithubUser(ctx context.Context, githubUser string) ([]*models.APIKey, error)
	UpdateAPIKeyLastUsed(ctx context.Context, token uuid.UUID) error
	DeleteAPIKeyByID(ctx context.Context, id uuid.UUID) error
}

type Cleaner

type Cleaner struct {
	// DB must be an initialized SQL client
	DB *sqlx.DB
	// Maximum ages for old DB records
	DestroyedEnvRecordsMaxAge, EventLogsMaxAge time.Duration
	// LogFunc is a function that logs a formatted string somewhere
	LogFunc func(string, ...interface{})
}

Cleaner is an object that performs data model clean up operations

func (*Cleaner) Clean

func (c *Cleaner) Clean()

Clean runs all data cleanup operations

func (*Cleaner) PruneDestroyedEnvRecords

func (c *Cleaner) PruneDestroyedEnvRecords(olderThan time.Duration) (err error)

PruneDestroyedEnvRecords deletes all QAEnvironment records with status Destroyed or Failed with a Created timestamp earlier than time.Now() - olderThan. olderThan must be > 0

func (*Cleaner) PruneEventLogs

func (c *Cleaner) PruneEventLogs(olderThan time.Duration) error

PruneEventLogs deletes all EventLog records with a Created timestamp earlier than time.Now() - olderThan. olderThan must be > 0

type DataLayer

type DataLayer interface {
	CreateQAEnvironment(context.Context, *QAEnvironment) error
	GetQAEnvironment(context.Context, string) (*QAEnvironment, error)
	GetQAEnvironmentConsistently(context.Context, string) (*QAEnvironment, error)
	GetQAEnvironments(context.Context) ([]QAEnvironment, error)
	DeleteQAEnvironment(context.Context, string) error
	RenameQAEnvironment(ctx context.Context, id int64, newName string) error
	GetQAEnvironmentsByStatus(ctx context.Context, status string) ([]QAEnvironment, error)
	GetRunningQAEnvironments(context.Context) ([]QAEnvironment, error)
	GetQAEnvironmentsByRepoAndPR(context.Context, string, uint) ([]QAEnvironment, error)
	GetQAEnvironmentsByRepo(ctx context.Context, repo string) ([]QAEnvironment, error)
	GetQAEnvironmentBySourceSHA(ctx context.Context, sourceSHA string) (*QAEnvironment, error)
	GetQAEnvironmentsBySourceBranch(ctx context.Context, sourceBranch string) ([]QAEnvironment, error)
	GetQAEnvironmentsByUser(ctx context.Context, user string) ([]QAEnvironment, error)
	SetQAEnvironmentStatus(context.Context, string, EnvironmentStatus) error
	SetQAEnvironmentRepoData(context.Context, string, *RepoRevisionData) error
	SetQAEnvironmentRefMap(context.Context, string, RefMap) error
	SetQAEnvironmentCommitSHAMap(context.Context, string, RefMap) error
	SetQAEnvironmentCreated(context.Context, string, time.Time) error
	GetExtantQAEnvironments(context.Context, string, uint) ([]QAEnvironment, error)
	SetAminoEnvironmentID(ctx context.Context, name string, did int) error
	SetAminoServiceToPort(ctx context.Context, name string, serviceToPort map[string]int64) error
	SetAminoKubernetesNamespace(ctx context.Context, name, namespace string) error
	AddEvent(context.Context, string, string) error
	Search(ctx context.Context, opts models.EnvSearchParameters) ([]QAEnvironment, error)
	SearchEnvsForUser(ctx context.Context, user string, opts models.EnvSearchParameters) ([]QAEnvironment, error)
	GetMostRecent(ctx context.Context, n uint) ([]QAEnvironment, error)
	GetMostRecentForUser(ctx context.Context, user string, n uint) ([]QAEnvironment, error)
	Close() error
	HelmDataLayer
	K8sEnvDataLayer
	EventLoggerDataLayer
	UISessionsDataLayer
	APIKeyDataLayer
}

DataLayer describes an object that interacts with the persistant data store

type EnvironmentStatus

type EnvironmentStatus = models.EnvironmentStatus

type EventLoggerDataLayer

type EventLoggerDataLayer interface {
	GetEventLogByID(id uuid.UUID) (*models.EventLog, error)
	GetEventLogByDeliveryID(deliveryID uuid.UUID) (*models.EventLog, error)
	GetEventLogsByEnvName(name string) ([]models.EventLog, error)
	GetEventLogsByRepoAndPR(repo string, pr uint) ([]models.EventLog, error)
	CreateEventLog(elog *models.EventLog) error
	SetEventLogEnvName(id uuid.UUID, name string) error
	AppendToEventLog(id uuid.UUID, msg string) error
	DeleteEventLog(id uuid.UUID) error
	DeleteEventLogsByEnvName(name string) (uint, error)
	DeleteEventLogsByRepoAndPR(repo string, pr uint) (uint, error)
	SetEventStatus(id uuid.UUID, status models.EventStatusSummary) error
	SetEventStatusConfig(id uuid.UUID, processingTime time.Duration, refmap map[string]string) error
	SetEventStatusConfigK8sNS(id uuid.UUID, ns string) error
	SetEventStatusTree(id uuid.UUID, tree map[string]models.EventStatusTreeNode) error
	SetEventStatusCompleted(id uuid.UUID, configStatus models.EventStatus) error
	SetEventStatusImageStarted(id uuid.UUID, name string) error
	SetEventStatusImageBuildID(id uuid.UUID, name string, furanBuildID guuid.UUID) error
	SetEventStatusImageCompleted(id uuid.UUID, name string, err bool) error
	SetEventStatusChartStarted(id uuid.UUID, name string, status models.NodeChartStatus) error
	SetEventStatusChartCompleted(id uuid.UUID, name string, status models.NodeChartStatus) error
	GetEventStatus(id uuid.UUID) (*models.EventStatusSummary, error)
	SetEventStatusRenderedStatus(id uuid.UUID, rstatus models.RenderedEventStatus) error
	SetEventStatusFailed(id uuid.UUID, ce metahelmlib.ChartError) error
}

EventLoggerDataLayer desribes an object that stores event log data

type FakeDataLayer

type FakeDataLayer struct {
	CreateMissingEventLog bool
	// contains filtered or unexported fields
}

FakeDataLayer is a fake implementation of DataLayer that persists data in-memory, for testing purposes

func NewDelayedFakeDataLayer added in v0.7.0

func NewDelayedFakeDataLayer(delay time.Duration) *FakeDataLayer

func NewFakeDataLayer

func NewFakeDataLayer() *FakeDataLayer

func NewPopulatedFakeDataLayer

func NewPopulatedFakeDataLayer(qaenvs []models.QAEnvironment, k8senvs []models.KubernetesEnvironment, helmreleases []models.HelmRelease, apikeys []models.APIKey) *FakeDataLayer

NewPopulatedFakeDataLayer returns a FakeDataLayer populated with the supplied data. Input data is not checked for consistency.

func (*FakeDataLayer) AddEvent

func (fdl *FakeDataLayer) AddEvent(ctx context.Context, name string, msg string) error

func (*FakeDataLayer) AppendToEventLog

func (fdl *FakeDataLayer) AppendToEventLog(id uuid.UUID, msg string) error

func (*FakeDataLayer) Close

func (fdl *FakeDataLayer) Close() error

func (*FakeDataLayer) CreateAPIKey added in v0.8.0

func (fdl *FakeDataLayer) CreateAPIKey(ctx context.Context, permissionLevel models.PermissionLevel, description, githubUser string) (uuid.UUID, error)

func (*FakeDataLayer) CreateEventLog

func (fdl *FakeDataLayer) CreateEventLog(elog *models.EventLog) error

func (*FakeDataLayer) CreateHelmReleasesForEnv

func (fdl *FakeDataLayer) CreateHelmReleasesForEnv(ctx context.Context, releases []models.HelmRelease) error

func (*FakeDataLayer) CreateK8sEnv

func (fdl *FakeDataLayer) CreateK8sEnv(ctx context.Context, env *models.KubernetesEnvironment) error

func (*FakeDataLayer) CreateQAEnvironment

func (fdl *FakeDataLayer) CreateQAEnvironment(ctx context.Context, qa *QAEnvironment) error

func (*FakeDataLayer) CreateUISession added in v0.7.6

func (fdl *FakeDataLayer) CreateUISession(targetRoute string, state []byte, clientIP net.IP, userAgent string, expires time.Time) (int, error)

func (*FakeDataLayer) DeleteAPIKeyByID added in v0.9.2

func (fdl *FakeDataLayer) DeleteAPIKeyByID(ctx context.Context, id uuid.UUID) error

func (*FakeDataLayer) DeleteEventLog

func (fdl *FakeDataLayer) DeleteEventLog(id uuid.UUID) error

func (*FakeDataLayer) DeleteEventLogsByEnvName

func (fdl *FakeDataLayer) DeleteEventLogsByEnvName(name string) (uint, error)

func (*FakeDataLayer) DeleteEventLogsByRepoAndPR

func (fdl *FakeDataLayer) DeleteEventLogsByRepoAndPR(repo string, pr uint) (uint, error)

func (*FakeDataLayer) DeleteExpiredUISessions added in v0.7.6

func (fdl *FakeDataLayer) DeleteExpiredUISessions() (uint, error)

func (*FakeDataLayer) DeleteHelmReleasesForEnv

func (fdl *FakeDataLayer) DeleteHelmReleasesForEnv(ctx context.Context, name string) (uint, error)

func (*FakeDataLayer) DeleteK8sEnv

func (fdl *FakeDataLayer) DeleteK8sEnv(ctx context.Context, name string) error

func (*FakeDataLayer) DeleteQAEnvironment

func (fdl *FakeDataLayer) DeleteQAEnvironment(ctx context.Context, name string) error

func (*FakeDataLayer) DeleteUISession added in v0.7.6

func (fdl *FakeDataLayer) DeleteUISession(id int) error

func (*FakeDataLayer) GetAPIKeyByID added in v0.9.2

func (fdl *FakeDataLayer) GetAPIKeyByID(ctx context.Context, id uuid.UUID) (*models.APIKey, error)

func (*FakeDataLayer) GetAPIKeyByToken added in v0.9.2

func (fdl *FakeDataLayer) GetAPIKeyByToken(ctx context.Context, token uuid.UUID) (*models.APIKey, error)

func (*FakeDataLayer) GetAPIKeysByGithubUser added in v0.8.0

func (fdl *FakeDataLayer) GetAPIKeysByGithubUser(ctx context.Context, githubUser string) ([]*models.APIKey, error)

func (*FakeDataLayer) GetEventLogByDeliveryID added in v0.7.6

func (fdl *FakeDataLayer) GetEventLogByDeliveryID(deliveryID uuid.UUID) (*models.EventLog, error)

func (*FakeDataLayer) GetEventLogByID

func (fdl *FakeDataLayer) GetEventLogByID(id uuid.UUID) (*models.EventLog, error)

func (*FakeDataLayer) GetEventLogsByEnvName

func (fdl *FakeDataLayer) GetEventLogsByEnvName(name string) ([]models.EventLog, error)

func (*FakeDataLayer) GetEventLogsByRepoAndPR

func (fdl *FakeDataLayer) GetEventLogsByRepoAndPR(repo string, pr uint) ([]models.EventLog, error)

func (*FakeDataLayer) GetEventStatus added in v0.7.5

func (fdl *FakeDataLayer) GetEventStatus(id uuid.UUID) (*models.EventStatusSummary, error)

func (*FakeDataLayer) GetExtantQAEnvironments

func (fdl *FakeDataLayer) GetExtantQAEnvironments(ctx context.Context, repo string, pr uint) ([]QAEnvironment, error)

func (*FakeDataLayer) GetHelmReleasesForEnv

func (fdl *FakeDataLayer) GetHelmReleasesForEnv(ctx context.Context, name string) ([]models.HelmRelease, error)

func (*FakeDataLayer) GetK8sEnv

func (fdl *FakeDataLayer) GetK8sEnv(ctx context.Context, name string) (*models.KubernetesEnvironment, error)

func (*FakeDataLayer) GetK8sEnvsByNamespace

func (fdl *FakeDataLayer) GetK8sEnvsByNamespace(ctx context.Context, ns string) ([]models.KubernetesEnvironment, error)

func (*FakeDataLayer) GetMostRecent

func (fdl *FakeDataLayer) GetMostRecent(ctx context.Context, n uint) ([]QAEnvironment, error)

func (*FakeDataLayer) GetMostRecentForUser added in v0.9.2

func (fdl *FakeDataLayer) GetMostRecentForUser(ctx context.Context, user string, n uint) ([]QAEnvironment, error)

func (*FakeDataLayer) GetQAEnvironment

func (fdl *FakeDataLayer) GetQAEnvironment(ctx context.Context, name string) (*QAEnvironment, error)

func (*FakeDataLayer) GetQAEnvironmentBySourceSHA

func (fdl *FakeDataLayer) GetQAEnvironmentBySourceSHA(ctx context.Context, sourceSHA string) (*QAEnvironment, error)

func (*FakeDataLayer) GetQAEnvironmentConsistently

func (fdl *FakeDataLayer) GetQAEnvironmentConsistently(ctx context.Context, name string) (*QAEnvironment, error)

func (*FakeDataLayer) GetQAEnvironments

func (fdl *FakeDataLayer) GetQAEnvironments(ctx context.Context) ([]QAEnvironment, error)

func (*FakeDataLayer) GetQAEnvironmentsByRepo

func (fdl *FakeDataLayer) GetQAEnvironmentsByRepo(ctx context.Context, repo string) ([]QAEnvironment, error)

func (*FakeDataLayer) GetQAEnvironmentsByRepoAndPR

func (fdl *FakeDataLayer) GetQAEnvironmentsByRepoAndPR(ctx context.Context, repo string, pr uint) ([]QAEnvironment, error)

func (*FakeDataLayer) GetQAEnvironmentsBySourceBranch

func (fdl *FakeDataLayer) GetQAEnvironmentsBySourceBranch(ctx context.Context, sourceBranch string) ([]QAEnvironment, error)

func (*FakeDataLayer) GetQAEnvironmentsByStatus

func (fdl *FakeDataLayer) GetQAEnvironmentsByStatus(ctx context.Context, status string) ([]QAEnvironment, error)

func (*FakeDataLayer) GetQAEnvironmentsByUser

func (fdl *FakeDataLayer) GetQAEnvironmentsByUser(ctx context.Context, user string) ([]QAEnvironment, error)

func (*FakeDataLayer) GetRunningQAEnvironments

func (fdl *FakeDataLayer) GetRunningQAEnvironments(ctx context.Context) ([]QAEnvironment, error)

func (*FakeDataLayer) GetUISession added in v0.7.6

func (fdl *FakeDataLayer) GetUISession(id int) (*models.UISession, error)

func (*FakeDataLayer) Load

func (fdl *FakeDataLayer) Load(dir string) error

Load reads JSON files in dir and loads them, overwriting any existing data

func (*FakeDataLayer) NewFakeCreateEvent added in v0.7.6

func (fdl *FakeDataLayer) NewFakeCreateEvent(started time.Time, repo, user, envname string) uuid.UUID

func (*FakeDataLayer) NewFakeEvent added in v0.7.6

func (fdl *FakeDataLayer) NewFakeEvent(started time.Time, repo, user, envname string, etype models.EventStatusType, success bool) uuid.UUID

func (*FakeDataLayer) RenameQAEnvironment added in v0.9.2

func (fdl *FakeDataLayer) RenameQAEnvironment(ctx context.Context, id int64, newName string) error

func (*FakeDataLayer) Save

func (fdl *FakeDataLayer) Save(dir string) ([]string, error)

Save writes all data to files in dir and returns the filenames, or error

func (*FakeDataLayer) Search

func (*FakeDataLayer) SearchEnvsForUser added in v0.9.2

func (fdl *FakeDataLayer) SearchEnvsForUser(ctx context.Context, user string, opts models.EnvSearchParameters) ([]QAEnvironment, error)

func (*FakeDataLayer) SetAminoEnvironmentID

func (fdl *FakeDataLayer) SetAminoEnvironmentID(ctx context.Context, name string, did int) error

func (*FakeDataLayer) SetAminoKubernetesNamespace

func (fdl *FakeDataLayer) SetAminoKubernetesNamespace(ctx context.Context, name, namespace string) error

func (*FakeDataLayer) SetAminoServiceToPort

func (fdl *FakeDataLayer) SetAminoServiceToPort(ctx context.Context, name string, serviceToPort map[string]int64) error

func (*FakeDataLayer) SetDelay added in v0.7.0

func (fdl *FakeDataLayer) SetDelay(d time.Duration)

func (*FakeDataLayer) SetEventLogEnvName

func (fdl *FakeDataLayer) SetEventLogEnvName(id uuid.UUID, name string) error

func (*FakeDataLayer) SetEventStatus added in v0.7.5

func (fdl *FakeDataLayer) SetEventStatus(id uuid.UUID, status models.EventStatusSummary) error

func (*FakeDataLayer) SetEventStatusChartCompleted added in v0.7.5

func (fdl *FakeDataLayer) SetEventStatusChartCompleted(id uuid.UUID, name string, status models.NodeChartStatus) error

func (*FakeDataLayer) SetEventStatusChartStarted added in v0.7.5

func (fdl *FakeDataLayer) SetEventStatusChartStarted(id uuid.UUID, name string, status models.NodeChartStatus) error

func (*FakeDataLayer) SetEventStatusCompleted added in v0.7.5

func (fdl *FakeDataLayer) SetEventStatusCompleted(id uuid.UUID, status models.EventStatus) error

func (*FakeDataLayer) SetEventStatusConfig added in v0.7.5

func (fdl *FakeDataLayer) SetEventStatusConfig(id uuid.UUID, processingTime time.Duration, refmap map[string]string) error

func (*FakeDataLayer) SetEventStatusConfigK8sNS added in v0.7.5

func (fdl *FakeDataLayer) SetEventStatusConfigK8sNS(id uuid.UUID, ns string) error

func (*FakeDataLayer) SetEventStatusFailed added in v0.8.0

func (fdl *FakeDataLayer) SetEventStatusFailed(id uuid.UUID, ce metahelmlib.ChartError) error

func (*FakeDataLayer) SetEventStatusImageBuildID added in v0.9.3

func (fdl *FakeDataLayer) SetEventStatusImageBuildID(id uuid.UUID, name string, furanBuildID guuid.UUID) error

func (*FakeDataLayer) SetEventStatusImageCompleted added in v0.7.5

func (fdl *FakeDataLayer) SetEventStatusImageCompleted(id uuid.UUID, name string, err bool) error

func (*FakeDataLayer) SetEventStatusImageStarted added in v0.7.5

func (fdl *FakeDataLayer) SetEventStatusImageStarted(id uuid.UUID, name string) error

func (*FakeDataLayer) SetEventStatusRenderedStatus added in v0.7.5

func (fdl *FakeDataLayer) SetEventStatusRenderedStatus(id uuid.UUID, rstatus models.RenderedEventStatus) error

func (*FakeDataLayer) SetEventStatusTree added in v0.7.5

func (fdl *FakeDataLayer) SetEventStatusTree(id uuid.UUID, tree map[string]models.EventStatusTreeNode) error

func (*FakeDataLayer) SetQAEnvironmentCommitSHAMap

func (fdl *FakeDataLayer) SetQAEnvironmentCommitSHAMap(ctx context.Context, name string, csm RefMap) error

func (*FakeDataLayer) SetQAEnvironmentCreated

func (fdl *FakeDataLayer) SetQAEnvironmentCreated(ctx context.Context, name string, ts time.Time) error

func (*FakeDataLayer) SetQAEnvironmentRefMap

func (fdl *FakeDataLayer) SetQAEnvironmentRefMap(ctx context.Context, name string, rm RefMap) error

func (*FakeDataLayer) SetQAEnvironmentRepoData

func (fdl *FakeDataLayer) SetQAEnvironmentRepoData(ctx context.Context, name string, rrd *RepoRevisionData) error

func (*FakeDataLayer) SetQAEnvironmentStatus

func (fdl *FakeDataLayer) SetQAEnvironmentStatus(ctx context.Context, name string, status EnvironmentStatus) error

func (*FakeDataLayer) UpdateAPIKeyLastUsed added in v0.8.0

func (fdl *FakeDataLayer) UpdateAPIKeyLastUsed(ctx context.Context, token uuid.UUID) error

func (*FakeDataLayer) UpdateHelmReleaseRevision

func (fdl *FakeDataLayer) UpdateHelmReleaseRevision(ctx context.Context, envname, release, revision string) error

func (*FakeDataLayer) UpdateK8sEnvConfigSignature added in v0.7.6

func (fdl *FakeDataLayer) UpdateK8sEnvConfigSignature(ctx context.Context, name string, confSig [32]byte) error

func (*FakeDataLayer) UpdateUISession added in v0.7.6

func (fdl *FakeDataLayer) UpdateUISession(id int, githubUser string, encryptedtoken []byte, authenticated bool) error

type HelmDataLayer

type HelmDataLayer interface {
	GetHelmReleasesForEnv(ctx context.Context, name string) ([]models.HelmRelease, error)
	UpdateHelmReleaseRevision(ctx context.Context, envname, release, revision string) error
	CreateHelmReleasesForEnv(ctx context.Context, releases []models.HelmRelease) error
	DeleteHelmReleasesForEnv(ctx context.Context, name string) (uint, error)
}

HelmDataLayer describes an object that stores data about Helm

type K8sEnvDataLayer

type K8sEnvDataLayer interface {
	GetK8sEnv(ctx context.Context, name string) (*models.KubernetesEnvironment, error)
	GetK8sEnvsByNamespace(ctx context.Context, ns string) ([]models.KubernetesEnvironment, error)
	CreateK8sEnv(ctx context.Context, env *models.KubernetesEnvironment) error
	DeleteK8sEnv(ctx context.Context, name string) error
	UpdateK8sEnvConfigSignature(ctx context.Context, name string, confSig [32]byte) error
}

K8sEnvDataLayer describes an object that stores data about the K8s environment details

type LogFunc

type LogFunc func(string, ...interface{})

LogFunc is a function that logs a formatted string somewhere

type MetricsCollector

type MetricsCollector = metrics.Collector

type PGLayer

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

PGLayer contains the data layer implementation for a Postgres database.

func NewPGLayer

func NewPGLayer(cfg *config.PGConfig, logger *log.Logger) (*PGLayer, error)

NewPGLayer instantiates a new PGLayer.

func (*PGLayer) AddEvent

func (p *PGLayer) AddEvent(ctx context.Context, name string, msg string) error

AddEvent adds an event a particular QAEnvironment.

func (*PGLayer) AppendToEventLog

func (pg *PGLayer) AppendToEventLog(id uuid.UUID, msg string) error

AppendToEventLog appends a new log line to an EventLog

func (*PGLayer) Close

func (p *PGLayer) Close() error

Close closes the database and any open connections

func (*PGLayer) CreateAPIKey added in v0.8.0

func (pg *PGLayer) CreateAPIKey(ctx context.Context, permissionLevel models.PermissionLevel, description, githubUser string) (uuid.UUID, error)

CreateAPIKey creates a new user api key

func (*PGLayer) CreateEventLog

func (pg *PGLayer) CreateEventLog(elog *models.EventLog) error

CreateEventLog creates a new EventLog. If elog.EnvName is an empty string, null will be persisted in the database for that column.

func (*PGLayer) CreateHelmReleasesForEnv

func (pg *PGLayer) CreateHelmReleasesForEnv(ctx context.Context, releases []models.HelmRelease) error

func (*PGLayer) CreateK8sEnv

func (pg *PGLayer) CreateK8sEnv(ctx context.Context, env *models.KubernetesEnvironment) error

CreateK8sEnv inserts a new k8s environment into the DB

func (*PGLayer) CreateQAEnvironment

func (p *PGLayer) CreateQAEnvironment(ctx context.Context, qae *QAEnvironment) error

CreateQAEnvironment persists a new QA record.

func (*PGLayer) CreateUISession added in v0.7.6

func (pg *PGLayer) CreateUISession(targetRoute string, state []byte, clientIP net.IP, userAgent string, expires time.Time) (int, error)

CreateUISession creates a new unauthenticated UI session and returns the ID

func (*PGLayer) DB

func (p *PGLayer) DB() *sqlx.DB

DB returns the raw sqlx DB client

func (*PGLayer) DeleteAPIKeyByID added in v0.9.2

func (pg *PGLayer) DeleteAPIKeyByID(ctx context.Context, id uuid.UUID) error

DeleteAPIKeyByID unconditionally deletes the api key for the api key record id

func (*PGLayer) DeleteEventLog

func (pg *PGLayer) DeleteEventLog(id uuid.UUID) error

DeleteEventLog deletes an EventLog

func (*PGLayer) DeleteEventLogsByEnvName

func (pg *PGLayer) DeleteEventLogsByEnvName(name string) (uint, error)

DeleteEventLogsByEnvName deletes all EventLogs associated with an environment and returns the number of EventLogs deleted, or error

func (*PGLayer) DeleteEventLogsByRepoAndPR

func (pg *PGLayer) DeleteEventLogsByRepoAndPR(repo string, pr uint) (uint, error)

DeleteEventLogsByRepoAndPR deletes all EventLogs associated with a repo and PR and returns the number of EventLogs deleted, or error

func (*PGLayer) DeleteExpiredUISessions added in v0.7.6

func (pg *PGLayer) DeleteExpiredUISessions() (uint, error)

DeleteExpiredUISessions deletes all expired sessions and returns the number deleted

func (*PGLayer) DeleteHelmReleasesForEnv

func (pg *PGLayer) DeleteHelmReleasesForEnv(ctx context.Context, name string) (uint, error)

func (*PGLayer) DeleteK8sEnv

func (pg *PGLayer) DeleteK8sEnv(ctx context.Context, name string) error

DeleteK8sEnv deletes a k8s environment from the DB

func (*PGLayer) DeleteQAEnvironment

func (p *PGLayer) DeleteQAEnvironment(ctx context.Context, name string) (err error)

DeleteQAEnvironment deletes a QA environment record. The environment must have status Destroyed. Callers must ensure that the underlying k8s environment has been deleted prior to calling this, otherwise potentially orphan k8s resources will be left running.

func (*PGLayer) DeleteUISession added in v0.7.6

func (pg *PGLayer) DeleteUISession(id int) error

DeleteUISession unconditionally deletes the session with ID

func (*PGLayer) GetAPIKeyByID added in v0.9.2

func (pg *PGLayer) GetAPIKeyByID(ctx context.Context, id uuid.UUID) (*models.APIKey, error)

GetAPIKeyByID returns the api key by id, nil if not found

func (*PGLayer) GetAPIKeyByToken added in v0.9.2

func (pg *PGLayer) GetAPIKeyByToken(ctx context.Context, token uuid.UUID) (*models.APIKey, error)

GetAPIKeyByToken returns the api key by token, nil if not found

func (*PGLayer) GetAPIKeysByGithubUser added in v0.8.0

func (pg *PGLayer) GetAPIKeysByGithubUser(ctx context.Context, githubUser string) ([]*models.APIKey, error)

GetAPIKeysByGithubUser returns all api keys for the github user or nil if not found

func (*PGLayer) GetEventLogByDeliveryID added in v0.7.6

func (pg *PGLayer) GetEventLogByDeliveryID(deliveryID uuid.UUID) (*models.EventLog, error)

func (*PGLayer) GetEventLogByID

func (pg *PGLayer) GetEventLogByID(id uuid.UUID) (*models.EventLog, error)

GetEventLogByID returns a single EventLog by id, or nil or error

func (*PGLayer) GetEventLogsByEnvName

func (pg *PGLayer) GetEventLogsByEnvName(name string) ([]models.EventLog, error)

GetEventLogsByEnvName gets all EventLogs associated with an environment

func (*PGLayer) GetEventLogsByRepoAndPR

func (pg *PGLayer) GetEventLogsByRepoAndPR(repo string, pr uint) ([]models.EventLog, error)

GetEventLogsByRepoAndPR gets all EventLogs associated with a repo and PR, sorted in reverse created order (newest first)

func (*PGLayer) GetEventStatus added in v0.7.5

func (pg *PGLayer) GetEventStatus(id uuid.UUID) (*models.EventStatusSummary, error)

func (*PGLayer) GetExtantQAEnvironments

func (p *PGLayer) GetExtantQAEnvironments(ctx context.Context, repo string, pr uint) ([]QAEnvironment, error)

GetExtantQAEnvironments finds any environments for the given repo/PR combination that are not status Destroyed

func (*PGLayer) GetHelmReleasesForEnv

func (pg *PGLayer) GetHelmReleasesForEnv(ctx context.Context, name string) ([]models.HelmRelease, error)

func (*PGLayer) GetK8sEnv

func (pg *PGLayer) GetK8sEnv(ctx context.Context, name string) (*models.KubernetesEnvironment, error)

GetK8sEnv gets a k8s environment by environment name

func (*PGLayer) GetK8sEnvsByNamespace

func (pg *PGLayer) GetK8sEnvsByNamespace(ctx context.Context, ns string) ([]models.KubernetesEnvironment, error)

GetK8sEnvsByNamespace returns any KubernetesEnvironments associated with a specific namespace name

func (*PGLayer) GetMostRecent

func (p *PGLayer) GetMostRecent(ctx context.Context, n uint) ([]QAEnvironment, error)

GetMostRecent finds the most recent environments from the last n days. Recency is defined by created/updated timestamps. The returned slice is in descending order of recency.

func (*PGLayer) GetMostRecentForUser added in v0.9.2

func (p *PGLayer) GetMostRecentForUser(ctx context.Context, user string, n uint) ([]QAEnvironment, error)

GetMostRecent finds the most recent environments for user from the last n days. Recency is defined by created/updated timestamps. The returned slice is in descending order of recency.

func (*PGLayer) GetQAEnvironment

func (p *PGLayer) GetQAEnvironment(ctx context.Context, name string) (*QAEnvironment, error)

GetQAEnvironment finds a QAEnvironment by the name field.

func (*PGLayer) GetQAEnvironmentBySourceSHA

func (p *PGLayer) GetQAEnvironmentBySourceSHA(ctx context.Context, sourceSHA string) (*QAEnvironment, error)

GetQAEnvironmentBySourceSHA returns an environment with a matching sourceSHA.

func (*PGLayer) GetQAEnvironmentConsistently

func (p *PGLayer) GetQAEnvironmentConsistently(ctx context.Context, name string) (*QAEnvironment, error)

GetQAEnvironmentConsistently finds a QAEnvironment by the name field consistently. This is a legacy method from when DynamoDB was used as the datastore.

func (*PGLayer) GetQAEnvironments

func (p *PGLayer) GetQAEnvironments(ctx context.Context) ([]QAEnvironment, error)

GetQAEnvironments returns all QA records

func (*PGLayer) GetQAEnvironmentsByRepo

func (p *PGLayer) GetQAEnvironmentsByRepo(ctx context.Context, repo string) ([]QAEnvironment, error)

GetQAEnvironmentsByRepo returns all environments which have matching repo.

func (*PGLayer) GetQAEnvironmentsByRepoAndPR

func (p *PGLayer) GetQAEnvironmentsByRepoAndPR(ctx context.Context, repo string, pr uint) ([]QAEnvironment, error)

GetQAEnvironmentsByRepoAndPR teturns all environments which have matching repo AND pull request.

func (*PGLayer) GetQAEnvironmentsBySourceBranch

func (p *PGLayer) GetQAEnvironmentsBySourceBranch(ctx context.Context, sourceBranch string) ([]QAEnvironment, error)

GetQAEnvironmentsBySourceBranch returns all environments which have matching sourceBranch.

func (*PGLayer) GetQAEnvironmentsByStatus

func (p *PGLayer) GetQAEnvironmentsByStatus(ctx context.Context, status string) ([]QAEnvironment, error)

GetQAEnvironmentsByStatus gets all environmens matching status. TODO(geoffrey): Revisit raw_status with @benjamen

func (*PGLayer) GetQAEnvironmentsByUser

func (p *PGLayer) GetQAEnvironmentsByUser(ctx context.Context, user string) ([]QAEnvironment, error)

GetQAEnvironmentsByUser retrieve all QAEnvironment by user (User is username in the DB see models/models.go).

func (*PGLayer) GetRunningQAEnvironments

func (p *PGLayer) GetRunningQAEnvironments(ctx context.Context) ([]QAEnvironment, error)

GetRunningQAEnvironments returns all environments with status "success", "updating" or "spawned", in ascending order of creation time.

func (*PGLayer) GetUISession added in v0.7.6

func (pg *PGLayer) GetUISession(id int) (*models.UISession, error)

GetUISession returns the session with id or nil if not found

func (*PGLayer) RenameQAEnvironment added in v0.9.2

func (p *PGLayer) RenameQAEnvironment(ctx context.Context, id int64, newName string) error

RenameQAEnvironment renames environment id to newName consistently along with everything associated with it via foreign keys. newName must be unique or this method will fail. At the application level, the environment *must* be rebuilt immediately following this rename to keep data models and objects consistent!

func (*PGLayer) Search

Search finds environments that satisfy the parameters given. Multiple parameters are combined with implicit AND.

func (*PGLayer) SearchEnvsForUser added in v0.9.2

func (p *PGLayer) SearchEnvsForUser(ctx context.Context, user string, opts models.EnvSearchParameters) ([]QAEnvironment, error)

SearchEnvsForUser finds environments for specified user that satisfy the parameters given. Multiple parameters are combined with implicit AND.

func (*PGLayer) SetAminoEnvironmentID

func (p *PGLayer) SetAminoEnvironmentID(ctx context.Context, name string, did int) error

SetAminoEnvironmentID sets the Amino environment ID for an environment.

func (*PGLayer) SetAminoKubernetesNamespace

func (p *PGLayer) SetAminoKubernetesNamespace(ctx context.Context, name string, namespace string) error

SetAminoKubernetesNamespace sets the Kubernetes namespace for an environment.

func (*PGLayer) SetAminoServiceToPort

func (p *PGLayer) SetAminoServiceToPort(ctx context.Context, name string, serviceToPort map[string]int64) error

SetAminoServiceToPort sets the Amino service port metadata for an environment.

func (*PGLayer) SetEventLogEnvName

func (pg *PGLayer) SetEventLogEnvName(id uuid.UUID, name string) error

SetEventLogEnvName sets the env name for an EventLog The name must be valid and exist in qa_environments or the foreign key will cause this method to return an error

func (*PGLayer) SetEventStatus added in v0.7.5

func (pg *PGLayer) SetEventStatus(id uuid.UUID, status models.EventStatusSummary) error

func (*PGLayer) SetEventStatusChartCompleted added in v0.7.5

func (pg *PGLayer) SetEventStatusChartCompleted(id uuid.UUID, name string, status models.NodeChartStatus) error

func (*PGLayer) SetEventStatusChartStarted added in v0.7.5

func (pg *PGLayer) SetEventStatusChartStarted(id uuid.UUID, name string, status models.NodeChartStatus) error

func (*PGLayer) SetEventStatusCompleted added in v0.7.5

func (pg *PGLayer) SetEventStatusCompleted(id uuid.UUID, configStatus models.EventStatus) error

func (*PGLayer) SetEventStatusConfig added in v0.7.5

func (pg *PGLayer) SetEventStatusConfig(id uuid.UUID, processingTime time.Duration, refmap map[string]string) error

func (*PGLayer) SetEventStatusConfigK8sNS added in v0.7.5

func (pg *PGLayer) SetEventStatusConfigK8sNS(id uuid.UUID, ns string) error

func (*PGLayer) SetEventStatusFailed added in v0.8.0

func (pg *PGLayer) SetEventStatusFailed(id uuid.UUID, ce metahelmlib.ChartError) error

SetEventStatusFailed will set the event status to indicate that it has failed and will persist the ChartError.

func (*PGLayer) SetEventStatusImageBuildID added in v0.9.3

func (pg *PGLayer) SetEventStatusImageBuildID(id uuid.UUID, name string, furanBuildID guuid.UUID) error

func (*PGLayer) SetEventStatusImageCompleted added in v0.7.5

func (pg *PGLayer) SetEventStatusImageCompleted(id uuid.UUID, name string, err bool) error

func (*PGLayer) SetEventStatusImageStarted added in v0.7.5

func (pg *PGLayer) SetEventStatusImageStarted(id uuid.UUID, name string) error

func (*PGLayer) SetEventStatusRenderedStatus added in v0.7.5

func (pg *PGLayer) SetEventStatusRenderedStatus(id uuid.UUID, rstatus models.RenderedEventStatus) error

func (*PGLayer) SetEventStatusTree added in v0.7.5

func (pg *PGLayer) SetEventStatusTree(id uuid.UUID, tree map[string]models.EventStatusTreeNode) error

func (*PGLayer) SetQAEnvironmentCommitSHAMap

func (p *PGLayer) SetQAEnvironmentCommitSHAMap(ctx context.Context, name string, commitSHAMap RefMap) error

SetQAEnvironmentCommitSHAMap sets a specific QAEnvironment's commitSHAMap.

func (*PGLayer) SetQAEnvironmentCreated

func (p *PGLayer) SetQAEnvironmentCreated(ctx context.Context, name string, created time.Time) error

SetQAEnvironmentCreated sets a specific QAEnvironment's created time.

func (*PGLayer) SetQAEnvironmentRefMap

func (p *PGLayer) SetQAEnvironmentRefMap(ctx context.Context, name string, refMap RefMap) error

SetQAEnvironmentRefMap sets a specific QAEnvironment's RefMap.

func (*PGLayer) SetQAEnvironmentRepoData

func (p *PGLayer) SetQAEnvironmentRepoData(ctx context.Context, name string, repo *RepoRevisionData) error

SetQAEnvironmentRepoData sets a specific QAEnvironment's RepoRevisionData.

func (*PGLayer) SetQAEnvironmentStatus

func (p *PGLayer) SetQAEnvironmentStatus(ctx context.Context, name string, status EnvironmentStatus) error

SetQAEnvironmentStatus sets a specific QAEnvironment's status. This method is unique in that callers often call this in cases where a root operation context is likely to be canceled. Because of this, it often makes sense to pass the background context, or a newly created child of the background context, to this function. For convenience, we set a default operation timeout to make sure that even if the caller passed the background context, we can prevent this function from waiting indefinitely.

func (*PGLayer) UpdateAPIKeyLastUsed added in v0.8.0

func (pg *PGLayer) UpdateAPIKeyLastUsed(ctx context.Context, token uuid.UUID) error

UpdateAPIKeyLastUsed updates the last used field for the api key token

func (*PGLayer) UpdateHelmReleaseRevision

func (pg *PGLayer) UpdateHelmReleaseRevision(ctx context.Context, envname, release, revision string) error

func (*PGLayer) UpdateK8sEnvConfigSignature added in v0.7.6

func (pg *PGLayer) UpdateK8sEnvConfigSignature(ctx context.Context, name string, confSig [32]byte) error

UpdateK8sEnvConfigSignature updates an existing k8s environment config signature

func (*PGLayer) UpdateUISession added in v0.7.6

func (pg *PGLayer) UpdateUISession(id int, githubUser string, encryptedtoken []byte, authenticated bool) error

UpdateUISession updates the session with ID with githubUser and authenticated flag

type QADestroyReason

type QADestroyReason = models.QADestroyReason

type QAEnvironment

type QAEnvironment = models.QAEnvironment

type QAEnvironmentEvent

type QAEnvironmentEvent = models.QAEnvironmentEvent

type QAEnvironments

type QAEnvironments = models.QAEnvironments

type QAType

type QAType = models.QAType

type RefMap

type RefMap = models.RefMap

type RepoRevisionData

type RepoRevisionData = models.RepoRevisionData

type ServerConfig

type ServerConfig = config.ServerConfig

type UISessionsDataLayer added in v0.7.6

type UISessionsDataLayer interface {
	CreateUISession(targetRoute string, state []byte, clientIP net.IP, userAgent string, expires time.Time) (int, error)
	UpdateUISession(id int, githubUser string, encryptedtoken []byte, authenticated bool) error
	DeleteUISession(id int) error
	GetUISession(id int) (*models.UISession, error)
	DeleteExpiredUISessions() (uint, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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