cloud

package
v0.4.3-rc1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: MPL-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package cloud implements a client SDK for communication with the cloud API.

Package cloud implements the SDK for communicating with the Terramate Cloud.

Index

Constants

View Source
const (
	// UsersPath is the users endpoint base path.
	UsersPath = "/v1/users"
	// MembershipsPath is the memberships endpoint base path.
	MembershipsPath = "/v1/memberships"
	// DeploymentsPath is the deployments endpoint base path.
	DeploymentsPath = "/v1/deployments"
	// DriftsPath is the drifts endpoint base path.
	DriftsPath = "/v1/drifts"
	// StacksPath is the stacks endpoint base path.
	StacksPath = "/v1/stacks"
)
View Source
const BaseURL = "https://" + Host

BaseURL is the default cloud.terramate.io base API URL.

View Source
const DefaultLogBatchSize = 256

DefaultLogBatchSize is the default batch size.

View Source
const DefaultLogSyncInterval = 1 * time.Second

DefaultLogSyncInterval is the maximum idle duration before a sync could happen.

View Source
const ErrNotFound errors.Kind = "resource not found (HTTP Status 404)"

ErrNotFound indicates the requested resource does not exist in the server.

View Source
const ErrUnexpectedResponseBody errors.Kind = "unexpected API response body"

ErrUnexpectedResponseBody indicates the server responded with an unexpected body.

View Source
const ErrUnexpectedStatus errors.Kind = "unexpected status code"

ErrUnexpectedStatus indicates the server responded with an unexpected status code.

View Source
const Host = "api.terramate.io"

Host of the official Terramate Cloud API.

Variables

This section is empty.

Functions

func Get

func Get[T Resource](ctx context.Context, client *Client, endpoint ...string) (entity T, err error)

Get requests the endpoint components list making a GET request and decode the response into the entity T if validates successfully.

func NormalizeGitURI

func NormalizeGitURI(raw string) string

NormalizeGitURI normalizes the raw uri in a Terramate Cloud compatible form.

func Patch

func Patch[T Resource](ctx context.Context, client *Client, payload interface{}, endpoint ...string) (entity T, err error)

Patch requests the endpoint components list making a PATCH request and decode the response into the entity T if validates successfully.

func Post

func Post[T Resource](ctx context.Context, client *Client, payload interface{}, endpoint ...string) (entity T, err error)

Post requests the endpoint components list making a POST request and decode the response into the entity T if validates successfully.

func Put added in v0.4.1

func Put[T Resource](ctx context.Context, client *Client, payload interface{}, endpoint ...string) (entity T, err error)

Put requests the endpoint components list making a PUT request and decode the response into the entity T if validated successfully.

func Request

func Request[T Resource](ctx context.Context, c *Client, method string, resourceURL string, postBody io.Reader) (entity T, err error)

Request makes a request to the Terramate Cloud using client. The instantiated type gets decoded and return as the entity T,

Types

type Client

type Client struct {
	// BaseURL is the cloud base endpoint URL.
	// If not set, it defaults to [BaseURL].
	BaseURL    string
	IDPKey     string
	Credential Credential

	// HTTPClient is the HTTP client reused in all connections.
	// if not set, a new instance of http.Client is created on the first request.
	HTTPClient *http.Client
}

Client is the cloud SDK client.

func (*Client) CreateDeploymentStacks

func (c *Client) CreateDeploymentStacks(
	ctx context.Context,
	orgUUID string,
	deploymentUUID string,
	deploymentStacksPayload DeploymentStacksPayloadRequest,
) (DeploymentStacksResponse, error)

CreateDeploymentStacks creates a new deployment for provided stacks payload.

func (*Client) CreateStackDrift added in v0.4.2

func (c *Client) CreateStackDrift(
	ctx context.Context,
	orgUUID string,
	driftPayload DriftStackPayloadRequest,
) (EmptyResponse, error)

CreateStackDrift pushes a new drift status for the given stack.

func (*Client) MemberOrganizations

func (c *Client) MemberOrganizations(ctx context.Context) (orgs MemberOrganizations, err error)

MemberOrganizations returns all organizations which are associated with the user.

func (*Client) Stacks added in v0.4.1

