datastore

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Operation to find the field is equal to the specified value.
	OperatorEqual = iota + 1
	// Operation to find the field isn't equal to the specified value.
	OperatorNotEqual
	// Operation to find ones that contain any one of the multiple values.
	OperatorIn
	// Operation to find ones that do not contain any of the specified multiple values.
	OperatorNotIn
	// Operation to find ones the field is greater than the specified value.
	OperatorGreaterThan
	// Operation to find ones the field is greater or equal than the specified value.
	OperatorGreaterThanOrEqual
	// Operation to find ones the field is less than the specified value.
	OperatorLessThan
	// Operation to find ones the field is less or equal than the specified value.
	OperatorLessThanOrEqual
	// Operation to find ones that have a specified value in its array.
	OperatorContains
)

Variables

View Source
var (
	ErrNotFound        = errors.New("not found")
	ErrInvalidArgument = errors.New("invalid argument")
	ErrAlreadyExists   = errors.New("already exists")
	ErrInvalidCursor   = errors.New("invalid cursor")
	ErrIteratorDone    = errors.New("iterator is done")
	ErrInternal        = errors.New("internal")
	ErrUnimplemented   = errors.New("unimplemented")
)
View Source
var (
	DeploymentChainAddDeploymentToBlock = func(deployment *model.Deployment) func(*model.DeploymentChain) error {
		return func(dc *model.DeploymentChain) error {
			if deployment.DeploymentChainBlockIndex >= uint32(len(dc.Blocks)) {
				return fmt.Errorf("invalid block index (%d) provided", deployment.DeploymentChainBlockIndex)
			}

			block := dc.Blocks[deployment.DeploymentChainBlockIndex]
			var updated bool
			for _, node := range block.Nodes {
				if node.ApplicationRef.ApplicationId != deployment.ApplicationId {
					continue
				}
				node.DeploymentRef = &model.ChainDeploymentRef{
					DeploymentId: deployment.Id,
					Status:       deployment.Status,
					StatusReason: deployment.StatusReason,
				}
				updated = true
				break
			}
			if !updated {
				return fmt.Errorf("unable to find the right node in chain to assign deployment to")
			}
			return nil
		}
	}

	DeploymentChainNodeDeploymentStatusUpdater = func(blockIndex uint32, deploymentID string, status model.DeploymentStatus, reason string) func(*model.DeploymentChain) error {
		return func(dc *model.DeploymentChain) error {
			if blockIndex >= uint32(len(dc.Blocks)) {
				return fmt.Errorf("invalid block index %d provided", blockIndex)
			}

			block := dc.Blocks[blockIndex]
			node, err := block.GetNodeByDeploymentID(deploymentID)
			if err != nil {
				return err
			}
			node.DeploymentRef.Status = status
			node.DeploymentRef.StatusReason = reason

			if block.IsCompleted() {
				return nil
			}

			block.Status = block.DesiredStatus()
			if block.IsCompleted() {
				block.CompletedAt = time.Now().Unix()
			}

			dc.Status = dc.DesiredStatus()
			if dc.IsCompleted() {
				dc.CompletedAt = time.Now().Unix()
			}

			return nil
		}
	}
)
View Source
var (
	DeploymentToPlannedUpdater = func(summary, statusReason, runningCommitHash, runningConfigFilename, version string, stages []*model.PipelineStage) func(*model.Deployment) error {
		return func(d *model.Deployment) error {
			d.Status = model.DeploymentStatus_DEPLOYMENT_PLANNED
			d.Summary = summary
			d.StatusReason = statusReason
			d.RunningCommitHash = runningCommitHash
			d.RunningConfigFilename = runningConfigFilename
			d.Version = version
			d.Stages = stages
			return nil
		}
	}

	DeploymentStatusUpdater = func(status model.DeploymentStatus, statusReason string) func(*model.Deployment) error {
		return func(d *model.Deployment) error {
			d.Status = status
			d.StatusReason = statusReason
			return nil
		}
	}

	DeploymentToCompletedUpdater = func(status model.DeploymentStatus, statuses map[string]model.StageStatus, statusReason string, completedAt int64) func(*model.Deployment) error {
		return func(d *model.Deployment) error {
			if !model.IsCompletedDeployment(status) {
				return fmt.Errorf("deployment status %s is not completed value: %w", status, ErrInvalidArgument)
			}

			d.Status = status
			d.StatusReason = statusReason
			d.CompletedAt = completedAt
			for i := range d.Stages {
				stageID := d.Stages[i].Id
				if status, ok := statuses[stageID]; ok {
					d.Stages[i].Status = status
				}
			}
			return nil
		}
	}

	StageStatusChangedUpdater = func(stageID string, status model.StageStatus, statusReason string, requires []string, visible bool, retriedCount int32, completedAt int64) func(*model.Deployment) error {
		return func(d *model.Deployment) error {
			for _, s := range d.Stages {
				if s.Id == stageID {
					s.Status = status
					s.StatusReason = statusReason
					if len(requires) > 0 {
						s.Requires = requires
					}
					s.Visible = visible
					s.RetriedCount = retriedCount
					s.CompletedAt = completedAt
					return nil
				}
			}
			return fmt.Errorf("stage id %s not found: %w", stageID, ErrInvalidArgument)
		}
	}
)
View Source
var (
	CommandHandledUpdater = func(status model.CommandStatus, metadata map[string]string, handledAt int64) func(*model.Command) error {
		return func(cmd *model.Command) error {
			cmd.Status = status
			cmd.Metadata = metadata
			cmd.HandledAt = handledAt
			return nil
		}
	}
)
View Source
var (
	PipedMetadataUpdater = func(
		cloudProviders []*model.Piped_CloudProvider,
		repos []*model.ApplicationGitRepository,
		se *model.Piped_SecretEncryption,
		version string,
		startedAt int64,
	) func(piped *model.Piped) error {

		return func(piped *model.Piped) error {
			piped.CloudProviders = cloudProviders
			piped.Repositories = repos

			piped.SecretEncryption = se

			piped.SealedSecretEncryption = nil

			piped.Version = version
			piped.StartedAt = startedAt
			return nil
		}
	}
)

