cloudstore

package
v0.4.5-rc3 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package cloudstore provides the in-memory store used by the fake Terramate Cloud server.

Index

Constants

View Source
const (
	// ErrAlreadyExists is the error for the case where the record already exists.
	ErrAlreadyExists errors.Kind = "record already exists"
	// ErrNotExists is the error when the record does not exists.
	ErrNotExists errors.Kind = "record does not exist"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data struct {
	Orgs      map[string]Org        `json:"orgs"`
	Users     map[string]cloud.User `json:"users"`
	WellKnown *cloud.WellKnown      `json:"well_known"`
	// contains filtered or unexported fields
}

Data is the in-memory data store. It has public fields but they *SHALL NOT* be directly manipulated unless for the case of initialiting the data.

func LoadDatastore

func LoadDatastore(fpath string) (*Data, error)

LoadDatastore loads the data store from a JSON file.

func (*Data) GetDeployment

func (d *Data) GetDeployment(org *Org, id cloud.UUID) (*Deployment, bool)

GetDeployment returns the given deployment.

func (*Data) GetDeploymentEvents

func (d *Data) GetDeploymentEvents(orgID, deploymentID cloud.UUID) (map[string][]deployment.Status, error)

GetDeploymentEvents returns the events of the given deployment.

func (*Data) GetDeploymentLogs

func (d *Data) GetDeploymentLogs(orgID cloud.UUID, stackMetaID string, deploymentID cloud.UUID, fromLine int) (cloud.DeploymentLogs, error)

GetDeploymentLogs returns the logs of the given deployment.

func (*Data) GetMemberships

func (d *Data) GetMemberships(user cloud.User) []Member

GetMemberships returns the organizations that user is member of.

func (*Data) GetOrg

func (d *Data) GetOrg(uuid cloud.UUID) (Org, bool)

GetOrg retrieves the organization with the provided uuid.

func (*Data) GetStack

func (d *Data) GetStack(org Org, id int64) (Stack, bool)

GetStack by id.

func (*Data) GetStackByMetaID

func (d *Data) GetStackByMetaID(org Org, id string) (Stack, int64, bool)

GetStackByMetaID returns the given stack.

func (*Data) GetStackDrifts

func (d *Data) GetStackDrifts(orguuid cloud.UUID, stackID int64) ([]Drift, error)

GetStackDrifts returns the drifts of the provided stack.

func (*Data) GetUser

func (d *Data) GetUser(email string) (cloud.User, bool)

GetUser retrieves the user by email from the store.

func (*Data) GetWellKnown

func (d *Data) GetWellKnown() *cloud.WellKnown

GetWellKnown gets the defined well-known.

func (*Data) InsertDeployment

func (d *Data) InsertDeployment(orgID cloud.UUID, deploy Deployment) error

InsertDeployment inserts the given deployment in the data store.

func (*Data) InsertDeploymentLogs

func (d *Data) InsertDeploymentLogs(
	orgID cloud.UUID,
	stackMetaID string,
	deploymentID cloud.UUID,
	logs cloud.DeploymentLogs,
) error

InsertDeploymentLogs inserts logs for the given deployment.

func (*Data) InsertDrift

func (d *Data) InsertDrift(orgID cloud.UUID, drift Drift) (int, error)

InsertDrift inserts a new drift into the store for the provided org.

func (*Data) MarshalJSON

func (d *Data) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface to the data store. It's required to avoid data races if store is concurrently accessed.

func (*Data) MustGetUser

func (d *Data) MustGetUser(email string) cloud.User

MustGetUser retrieves the user by email or panics.

func (*Data) MustOrgByName

func (d *Data) MustOrgByName(name string) Org

MustOrgByName must return an organization with the provided name otherwise it panics.

func (*Data) OrgByName

func (d *Data) OrgByName(name string) (Org, bool)

OrgByName returns an organization with the provided name.

func (*Data) SetDeploymentStatus

func (d *Data) SetDeploymentStatus(org Org, deploymentID cloud.UUID, stackID int64, status deployment.Status) error

SetDeploymentStatus sets the given deployment stack to the given status.

func (*Data) UpsertOrg

func (d *Data) UpsertOrg(org Org)

UpsertOrg inserts or updates the provided organization.

func (*Data) UpsertStack

func (d *Data) UpsertStack(orguuid cloud.UUID, st Stack) (int64, error)

UpsertStack inserts or updates the given stack.

type Deployment

type Deployment struct {
	UUID          cloud.UUID                     `json:"uuid"`
	Stacks        []int64                        `json:"stacks"`
	Workdir       string                         `json:"workdir"`
	StackCommands map[string]string              `json:"stack_commands"`
	DeploymentURL string                         `json:"deployment_url,omitempty"`
	Status        deployment.Status              `json:"status"`
	Metadata      *cloud.DeploymentMetadata      `json:"metadata"`
	ReviewRequest *cloud.DeploymentReviewRequest `json:"review_request"`
	State         DeploymentState                `json:"state"`
}

Deployment model.

type DeploymentState

type DeploymentState struct {
	StackStatus       map[int64]deployment.Status    `json:"stacks_status"`
	StackStatusEvents map[int64][]deployment.Status  `json:"stacks_events"`
	StackLogs         map[int64]cloud.DeploymentLogs `json:"stacks_logs"`
}

DeploymentState is the state of a deployment.

type Drift

type Drift struct {
	ID          int64                     `json:"id"`
	StackMetaID string                    `json:"stack_meta_id"`
	Status      drift.Status              `json:"status"`
	Details     *cloud.ChangesetDetails   `json:"details"`
	Metadata    *cloud.DeploymentMetadata `json:"metadata"`
	Command     []string                  `json:"command"`
	StartedAt   *time.Time                `json:"started_at,omitempty"`
	FinishedAt  *time.Time                `json:"finished_at,omitempty"`
}

Drift model.

type Member

type Member struct {
	UserUUID cloud.UUID `json:"user_uuid"`
	Role     string     `json:"role"`
	Status   string     `json:"status"`
	MemberID int64      // implicit from the members list position index.
	Org      *Org       // back-pointer set while retrieving memberships.
}

Member represents the organization member.

type Org

type Org struct {
	UUID        cloud.UUID `json:"uuid"`
	Name        string     `json:"name"`
	DisplayName string     `json:"display_name"`
	Domain      string     `json:"domain"`
	Status      string     `json:"status"`

	Members     []Member                   `json:"members"`
	Stacks      []Stack                    `json:"stacks"`
	Deployments map[cloud.UUID]*Deployment `json:"deployments"`
	Drifts      []Drift                    `json:"drifts"`
}

Org is the organization model.

type Stack

type Stack struct {
	cloud.Stack

	State StackState `json:"state"`
}

Stack is the stack representation.

type StackState

type StackState struct {
	Status           stack.Status      `json:"status"`
	DeploymentStatus deployment.Status `json:"deployment_status"`
	DriftStatus      drift.Status      `json:"drift_status"`
	CreatedAt        *time.Time        `json:"created_at,omitempty"`
	UpdatedAt        *time.Time        `json:"updated_at,omitempty"`
	SeenAt           *time.Time        `json:"seen_at,omitempty"`
}

StackState represents the state of the stack.

func NewState

func NewState() StackState

NewState creates a new valid state.

Jump to

Keyboard shortcuts

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