func (c *Client) Stacks(ctx context.Context, orgUUID string, status stack.FilterStatus) (StacksResponse, error)

Stacks returns all stacks for the given organization.

func (*Client) SyncDeploymentLogs added in v0.4.3

func (c *Client) SyncDeploymentLogs(
	ctx context.Context,
	orgUUID string,
	stackID int,
	deploymentUUID string,
	logs DeploymentLogs,
) error

SyncDeploymentLogs sends a batch of deployment logs to Terramate Cloud.

func (*Client) UpdateDeploymentStacks

func (c *Client) UpdateDeploymentStacks(ctx context.Context, orgUUID string, deploymentUUID string, payload UpdateDeploymentStacks) error

UpdateDeploymentStacks updates the deployment status of each stack in the payload set.

func (*Client) Users

func (c *Client) Users(ctx context.Context) (user User, err error)

Users retrieves the user details for the signed in user.

type Credential

type Credential interface {
	// Token retrieves a new token ready be used (the credential provider must refresh the token if needed)
	Token() (string, error)
}

Credential is the interface for the credential providers.

type DeploymentLog added in v0.4.3

type DeploymentLog struct {
	Line      int64      `json:"log_line"`
	Timestamp *time.Time `json:"timestamp"`
	Channel   LogChannel `json:"channel"`
	Message   string     `json:"message"`
}

DeploymentLog represents a single log message.

func (DeploymentLog) Validate added in v0.4.3

func (l DeploymentLog) Validate() error

Validate a deployment log.

type DeploymentLogs added in v0.4.3

type DeploymentLogs []*DeploymentLog

DeploymentLogs represents a batch of log messages.

func (DeploymentLogs) Validate added in v0.4.3

func (ls DeploymentLogs) Validate() error

Validate a list of deployment logs.

type DeploymentMetadata added in v0.4.1

type DeploymentMetadata struct {
	GitHeadCommitSHA string `json:"git_head_commit_sha,omitempty"`

	GithubPullRequestAuthorLogin      string `json:"github_pull_request_author_login,omitempty"`
	GithubPullRequestAuthorAvatarURL  string `json:"github_pull_request_author_avatar_url,omitempty"`
	GithubPullRequestAuthorGravatarID string `json:"github_pull_request_author_gravatar_id,omitempty"`

	GithubPullRequestURL            string `json:"github_pull_request_url,omitempty"`
	GithubPullRequestNumber         int    `json:"github_pull_request_number,omitempty"`
	GithubPullRequestTitle          string `json:"github_pull_request_title,omitempty"`
	GithubPullRequestDescription    string `json:"github_pull_request_description,omitempty"`
	GithubPullRequestState          string `json:"github_pull_request_state,omitempty"`
	GithubPullRequestMergeCommitSHA string `json:"github_pull_request_merge_commit_sha,omitempty"`

	GithubPullRequestHeadLabel            string `json:"github_pull_request_head_label,omitempty"`
	GithubPullRequestHeadRef              string `json:"github_pull_request_head_ref,omitempty"`
	GithubPullRequestHeadSHA              string `json:"github_pull_request_head_sha,omitempty"`
	GithubPullRequestHeadAuthorLogin      string `json:"github_pull_request_head_author_login,omitempty"`
	GithubPullRequestHeadAuthorAvatarURL  string `json:"github_pull_request_head_author_avatar_url,omitempty"`
	GithubPullRequestHeadAuthorGravatarID string `json:"github_pull_request_head_author_gravatar_id,omitempty"`

	GithubPullRequestBaseLabel            string `json:"github_pull_request_base_label,omitempty"`
	GithubPullRequestBaseRef              string `json:"github_pull_request_base_ref,omitempty"`
	GithubPullRequestBaseSHA              string `json:"github_pull_request_base_sha,omitempty"`
	GithubPullRequestBaseAuthorLogin      string `json:"github_pull_request_base_author_login,omitempty"`
	GithubPullRequestBaseAuthorAvatarURL  string `json:"github_pull_request_base_author_avatar_url,omitempty"`
	GithubPullRequestBaseAuthorGravatarID string `json:"github_pull_request_base_author_gravatar_id,omitempty"`

	GithubPullRequestCreatedAt *time.Time `json:"github_pull_request_created_at,omitempty"`
	GithubPullRequestUpdatedAt *time.Time `json:"github_pull_request_updated_at,omitempty"`
	GithubPullRequestClosedAt  *time.Time `json:"github_pull_request_closed_at,omitempty"`
	GithubPullRequestMergedAt  *time.Time `json:"github_pull_request_merged_at,omitempty"`

	GithubCommitVerified       *bool  `json:"github_commit_verified,omitempty"`
	GithubCommitVerifiedReason string `json:"github_commit_verified_reason,omitempty"`

	GithubCommitTitle            string     `json:"github_commit_title,omitempty"`
	GithubCommitDescription      string     `json:"github_commit_description,omitempty"`
	GithubCommitAuthorLogin      string     `json:"github_commit_author_login,omitempty"`
	GithubCommitAuthorAvatarURL  string     `json:"github_commit_author_avatar_url,omitempty"`
	GithubCommitAuthorGravatarID string     `json:"github_commit_author_gravatar_id,omitempty"`
	GithubCommitAuthorGitName    string     `json:"github_commit_author_git_name,omitempty"`
	GithubCommitAuthorGitEmail   string     `json:"github_commit_author_git_email,omitempty"`
	GithubCommitAuthorGitDate    *time.Time `json:"github_commit_author_git_date,omitempty"`

	GithubCommitCommitterLogin      string     `json:"github_commit_committer_login,omitempty"`
	GithubCommitCommitterAvatarURL  string     `json:"github_commit_committer_avatar_url,omitempty"`
	GithubCommitCommitterGravatarID string     `json:"github_commit_committer_gravatar_id,omitempty"`
	GithubCommitCommitterGitName    string     `json:"github_commit_committer_git_name,omitempty"`
	GithubCommitCommitterGitEmail   string     `json:"github_commit_committer_git_email,omitempty"`
	GithubCommitCommitterGitDate    *time.Time `json:"github_commit_committer_git_date,omitempty"`

	GithubActionsDeploymentBranch      string `json:"github_actions_deployment_branch,omitempty"`
	GithubActionsDeploymentTriggeredBy string `json:"github_actions_triggered_by,omitempty"`
	GithubActionsRunID                 string `json:"github_actions_run_id,omitempty"`
	GithubActionsRunAttempt            string `json:"github_actions_run_attempt,omitempty"`
}