Functions

This section is empty.

Types

type APIKeyStore

type APIKeyStore interface {
	AddAPIKey(ctx context.Context, k *model.APIKey) error
	GetAPIKey(ctx context.Context, id string) (*model.APIKey, error)
	ListAPIKeys(ctx context.Context, opts ListOptions) ([]*model.APIKey, error)
	DisableAPIKey(ctx context.Context, id, projectID string) error
}

func NewAPIKeyStore

func NewAPIKeyStore(ds DataStore) APIKeyStore

type ApplicationStore

type ApplicationStore interface {
	AddApplication(ctx context.Context, app *model.Application) error
	GetApplication(ctx context.Context, id string) (*model.Application, error)
	ListApplications(ctx context.Context, opts ListOptions) ([]*model.Application, string, error)
	EnableApplication(ctx context.Context, id string) error
	DisableApplication(ctx context.Context, id string) error
	DeleteApplication(ctx context.Context, id string) error
	UpdateApplication(ctx context.Context, id string, updater func(*model.Application) error) error
	UpdateApplicationSyncState(ctx context.Context, id string, syncState *model.ApplicationSyncState) error
	UpdateApplicationMostRecentDeployment(ctx context.Context, id string, status model.DeploymentStatus, deployment *model.ApplicationDeploymentReference) error
	FillConfigFilenameToDeploymentReference(ctx context.Context, id string) error
}

func NewApplicationStore

func NewApplicationStore(ds DataStore) ApplicationStore

type Collection added in v0.24.1

type Collection interface {
	Kind() string
	Factory() Factory
}

type CommandStore

type CommandStore interface {
	AddCommand(ctx context.Context, cmd *model.Command) error
	GetCommand(ctx context.Context, id string) (*model.Command, error)
	ListCommands(ctx context.Context, opts ListOptions) ([]*model.Command, error)
	UpdateCommand(ctx context.Context, id string, updater func(piped *model.Command) error) error
}

func NewCommandStore

func NewCommandStore(ds DataStore) CommandStore

type DataStore

type DataStore interface {
	// Find finds the documents matched given criteria.
	Find(ctx context.Context, col Collection, opts ListOptions) (Iterator, error)
	// Get gets one document specified with ID, and unmarshal it to typed struct.
	// If the document can not be found in datastore, ErrNotFound will be returned.
	Get(ctx context.Context, col Collection, id string, entity interface{}) error
	// Create saves a new entity to the datastore.
	// If an entity with the same ID is already existing, ErrAlreadyExists will be returned.
	Create(ctx context.Context, col Collection, id string, entity interface{}) error
	// Update updates an existing entity in the datastore.
	// If updating entity was not found in the datastore, ErrNotFound will be returned.
	Update(ctx context.Context, col Collection, id string, updater Updater) error
	// Close closes datastore resources held by the client.
	Close() error
}

