cloud

package
v0.4.1-rc3 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2023 License: MPL-2.0 Imports: 13 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"
)
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 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) MemberOrganizations

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

MemberOrganizations returns all organizations which are associated with the user.

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 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 {
	CommitSHA         string   `json:"commit_sha,omitempty"`
	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"`
	DeploymentURL     string   `json:"deployment_url,omitempty"`
	DeploymentStatus  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      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"`
}

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 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 {
	ID              int      `json:"stack_id"`
	Repository      string   `json:"repository"`
	Path            string   `json:"path"`
	MetaID          string   `json:"meta_id"`
	MetaName        string   `json:"meta_name"`
	MetaDescription string   `json:"meta_description"`
	MetaTags        []string `json:"meta_tags"`
	Status          Status   `json:"status"`

	// readonly fields
	CreatedAt int `json:"created_at"`
	UpdatedAt int `json:"updated_at"`
	SeenAt    int `json:"seen_at"`
}

Stack represents a stack in the Terramate Cloud.

func (Stack) Validate

func (stack Stack) Validate() error

Validate the stack entity.

type Status

type Status int

Status of a stack or deployment

const (
	Unknown  Status = iota // Unknown status is used for newly created stacks, which never ran.
	Pending                // Pending status
	Running                // Running status indicates the stack is running.
	OK                     // OK status is used when the stack ran successfully.
	Drifted                // Drifted status is used when a stack definition is different from that of the current status.
	Failed                 // Failed status indicates the deployment of the stack failed.
	Canceled               // Canceled indicates the deployment of the stack was canceled.

)

func (Status) MarshalJSON

func (s Status) MarshalJSON() ([]byte, error)

MarshalJSON implements the Marshaller interface.

func (Status) String

func (s Status) String() string

String representation of the status.

func (*Status) UnmarshalJSON

func (s *Status) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the Unmarshaller interface.

func (Status) Validate

func (s Status) Validate() error

Validate the status.

type UpdateDeploymentStack

type UpdateDeploymentStack struct {
	StackID int    `json:"stack_id"`
	Status  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 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