cloudstore

package
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2024 License: MPL-2.0 Imports: 12 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"`

	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) (*Data, 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 cloud.CommandLogs) error

AppendPreviewLogs appends logs to the given stack preview.

func (*Data) FindDeploymentForCommit added in v0.5.0

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

FindDeploymentForCommit returns the deployment for the given commit.

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, stackTarget string, deploymentID cloud.UUID, fromLine int) (cloud.CommandLogs, error)

GetDeploymentLogs returns the logs of the given deployment.

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 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) 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 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,
	stackTarget string,
	deploymentID cloud.UUID,
	logs cloud.CommandLogs,
) 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) UpdateStackPreview added in v0.5.4

func (d *Data) UpdateStackPreview(org Org, stackPreviewID string, status string, changeset *cloud.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 cloud.UUID, p Preview) (string, error)

UpsertPreview inserts or updates the given preview.

func (*Data) UpsertStack

func (d *Data) UpsertStack(orguuid cloud.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          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.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]cloud.CommandLogs   `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"`
	StackTarget string                    `json:"stack_target"`
	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"`
	Previews       []Preview                  `json:"previews"`
	ReviewRequests []cloud.ReviewRequest      `json:"review_requests"`
}

Org is the organization model.

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   *cloud.ReviewRequest      `json:"review_request,omitempty"`
	Metadata        *cloud.DeploymentMetadata `json:"metadata,omitempty"`
	StackPreviews   []*StackPreview           `json:"stack_previews"`
}

Preview is the preview model.

type Stack

type Stack struct {
	cloud.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 *cloud.ChangesetDetails `json:"changeset_details,omitempty"`
	Logs             cloud.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