type DeploymentChainStore

type DeploymentChainStore interface {
	AddDeploymentChain(ctx context.Context, d *model.DeploymentChain) error
	GetDeploymentChain(ctx context.Context, id string) (*model.DeploymentChain, error)
	ListDeploymentChains(ctx context.Context, opts ListOptions) ([]*model.DeploymentChain, string, error)
	UpdateDeploymentChain(ctx context.Context, id string, updater func(*model.DeploymentChain) error) error
}

func NewDeploymentChainStore

func NewDeploymentChainStore(ds DataStore) DeploymentChainStore

type DeploymentStore

type DeploymentStore interface {
	AddDeployment(ctx context.Context, d *model.Deployment) error
	GetDeployment(ctx context.Context, id string) (*model.Deployment, error)
	ListDeployments(ctx context.Context, opts ListOptions) ([]*model.Deployment, string, error)
	UpdateDeployment(ctx context.Context, id string, updater func(*model.Deployment) error) error
	UpdateDeploymentMetadata(ctx context.Context, id string, metadata map[string]string) error
	UpdateDeploymentStageMetadata(ctx context.Context, deploymentID, stageID string, metadata map[string]string) error
}

func NewDeploymentStore

func NewDeploymentStore(ds DataStore) DeploymentStore

type EnvironmentStore

type EnvironmentStore interface {
	AddEnvironment(ctx context.Context, env *model.Environment) error
	GetEnvironment(ctx context.Context, id string) (*model.Environment, error)
	ListEnvironments(ctx context.Context, opts ListOptions) ([]*model.Environment, error)
	EnableEnvironment(ctx context.Context, id string) error
	DisableEnvironment(ctx context.Context, id string) error
	DeleteEnvironment(ctx context.Context, id string) error
}

func NewEnvironmentStore

func NewEnvironmentStore(ds DataStore) EnvironmentStore

type EventStore

type EventStore interface {
	AddEvent(ctx context.Context, e model.Event) error
	ListEvents(ctx context.Context, opts ListOptions) ([]*model.Event, string, error)
	UpdateEventStatus(ctx context.Context, eventID string, status model.EventStatus, statusDescription string) error
}

func NewEventStore

func NewEventStore(ds DataStore) EventStore

type Factory

type Factory func() interface{}

type Iterator

type Iterator interface {
	Next(dst interface{}) error
	Cursor() (string, error)
}

type ListFilter

type ListFilter struct {
	Field    string
	Operator Operator
	Value    interface{}
}

type ListOptions

type ListOptions struct {
	Limit   int
	Filters []ListFilter
	Orders  []Order
	Cursor  string
}

type MockCollection added in v0.24.1

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

MockCollection is a mock of Collection interface.

func NewMockCollection added in v0.24.1

func NewMockCollection(ctrl *gomock.Controller) *MockCollection

NewMockCollection creates a new mock instance.

func (*MockCollection) EXPECT added in v0.24.1

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockCollection) Factory added in v0.24.1

func (m *MockCollection) Factory() Factory

Factory mocks base method.

func (*MockCollection) Kind added in v0.24.1

func (m *MockCollection) Kind() string

Kind mocks base method.

type MockCollectionMockRecorder added in v0.24.1

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

MockCollectionMockRecorder is the mock recorder for MockCollection.

func (*MockCollectionMockRecorder) Factory added in v0.24.1

func (mr *MockCollectionMockRecorder) Factory() *gomock.Call

Factory indicates an expected call of Factory.

func (*MockCollectionMockRecorder) Kind added in v0.24.1

Kind indicates an expected call of Kind.

type MockDataStore

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

MockDataStore is a mock of DataStore interface.

func NewMockDataStore

func NewMockDataStore(ctrl *gomock.Controller) *MockDataStore

NewMockDataStore creates a new mock instance.

func (*MockDataStore) Close

func (m *MockDataStore) Close() error

Close mocks base method.

func (*MockDataStore) Create

func (m *MockDataStore) Create(ctx context.Context, col Collection, id string, entity interface{}) error

Create mocks base method.