DeploymentMetadata stores the metadata available in the target platform. For now, we only support GitHub and Github Actions Metadata. It's marshaled as a flat hashmap of values. Note: no sensitive information must be stored here because it could be logged.

func (DeploymentMetadata) Validate added in v0.4.1

func (m DeploymentMetadata) Validate() error

Validate the metadata.

type DeploymentReviewRequest

type DeploymentReviewRequest struct {
	Platform    string `json:"platform"`
	Repository  string `json:"repository"`
	CommitSHA   string `json:"commit_sha"`
	Number      int    `json:"number"`
	Title       string `json:"title"`
	Description string `json:"description"`
	URL         string `json:"url"`
}

DeploymentReviewRequest is the review_request object.

func (DeploymentReviewRequest) Validate

func (rr DeploymentReviewRequest) Validate() error

Validate the DeploymentReviewRequest object.

type DeploymentStackRequest

type DeploymentStackRequest struct {
	Stack

	CommitSHA         string            `json:"commit_sha,omitempty"`
	DeploymentURL     string            `json:"deployment_url,omitempty"`
	DeploymentStatus  deployment.Status `json:"deployment_status,omitempty"`
	DeploymentCommand string            `json:"deployment_cmd"`
}

DeploymentStackRequest represents the stack object of the request payload type for the creation of stack deployments.

func (DeploymentStackRequest) Validate

func (d DeploymentStackRequest) Validate() error

Validate the deployment stack request.

type DeploymentStackRequests

type DeploymentStackRequests []DeploymentStackRequest

DeploymentStackRequests is a list of DeploymentStacksRequest.

func (DeploymentStackRequests) Validate

func (d DeploymentStackRequests) Validate() error

Validate the list of deployment stack requests.

type DeploymentStackResponse

