cloudstore

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MPL-2.0 Imports: 15 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]resources.User `json:"users"`
	WellKnown *resources.WellKnown      `json:"well_known"`

	Github struct {
		GetPullRequestResponse json.RawMessage `json:"get_pull_request_response"`
		GetCommitResponse      json.RawMessage `json:"get_commit_response"`
	} `json:"github"`
	// 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) (store *Data, defaultOrg string, err error)

LoadDatastore loads the data store from a JSON file.

func (*Data) AppendPreviewLogs added in v0.5.4

func (d *Data) AppendPreviewLogs(org Org, stackPreviewID string, logs resources.CommandLogs) error

AppendPreviewLogs appends logs to the given stack preview.

func (*Data) DeleteOutput added in v0.12.0

func (d *Data) DeleteOutput(orgUUID resources.UUID, id resources.UUID) error

DeleteOutput deletes the output with the given id.

func (*Data) FindDeploymentForCommit added in v0.5.0

func (d *Data) FindDeploymentForCommit(orgID resources.UUID, commitSHA string) (*Deployment, bool)

FindDeploymentForCommit returns the deployment for the given commit.

func (*Data) GetDeployment

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

GetDeployment returns the given deployment.

func (*Data) GetDeploymentEvents

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

GetDeploymentEvents returns the events of the given deployment.

func (*Data) GetDeploymentLogs

func (d *Data) GetDeploymentLogs(orgID resources.UUID, stackMetaID string, stackTarget string, deploymentID resources.UUID, fromLine int) (resources.CommandLogs, error)

GetDeploymentLogs returns the logs of the given deployment.

func (*Data) GetDriftLogs added in v0.15.0

func (d *Data) GetDriftLogs(
	orgID resources.UUID,
	driftUUID resources.UUID,
) (resources.CommandLogs, error)

GetDriftLogs gets logs for the given drift.

func (*Data) GetGithubCommitResponse added in v0.5.4

func (d *Data) GetGithubCommitResponse() json.RawMessage

GetGithubCommitResponse returns the github commit response.

func (*Data) GetGithubPullRequestResponse added in v0.5.4

func (d *Data) GetGithubPullRequestResponse() json.RawMessage

GetGithubPullRequestResponse returns the github pull request response.

func (*Data) GetMemberships

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

GetMemberships returns the organizations that user is member of.

func (*Data) GetMembershipsForKey added in v0.11.5

func (d *Data) GetMembershipsForKey(key string) []Member

GetMembershipsForKey returns the memberships for the given key.

func (*Data) GetOrg

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

GetOrg retrieves the organization with the provided uuid.

func (*Data) GetOutput added in v0.12.0

func (d *Data) GetOutput(orgUUID resources.UUID, id resources.UUID) (resources.StoreOutput, error)

GetOutput retrieves the output for the given id.

func (*Data) GetOutputByKey added in v0.12.0

func (d *Data) GetOutputByKey(orgUUID resources.UUID, key resources.StoreOutputKey) (resources.StoreOutput, error)

GetOutputByKey retrieves the output for the given key.

func (*Data) GetPreviewByID added in v0.5.4

func (d *Data) GetPreviewByID(org Org, previewID string) (Preview, bool)

GetPreviewByID returns the preview associated with previewID.

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, target string) (Stack, int64, bool)

GetStackByMetaID returns the given stack.

func (*Data) GetStackDrifts

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

GetStackDrifts returns the drifts of the provided stack.

func (*Data) GetUser

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

GetUser retrieves the user by email from the store.

func (*Data) GetWellKnown

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

GetWellKnown gets the defined well-known.

func (*Data) InsertDeployment

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

InsertDeployment inserts the given deployment in the data store.

func (*Data) InsertDeploymentLogs

func (d *Data) InsertDeploymentLogs(
	orgID resources.UUID,
	stackMetaID string,
	stackTarget string,
	deploymentID resources.UUID,
	logs resources.CommandLogs,
) error

InsertDeploymentLogs inserts logs for the given deployment.

func (*Data) InsertDrift

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

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

func (*Data) InsertDriftLogs added in v0.15.0

func (d *Data) InsertDriftLogs(
	orgID resources.UUID,
	driftUUID resources.UUID,
	logs resources.CommandLogs,
) error

InsertDriftLogs inserts logs for the given drift.

func (*Data) InsertOutput added in v0.12.0

func (d *Data) InsertOutput(orgUUID resources.UUID, output *resources.StoreOutput) error

InsertOutput inserts the given output into the store.

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) resources.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 resources.UUID, stackID int64, status deployment.Status) error

SetDeploymentStatus sets the given deployment stack to the given status.