func (*MockDataStore) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockDataStore) Find

func (m *MockDataStore) Find(ctx context.Context, col Collection, opts ListOptions) (Iterator, error)

Find mocks base method.

func (*MockDataStore) Get

func (m *MockDataStore) Get(ctx context.Context, col Collection, id string, entity interface{}) error

Get mocks base method.

func (*MockDataStore) Update

func (m *MockDataStore) Update(ctx context.Context, col Collection, id string, updater Updater) error

Update mocks base method.

type MockDataStoreMockRecorder

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

MockDataStoreMockRecorder is the mock recorder for MockDataStore.

func (*MockDataStoreMockRecorder) Close

func (mr *MockDataStoreMockRecorder) Close() *gomock.Call

Close indicates an expected call of Close.

func (*MockDataStoreMockRecorder) Create

func (mr *MockDataStoreMockRecorder) Create(ctx, col, id, entity interface{}) *gomock.Call

Create indicates an expected call of Create.

func (*MockDataStoreMockRecorder) Find

func (mr *MockDataStoreMockRecorder) Find(ctx, col, opts interface{}) *gomock.Call

Find indicates an expected call of Find.

func (*MockDataStoreMockRecorder) Get

func (mr *MockDataStoreMockRecorder) Get(ctx, col, id, entity interface{}) *gomock.Call

Get indicates an expected call of Get.

func (*MockDataStoreMockRecorder) Update

func (mr *MockDataStoreMockRecorder) Update(ctx, col, id, updater interface{}) *gomock.Call

Update indicates an expected call of Update.

type MockIterator

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

MockIterator is a mock of Iterator interface.

func NewMockIterator

func NewMockIterator(ctrl *gomock.Controller) *MockIterator

NewMockIterator creates a new mock instance.

func (*MockIterator) Cursor

func (m *MockIterator) Cursor() (string, error)

Cursor mocks base method.

func (*MockIterator) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockIterator) Next

func (m *MockIterator) Next(dst interface{}) error

Next mocks base method.

type MockIteratorMockRecorder

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

MockIteratorMockRecorder is the mock recorder for MockIterator.

func (*MockIteratorMockRecorder) Cursor

func (mr *MockIteratorMockRecorder) Cursor() *gomock.Call

Cursor indicates an expected call of Cursor.

func (*MockIteratorMockRecorder) Next

func (mr *MockIteratorMockRecorder) Next(dst interface{}) *gomock.Call

Next indicates an expected call of Next.

type Operator

type Operator int

type Order

type Order struct {
	Field     string
	Direction OrderDirection
}

type OrderDirection

type OrderDirection int
const (
	// Asc sorts results from smallest to largest.
	Asc OrderDirection = iota + 1
	// Desc sorts results from largest to smallest.
	Desc
)

type PipedStore

type PipedStore interface {
	AddPiped(ctx context.Context, piped *model.Piped) error
	GetPiped(ctx context.Context, id string) (*model.Piped, error)
	ListPipeds(ctx context.Context, opts ListOptions) ([]*model.Piped, error)
	UpdatePiped(ctx context.Context, id string, updater func(piped *model.Piped) error) error
	EnablePiped(ctx context.Context, id string) error
	DisablePiped(ctx context.Context, id string) error
	AddKey(ctx context.Context, id, keyHash, creator string, createdAt time.Time) error
	DeleteOldKeys(ctx context.Context, id string) error
}

func NewPipedStore

func NewPipedStore(ds DataStore) PipedStore

type ProjectStore

type ProjectStore interface {
	AddProject(ctx context.Context, proj *model.Project) error
	GetProject(ctx context.Context, id string) (*model.Project, error)
	ListProjects(ctx context.Context, opts ListOptions) ([]model.Project, error)
	UpdateProject(ctx context.Context, id string, updater func(project *model.Project) error) error
	UpdateProjectStaticAdmin(ctx context.Context, id, username, password string) error
	EnableStaticAdmin(ctx context.Context, id string) error
	DisableStaticAdmin(ctx context.Context, id string) error
	UpdateProjectSSOConfig(ctx context.Context, id string, sso *model.ProjectSSOConfig) error
	UpdateProjectRBACConfig(ctx context.Context, id string, sso *model.ProjectRBACConfig) error
}

func NewProjectStore

func NewProjectStore(ds DataStore) ProjectStore

type Updater

type Updater func(interface{}) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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