cloud

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2023 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package cloud provides types for use with cloud providers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	GetUser(ctx context.Context) (*User, error)
	// ListRepositories lists repositories accessible to the current user.
	ListRepositories(ctx context.Context, opts ListRepositoriesOptions) ([]Repo, error)
	GetRepository(ctx context.Context, identifier string) (Repo, error)
	// GetRepoTarball retrieves a .tar.gz tarball of a git repository
	GetRepoTarball(ctx context.Context, opts GetRepoTarballOptions) ([]byte, error)
	// CreateWebhook creates a webhook on the cloud provider, returning the
	// provider's unique ID for the webhook.
	CreateWebhook(ctx context.Context, opts CreateWebhookOptions) (string, error)
	UpdateWebhook(ctx context.Context, opts UpdateWebhookOptions) error
	GetWebhook(ctx context.Context, opts GetWebhookOptions) (Webhook, error)
	DeleteWebhook(ctx context.Context, opts DeleteWebhookOptions) error
	SetStatus(ctx context.Context, opts SetStatusOptions) error
	// ListTags lists git tags on a repository. Each tag should be prefixed with
	// 'tags/'.
	ListTags(ctx context.Context, opts ListTagsOptions) ([]string, error)
}

type ClientOptions

type ClientOptions struct {
	Hostname            string
	SkipTLSVerification bool

	Credentials
}

ClientOptions are options for constructing a cloud client

type Cloud

type Cloud interface {
	NewClient(context.Context, ClientOptions) (Client, error)
	EventHandler
}

Cloud is an external provider of various cloud services e.g. identity provider, VCS repositories etc.

type CloudOAuthConfig

type CloudOAuthConfig struct {
	Config
	OAuthConfig *oauth2.Config
}

CloudOAuthConfig is the configuration for a cloud provider and its OAuth configuration.

type Config

type Config struct {
	Name                string
	Hostname            string
	SkipTLSVerification bool

	Cloud
}

Config is configuration for a cloud provider

func (*Config) HTTPClient

func (cfg *Config) HTTPClient() *http.Client

func (*Config) NewClient

func (cfg *Config) NewClient(ctx context.Context, creds Credentials) (Client, error)

func (Config) String

func (cfg Config) String() string

type CreateWebhookOptions

type CreateWebhookOptions struct {
	Identifier string // repo identifier, <owner>/<repo>
	Secret     string // secret string for generating signature
	Endpoint   string // otf's external-facing host[:port]
	Events     []VCSEventType
}

type Credentials

type Credentials struct {
	// tokens are mutually-exclusive - at least one must be specified
	OAuthToken    *oauth2.Token
	PersonalToken *string
}

Credentials are credentials for a cloud client

type DeleteWebhookOptions

type DeleteWebhookOptions struct {
	Identifier string // Repository identifier, <owner>/<repo>
	ID         string // vcs' webhook ID
}

DeleteWebhookOptions are options for deleting a webhook.

type EventHandler

type EventHandler interface {
	// HandleEvent extracts a cloud-specific event from the http request, converting it into a
	// VCS event. Returns nil if the event is to be ignored.
	HandleEvent(w http.ResponseWriter, r *http.Request, opts HandleEventOptions) VCSEvent
}

EventHandler handles incoming events

type GetRepoTarballOptions

type GetRepoTarballOptions struct {
	Identifier string // repo identifier, <owner>/<repo>
	Ref        string // branch/tag/SHA ref
}

type GetWebhookOptions

type GetWebhookOptions struct {
	Identifier string // Repository identifier, <owner>/<repo>
	ID         string // vcs' webhook ID
}

GetWebhookOptions are options for retrieving a webhook.

type HandleEventOptions

type HandleEventOptions struct {
	Secret    string
	WebhookID uuid.UUID
}

type ListRepositoriesOptions

type ListRepositoriesOptions struct {
	PageSize int
}

type ListTagsOptions