type DeploymentStackResponse struct {
	StackID     int               `json:"stack_id"`
	StackMetaID string            `json:"meta_id"`
	Status      deployment.Status `json:"status"`
}

DeploymentStackResponse represents the deployment creation response item.

func (DeploymentStackResponse) Validate

func (d DeploymentStackResponse) Validate() error

Validate the deployment stack response.

type DeploymentStacksPayloadRequest

type DeploymentStacksPayloadRequest struct {
	ReviewRequest *DeploymentReviewRequest `json:"review_request,omitempty"`
	Stacks        DeploymentStackRequests  `json:"stacks"`
	Workdir       project.Path             `json:"workdir"`
	Metadata      *DeploymentMetadata      `json:"metadata,omitempty"`
}

DeploymentStacksPayloadRequest is the request payload for the creation of stack deployments.

func (DeploymentStacksPayloadRequest) Validate

Validate the deployment stack payload.

type DeploymentStacksResponse

type DeploymentStacksResponse []DeploymentStackResponse

DeploymentStacksResponse represents the list of DeploymentStackResponse.

func (DeploymentStacksResponse) Validate

func (ds DeploymentStacksResponse) Validate() error

Validate the list of deployment stacks response.

type DriftDetails added in v0.4.3

type DriftDetails struct {
	Provisioner    string `json:"provisioner"`
	ChangesetASCII string `json:"changeset_ascii,omitempty"`
	ChangesetJSON  string `json:"changeset_json,omitempty"`
}

DriftDetails represents the details of a drift.

func (DriftDetails) Validate added in v0.4.3

func (ds DriftDetails) Validate() error

Validate the drift details.

type DriftStackPayloadRequest added in v0.4.2

type DriftStackPayloadRequest struct {
	Stack    Stack               `json:"stack"`
	Status   stack.Status        `json:"drift_status"`
	Details  *DriftDetails       `json:"drift_details,omitempty"`
	Metadata *DeploymentMetadata `json:"metadata,omitempty"`
	Command  []string            `json:"command"`
}

DriftStackPayloadRequest is the payload for the drift sync.

func (DriftStackPayloadRequest) Validate added in v0.4.2

func (d DriftStackPayloadRequest) Validate() error

Validate the drift request payload.

type DriftStackPayloadRequests added in v0.4.2

type DriftStackPayloadRequests []DriftStackPayloadRequest

DriftStackPayloadRequests is a list of DriftStackPayloadRequest

func (DriftStackPayloadRequests) Validate added in v0.4.2

func (ds DriftStackPayloadRequests) Validate() error

Validate the list of drift requests.

type EmptyResponse added in v0.4.1

type EmptyResponse string

EmptyResponse is used to represent an empty string response.

func (EmptyResponse) Validate added in v0.4.1

func (s EmptyResponse) Validate() error

Validate that content is empty.

type LogChannel added in v0.4.3

type LogChannel int

LogChannel is an enum-like type for the output channels supported.

const (
	StdoutLogChannel LogChannel // StdoutLogChannel is the stdout channel
	StderrLogChannel            // StderrLogChannel is the stderr channel
)

func (*LogChannel) MarshalJSON added in v0.4.3

func (c *LogChannel) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (LogChannel) String added in v0.4.3

func (c LogChannel) String() string

String returns the channel name.

func (*LogChannel) UnmarshalJSON added in v0.4.3

func (c *LogChannel) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type LogSyncer added in v0.4.3

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

LogSyncer is the log syncer controller type.

func NewLogSyncer added in v0.4.3

func NewLogSyncer(syncfn Syncer) *LogSyncer

NewLogSyncer creates a new log syncer.

func NewLogSyncerWith added in v0.4.3

func NewLogSyncerWith(
	syncfn Syncer,
	batchSize int,
	syncInterval time.Duration,
) *LogSyncer

NewLogSyncerWith creates a new customizable syncer.

func (*LogSyncer) NewBuffer added in v0.4.3

func (s *LogSyncer) NewBuffer(channel LogChannel, out io.Writer) io.Writer

NewBuffer creates a new synchronized buffer.

func (*LogSyncer) Wait added in v0.4.3

func (s *LogSyncer) Wait()

Wait waits for the processing of all log messages. After calling this method, it's not safe to call any other method, as it closes the internal channels and shutdown all goroutines.

