cloud

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package cloud provides types for use with cloud providers.

Index

Constants

View Source
const (
	Github = "github"
	Gitlab = "gitlab"
)
View Source
const (
	VCSEventTypePull VCSEventType = iota
	VCSEventTypePush
	VCSEventTypeTag

	VCSActionCreated VCSAction = iota
	VCSActionDeleted
	VCSActionMerged
	VCSActionUpdated
)

Variables

This section is empty.

Functions

func NewTestModuleRepo

func NewTestModuleRepo(provider, name string) string

func NewTestRepo

func NewTestRepo() string

Types

type Client

type Client interface {
	// GetCurrentUser retrieves the current user
	GetCurrentUser(ctx context.Context) (User, error)
	// ListRepositories lists repositories accessible to the current user.
	ListRepositories(ctx context.Context, opts ListRepositoriesOptions) ([]string, error)
	GetRepository(ctx context.Context, identifier string) (Repository, error)
	// GetRepoTarball retrieves a .tar.gz tarball of a git repository
	GetRepoTarball(ctx context.Context, opts GetRepoTarballOptions) ([]byte, string, 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, id string, 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)
	// ListPullRequestFiles returns the paths of files that are modified in the pull request
	ListPullRequestFiles(ctx context.Context, repo string, pull int) ([]string, error)
	// GetCommit retrieves commit from the repo with the given git ref
	GetCommit(ctx context.Context, repo, ref string) (Commit, 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 Commit added in v0.1.8

type Commit struct {
	SHA    string
	URL    string
	Author CommitAuthor
}

type CommitAuthor added in v0.1.8

type CommitAuthor struct {
	Username   string
	ProfileURL string
	AvatarURL  string
}

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 {
	Repo     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 {
	Repo 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, secret string) *VCSEvent
}

EventHandler handles incoming events

type GetRepoTarballOptions

type GetRepoTarballOptions struct {
	Repo string  // repo identifier, <owner>/<repo>
	Ref  *string // branch/tag/SHA ref, nil means default branch
}

type GetWebhookOptions

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

GetWebhookOptions are options for retrieving a webhook.

type Kind added in v0.1.8

type Kind string

Kind is the kind of cloud provider, e.g. github, gitlab, etc.

type ListRepositoriesOptions

type ListRepositoriesOptions struct {
	PageSize int
}

type ListTagsOptions

type ListTagsOptions struct {
	Repo   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 OIDCConfig

type OIDCConfig struct {
	// Name is the user-friendly identifier of the oidc endpoint.
	Name string
	// IssuerURL is the issuer url for the oidc provider.
	IssuerURL string
	// RedirectURL is the redirect url for the oidc provider.
	RedirectURL string
	// ClientID is the client id for the oidc provider.
	ClientID string
	// ClientSecret is the client secret for the oidc provider.
	ClientSecret string
	// Skip TLS Verification when communicating with issuer.
	SkipTLSVerification bool
	// Scopes to request from the oidc provider.
	Scopes []string
	// UsernameClaim is the claim that provides the username.
	UsernameClaim string
}

OIDCConfig is the configuration for a generic oidc provider.

type Repository added in v0.1.8

type Repository struct {
	Path          string
	DefaultBranch string
}

type Service

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

type SetStatusOptions

type SetStatusOptions struct {
	Workspace   string // workspace name
	Repo        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 UpdateWebhookOptions

type UpdateWebhookOptions CreateWebhookOptions

type User

type User struct {
	Name string
}

User is a user account on a cloud provider.

type VCSAction added in v0.1.4

type VCSAction int

type VCSEvent

type VCSEvent struct {
	//
	// These fields are populated by the generic webhook handler
	//
	RepoID        uuid.UUID
	VCSProviderID string
	RepoPath      string

	//
	// These fields are populated by cloud-specific handlers
	//
	Cloud Kind

	Type          VCSEventType
	Action        VCSAction
	Tag           string
	CommitSHA     string
	CommitURL     string
	Branch        string // head branch
	DefaultBranch string

	PullRequestNumber int
	PullRequestURL    string
	PullRequestTitle  string

	SenderUsername  string
	SenderAvatarURL string
	SenderHTMLURL   string

	// Paths of files that have been added/modified/removed. Only applicable
	// to Push and Tag events types.
	Paths []string
}

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

type VCSEventType

type VCSEventType int

type VCSStatus

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

type Webhook

type Webhook struct {
	ID       string // cloud's webhook ID
	Repo     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.

Jump to

Keyboard shortcuts

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