cloud

package
v0.4.2-rc2 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2023 License: MPL-2.0 Imports: 16 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 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) 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 DeploymentMetadata added in v0.4.1

type DeploymentMetadata GitHubMetadata

DeploymentMetadata stores the metadata available in the target platform. For now, we only support GitHub 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 DriftStackPayloadRequest added in v0.4.2

type DriftStackPayloadRequest struct {
	Stack    Stack               `json:"stack"`
	Status   stack.Status        `json:"drift_status"`
	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 GitHubMetadata added in v0.4.1

type GitHubMetadata struct {
	Platform                    string `json:"platform"`
	PullRequestAuthorLogin      string `json:"pull_request_author_login,omitempty"`
	PullRequestAuthorAvatarURL  string `json:"pull_request_author_avatar_url,omitempty"`
	PullRequestAuthorGravatarID string `json:"pull_request_author_gravatar_id,omitempty"`

	PullRequestHeadLabel            string `json:"pull_request_head_label,omitempty"`
	PullRequestHeadRef              string `json:"pull_request_head_ref,omitempty"`
	PullRequestHeadSHA              string `json:"pull_request_head_sha,omitempty"`
	PullRequestHeadAuthorLogin      string `json:"pull_request_head_author_login,omitempty"`
	PullRequestHeadAuthorAvatarURL  string `json:"pull_request_head_author_avatar_url,omitempty"`
	PullRequestHeadAuthorGravatarID string `json:"pull_request_head_author_gravatar_id,omitempty"`

	PullRequestBaseLabel            string `json:"pull_request_base_label,omitempty"`
	PullRequestBaseRef              string `json:"pull_request_base_ref,omitempty"`
	PullRequestBaseSHA              string `json:"pull_request_base_sha,omitempty"`
	PullRequestBaseAuthorLogin      string `json:"pull_request_base_author_login,omitempty"`
	PullRequestBaseAuthorAvatarURL  string `json:"pull_request_base_author_avatar_url,omitempty"`
	PullRequestBaseAuthorGravatarID string `json:"pull_request_base_author_gravatar_id,omitempty"`

	PullRequestCreatedAt *time.Time `json:"pull_request_created_at,omitempty"`
	PullRequestUpdatedAt *time.Time `json:"pull_request_updated_at,omitempty"`
	PullRequestClosedAt  *time.Time `json:"pull_request_closed_at,omitempty"`
	PullRequestMergedAt  *time.Time `json:"pull_request_merged_at,omitempty"`

	DeploymentBranch string `json:"deployment_branch,omitempty"`

	DeploymentCommitVerified       *bool  `json:"deployment_commit_verified,omitempty"`
	DeploymentCommitVerifiedReason string `json:"deployment_commit_verified_reason,omitempty"`

	DeploymentCommitSHA         string `json:"deployment_commit_sha,omitempty"`
	DeploymentCommitTitle       string `json:"deployment_commit_title,omitempty"`
	DeploymentCommitDescription string `json:"deployment_commit_description,omitempty"`

	DeploymentCommitAuthorLogin      string     `json:"deployment_commit_author_login,omitempty"`
	DeploymentCommitAuthorAvatarURL  string     `json:"deployment_commit_author_avatar_url,omitempty"`
	DeploymentCommitAuthorGravatarID string     `json:"deployment_commit_author_gravatar_id,omitempty"`
	DeploymentCommitAuthorGitName    string     `json:"deployment_commit_author_git_name,omitempty"`
	DeploymentCommitAuthorGitEmail   string     `json:"deployment_commit_author_git_email,omitempty"`
	DeploymentCommitAuthorGitDate    *time.Time `json:"deployment_commit_author_git_date,omitempty"`

	DeploymentCommitCommitterLogin      string     `json:"deployment_commit_committer_login,omitempty"`
	DeploymentCommitCommitterAvatarURL  string     `json:"deployment_commit_committer_avatar_url,omitempty"`
	DeploymentCommitCommitterGravatarID string     `json:"deployment_commit_committer_gravatar_id,omitempty"`
	DeploymentCommitCommitterGitName    string     `json:"deployment_commit_committer_git_name,omitempty"`
	DeploymentCommitCommitterGitEmail   string     `json:"deployment_commit_committer_git_email,omitempty"`
	DeploymentCommitCommitterGitDate    *time.Time `json:"deployment_commit_committer_git_date,omitempty"`

	DeploymentTriggeredBy string `json:"deployment_triggered_by,omitempty"`
}

GitHubMetadata stores the GitHub related metadata.

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"`
	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 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