func (*Data) UpdateDrift added in v0.15.0

func (d *Data) UpdateDrift(org *Org, driftUUID resources.UUID, status drift.Status, changeset *resources.ChangesetDetails, at time.Time) (Drift, bool)

UpdateDrift updates the drift in the store.

func (*Data) UpdateOutputValue added in v0.12.0

func (d *Data) UpdateOutputValue(orgUUID resources.UUID, id resources.UUID, newval string) error

UpdateOutputValue updates the value of the output.

func (*Data) UpdateStackPreview added in v0.5.4

func (d *Data) UpdateStackPreview(org Org, stackPreviewID string, status string, changeset *resources.ChangesetDetails) (*StackPreview, bool)

UpdateStackPreview updates the given stack preview.

func (*Data) UpsertOrg

func (d *Data) UpsertOrg(org Org)

UpsertOrg inserts or updates the provided organization.

func (*Data) UpsertPreview added in v0.5.4

func (d *Data) UpsertPreview(orguuid resources.UUID, p Preview) (string, error)

UpsertPreview inserts or updates the given preview.

func (*Data) UpsertStack

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

UpsertStack inserts or updates the given stack.

func (*Data) UpsertStackPreview added in v0.5.4

func (d *Data) UpsertStackPreview(org Org, previewID string, sp *StackPreview) (string, error)

UpsertStackPreview inserts or updates the given stack preview.

type Deployment

type Deployment struct {
	UUID          resources.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      *resources.DeploymentMetadata `json:"metadata"`
	ReviewRequest *resources.ReviewRequest      `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]resources.CommandLogs `json:"stacks_logs"`
}

DeploymentState is the state of a deployment.

type Drift

type Drift struct {
	ID          int64                         `json:"id"`
	UUID        resources.UUID                `json:"uuid"`
	StackMetaID string                        `json:"stack_meta_id"`
	StackTarget string                        `json:"stack_target"`
	Status      drift.Status                  `json:"status"`
	Changeset   *resources.ChangesetDetails   `json:"changeset"`
	Metadata    *resources.DeploymentMetadata `json:"metadata"`
	Command     []string                      `json:"command"`
	StartedAt   *time.Time                    `json:"started_at,omitempty"`
	FinishedAt  *time.Time                    `json:"finished_at,omitempty"`
	State       DriftState                    `json:"state"`
}

Drift model.

type DriftState added in v0.15.0

type DriftState struct {
	Logs resources.CommandLogs
}

DriftState is the state of a drift check run.

type Member

type Member struct {
	UserUUID resources.UUID `json:"user_uuid"`
	APIKey   string         `json:"apikey"`
	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        resources.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[resources.UUID]*Deployment   `json:"deployments"`
	Drifts         map[resources.UUID]Drift         `json:"drifts"`
	Previews       []Preview                        `json:"previews"`
	ReviewRequests []resources.ReviewRequest        `json:"review_requests"`
	Outputs        map[string]resources.StoreOutput `json:"outputs"` // map of (encoded key) -> output'
}

Org is the organization model.

func (Org) Clone added in v0.10.6

func (org Org) Clone() Org

Clone the organization.

type OutputKey added in v0.12.0

type OutputKey struct {
	OrgUUID     resources.UUID `json:"org_uuid"`
	Repository  string         `json:"repository"`
	StackMetaID string         `json:"stack_meta_id"`
	Target      string         `json:"target"`
	Name        string         `json:"name"`
}

OutputKey is the primary key of an output.

type Preview added in v0.5.4

type Preview struct {
	PreviewID string `json:"preview_id"`

	PushedAt        int64                         `json:"pushed_at"`
	CommitSHA       string                        `json:"commit_sha"`
	Technology      string                        `json:"technology"`
	TechnologyLayer string                        `json:"technology_layer"`
	ReviewRequest   *resources.ReviewRequest      `json:"review_request,omitempty"`
	Metadata        *resources.DeploymentMetadata `json:"metadata,omitempty"`
	StackPreviews   []*StackPreview               `json:"stack_previews"`
}

Preview is the preview model.

type Stack

type Stack struct {
	resources.Stack

	State StackState `json:"state"`
}

Stack is the stack representation.

type StackPreview added in v0.5.4

type StackPreview struct {
	Stack

	ID               string                      `json:"stack_preview_id"`
	Status           preview.StackStatus         `json:"status"`
	Cmd              []string                    `json:"cmd,omitempty"`
	ChangesetDetails *resources.ChangesetDetails `json:"changeset_details,omitempty"`
	Logs             resources.CommandLogs       `json:"logs,omitempty"`
}

StackPreview is the stack preview model.

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