type MemberOrganization

type MemberOrganization struct {
	MemberID    int    `json:"member_id,omitempty"`
	Name        string `json:"org_name"`
	DisplayName string `json:"org_display_name"`
	Domain      string `json:"org_domain"`
	UUID        string `json:"org_uuid"`
	Role        string `json:"role,omitempty"`
	Status      string `json:"status"`
}

MemberOrganization represents the organization associated with the member.

func (MemberOrganization) Validate

func (org MemberOrganization) Validate() error

Validate checks if at least the fields required by Terramate CLI are set.

type MemberOrganizations

type MemberOrganizations []MemberOrganization

MemberOrganizations is a list of organizations associated with the member.

func (MemberOrganizations) String

func (orgs MemberOrganizations) String() string

String representation of the list of organization associated with the user.

func (MemberOrganizations) Validate

func (orgs MemberOrganizations) Validate() error

Validate if the organization list is valid.

type Resource

type Resource interface {
	Validate() error
}

Resource is the interface used to represent resource entities.

type Stack

type Stack struct {
	Repository      string   `json:"repository"`
	DefaultBranch   string   `json:"default_branch"`
	Path            string   `json:"path"`
	MetaID          string   `json:"meta_id"`
	MetaName        string   `json:"meta_name,omitempty"`
	MetaDescription string   `json:"meta_description,omitempty"`
	MetaTags        []string `json:"meta_tags,omitempty"`
}

Stack represents the stack as defined by the user HCL code.

func (Stack) Validate

func (s Stack) Validate() error

Validate the stack object.

type StackResponse added in v0.4.2

type StackResponse struct {
	ID int `json:"stack_id"`
	Stack
	Status stack.Status `json:"status"`

	// readonly fields
	CreatedAt *time.Time `json:"created_at,omitempty"`
	UpdatedAt *time.Time `json:"updated_at,omitempty"`
	SeenAt    *time.Time `json:"seen_at,omitempty"`
}

StackResponse represents a stack in the Terramate Cloud.

func (StackResponse) Validate added in v0.4.2

func (stack StackResponse) Validate() error

Validate the stack entity.

type StacksResponse added in v0.4.1

type StacksResponse struct {
	Stacks []StackResponse `json:"stacks"`
}

StacksResponse represents the stacks object response.

func (StacksResponse) Validate added in v0.4.1

func (stacksResp StacksResponse) Validate() error

Validate the StacksResponse object.

type Syncer added in v0.4.3

type Syncer func(l DeploymentLogs)

Syncer is the actual synchronizer callback.

type UpdateDeploymentStack

type UpdateDeploymentStack struct {
	StackID int               `json:"stack_id"`
	Status  deployment.Status `json:"status"`
}

UpdateDeploymentStack is the request payload item for updating the deployment status.

func (UpdateDeploymentStack) Validate

func (d UpdateDeploymentStack) Validate() error

Validate the UpdateDeploymentStack object.

type UpdateDeploymentStacks

type UpdateDeploymentStacks struct {
	Stacks []UpdateDeploymentStack `json:"stacks"`
}

UpdateDeploymentStacks is the request payload for updating the deployment status.

func (UpdateDeploymentStacks) Validate

func (ds UpdateDeploymentStacks) Validate() error

Validate the list of UpdateDeploymentStack.

type User

type User struct {
	Email       string `json:"email"`
	DisplayName string `json:"display_name"`
	JobTitle    string `json:"job_title"`
	IDPUserID   string `json:"idp_user_id"`
}

User represents the signed in user information.

func (User) Validate

func (u User) Validate() error

Validate if the user has the Terramate CLI required fields.

Directories

Path Synopsis
Package deployment provides types and helpers for cloud deployments.
Package deployment provides types and helpers for cloud deployments.
Package stack provides types and helpers for cloud stacks.
Package stack provides types and helpers for cloud stacks.
Package testserver provides fake Terramate Cloud endpoints for testing purposes.
Package testserver provides fake Terramate Cloud endpoints for testing purposes.
cmd/fakecloud
Package main implements the cloudmock service.
Package main implements the cloudmock service.

Jump to

Keyboard shortcuts

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