type ListTagsOptions struct {
	Identifier string // repo identifier, <owner>/<repo>
	Prefix     string // only list tags that start with this string
}

ListTagsOptions are options for listing tags on a vcs repository

type OAuthConfigs

type OAuthConfigs []*CloudOAuthConfig

func (OAuthConfigs) Configs

func (cfgs OAuthConfigs) Configs() []Config

Configs returns the list of cloud configs from a list of cloud oauth configs

type Repo

type Repo struct {
	Identifier string `schema:"identifier,required"` // <repo_owner>/<repo_name>
	Branch     string `schema:"branch,required"`     // default branch
}

Repo is a VCS repository belonging to a cloud

func NewTestModuleRepo

func NewTestModuleRepo(provider, name string) Repo

func NewTestRepo

func NewTestRepo() Repo

func (Repo) ID

func (r Repo) ID() string

type Service

type Service interface {
	GetCloudConfig(name string) (Config, error)
	ListCloudConfigs() []Config
}

type SetStatusOptions

type SetStatusOptions struct {
	Workspace   string
	Identifier  string // <owner>/<repo>
	Ref         string // git ref
	Status      VCSStatus
	TargetURL   string
	Description string
}

SetStatusOptions are options for setting a status on a VCS repo

type Team

type Team struct {
	Name         string
	Organization string // team belongs to an organization
}

Team is a team account on a cloud provider.

type UpdateWebhookOptions

type UpdateWebhookOptions struct {
	ID string // vcs' webhook ID

	CreateWebhookOptions
}

type User

type User struct {
	Name string

	Organizations []string // org memberships
	Teams         []Team   // team memberships
}

User is a user account on a cloud provider.

type VCSEvent

type VCSEvent any

VCSEvent is a VCS event received from a cloud, e.g. a commit event from github

type VCSEventType

type VCSEventType int
const (
	VCSPullEventType VCSEventType = iota
	VCSPushEventType
)

type VCSPullEvent

type VCSPullEvent struct {
	WebhookID  uuid.UUID
	Action     VCSPullEventAction
	Identifier string // repo identifier, <owner>/<repo>
	CommitSHA  string
	Branch     string // head branch
}

VCSPullEvent occurs when an action is carried out on a pull request

type VCSPullEventAction

type VCSPullEventAction string
const (
	VCSPullEventOpened  VCSPullEventAction = "opened"
	VCSPullEventClosed  VCSPullEventAction = "closed" // closed without merging
	VCSPullEventMerged  VCSPullEventAction = "merged"
	VCSPullEventUpdated VCSPullEventAction = "updated"
)

type VCSPushEvent

type VCSPushEvent struct {
	WebhookID  uuid.UUID
	Identifier string // repo identifier, <owner>/<repo>
	CommitSHA  string
	Branch     string
}

VCSPushEvent occurs when a commit is pushed to a repo.

type VCSStatus

type VCSStatus string
const (
	VCSPendingStatus VCSStatus = "pending"
	VCSRunningStatus VCSStatus = "running"
	VCSSuccessStatus VCSStatus = "success"
	VCSErrorStatus   VCSStatus = "error"
	VCSFailureStatus VCSStatus = "failure"
)

type VCSTagEvent

type VCSTagEvent struct {
	WebhookID  uuid.UUID
	Identifier string // repo identifier, <owner>/<repo>
	CommitSHA  string
	Tag        string
	Action     VCSTagEventAction
}

VCSTagEvent occurs when a tag is created or deleted on a repo.

type VCSTagEventAction

type VCSTagEventAction string
const (
	VCSTagEventCreatedAction VCSTagEventAction = "created"
	VCSTagEventDeletedAction VCSTagEventAction = "deleted"
)

type Webhook

type Webhook struct {
	ID         string // vcs' ID
	Identifier string // identifier is <repo_owner>/<repo_name>
	Events     []VCSEventType
	Endpoint   string // the OTF URL that receives events
}

Webhook is a cloud's configuration for a webhook on OTF.

Jump to

Keyboard shortcuts

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