http

package
v0.0.28 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: MPL-2.0 Imports: 36 Imported by: 0

Documentation

Overview

Package http provides an HTTP interface allowing HTTP clients to interact with OTF.

Index

Constants

View Source
const (

	// DefaultBasePath on which the API is served.
	DefaultBasePath = "/api/v2/"
	// PingEndpoint is a no-op API endpoint used to configure the rate limiter
	PingEndpoint = "ping"
)
View Source
const (
	DefaultAddress = "localhost:8080"
)

Variables

This section is empty.

Functions

func Absolute added in v0.0.19

func Absolute(r *http.Request, path string) string

Absolute returns an absolute URL for the given path. It uses the http request to determine the correct hostname and scheme to use. Handles situations where otf is sitting behind a reverse proxy, using the X-Forwarded-* headers the proxy sets.

func ExternalHost added in v0.0.19

func ExternalHost(r *http.Request) string

ExternalHost uses the incoming HTTP request to determine the host:port on which this server can be reached externally by clients and the internet.

func GetClientIP added in v0.0.21

func GetClientIP(r *http.Request) (string, error)

GetClientIP gets the client's IP address

func GetHealthz added in v0.0.12

func GetHealthz(w http.ResponseWriter, r *http.Request)

func SanitizeAddress added in v0.0.8

func SanitizeAddress(address string) (string, error)

SanitizeAddress ensures address is in format https://<host>:<port>

func SanitizeHostname added in v0.0.8

func SanitizeHostname(hostname string) (string, error)

SanitizeHostname ensures hostname is in the format <host>:<port>

Types

type AgentToken added in v0.0.12

type AgentToken struct {
	*otf.AgentToken
	// contains filtered or unexported fields
}

func (*AgentToken) ToJSONAPI added in v0.0.12

func (t *AgentToken) ToJSONAPI() any

ToJSONAPI assembles a JSON-API DTO.

type Client added in v0.0.8

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

func NewClient added in v0.0.27

func NewClient(config Config) (*Client, error)

func (*Client) CreateAgentToken added in v0.0.27

func (c *Client) CreateAgentToken(ctx context.Context, options otf.CreateAgentTokenOptions) (*otf.AgentToken, error)

func (*Client) CreateOrganization added in v0.0.27

func (c *Client) CreateOrganization(ctx context.Context, options otf.OrganizationCreateOptions) (*otf.Organization, error)

CreateOrganization creates a new organization with the given options.

func (*Client) CreateWorkspace added in v0.0.27

func (c *Client) CreateWorkspace(ctx context.Context, opts otf.CreateWorkspaceOptions) (*otf.Workspace, error)

func (*Client) Do added in v0.0.27

func (c *Client) Do(ctx context.Context, req *retryablehttp.Request, v interface{}) error

Do sends an API request and returns the API response. The API response is JSONAPI decoded and the document's primary data is stored in the value pointed to by v, or returned as an error if an API error has occurred.

If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it.

The provided ctx must be non-nil. If it is canceled or times out, ctx.Err() will be returned.

func (*Client) DownloadConfig added in v0.0.27

func (c *Client) DownloadConfig(ctx context.Context, cvID string) ([]byte, error)

DownloadConfig downloads a configuration version tarball. Only configuration versions in the uploaded state may be downloaded.

func (*Client) FinishPhase added in v0.0.27

func (c *Client) FinishPhase(ctx context.Context, id string, phase otf.PhaseType, opts otf.PhaseFinishOptions) (*otf.Run, error)

func (*Client) GetAgentToken added in v0.0.27

func (c *Client) GetAgentToken(ctx context.Context, token string) (*otf.AgentToken, error)

func (*Client) GetLockFile added in v0.0.27

func (c *Client) GetLockFile(ctx context.Context, runID string) ([]byte, error)

func (*Client) GetPlanFile added in v0.0.27

func (c *Client) GetPlanFile(ctx context.Context, runID string, format otf.PlanFormat) ([]byte, error)

func (*Client) GetRun added in v0.0.27

func (c *Client) GetRun(ctx context.Context, runID string) (*otf.Run, error)

func (*Client) GetWorkspace added in v0.0.27

func (c *Client) GetWorkspace(ctx context.Context, workspaceID string) (*otf.Workspace, error)

GetWorkspace retrieves a workspace by its ID

func (*Client) GetWorkspaceByName added in v0.0.27

func (c *Client) GetWorkspaceByName(ctx context.Context, organization, workspace string) (*otf.Workspace, error)

GetWorkspaceByName retrieves a workspace by organization and name.

func (*Client) Hostname added in v0.0.27

func (c *Client) Hostname() string

Hostname returns the server host:port.

func (*Client) ListRuns added in v0.0.27

func (c *Client) ListRuns(ctx context.Context, opts otf.RunListOptions) (*otf.RunList, error)

func (*Client) ListWorkspaces added in v0.0.27

func (c *Client) ListWorkspaces(ctx context.Context, options otf.WorkspaceListOptions) (*otf.WorkspaceList, error)

func (*Client) LockWorkspace added in v0.0.27

func (c *Client) LockWorkspace(ctx context.Context, workspaceID string, opts otf.WorkspaceLockOptions) (*otf.Workspace, error)

func (*Client) NewRequest added in v0.0.27

func (c *Client) NewRequest(method, path string, v interface{}) (*retryablehttp.Request, error)

NewRequest creates an API request with proper headers and serialization.

A relative URL path can be provided, in which case it is resolved relative to the baseURL of the Client. Relative URL paths should always be specified without a preceding slash. Adding a preceding slash allows for ignoring the configured baseURL for non-standard endpoints.

If v is supplied, the value will be JSONAPI encoded and included as the request body. If the method is GET, the value will be parsed and added as query parameters.

func (*Client) PutChunk added in v0.0.27

func (c *Client) PutChunk(ctx context.Context, chunk otf.Chunk) error

func (*Client) RetryServerErrors added in v0.0.27

func (c *Client) RetryServerErrors(retry bool)

RetryServerErrors configures the retry HTTP check to also retry unexpected errors or requests that failed with a server error.

func (*Client) StartPhase added in v0.0.27

func (c *Client) StartPhase(ctx context.Context, id string, phase otf.PhaseType, opts otf.PhaseStartOptions) (*otf.Run, error)

func (*Client) UnlockWorkspace added in v0.0.27

func (c *Client) UnlockWorkspace(ctx context.Context, workspaceID string, _ otf.WorkspaceUnlockOptions) (*otf.Workspace, error)

func (*Client) UpdateWorkspace added in v0.0.27

func (c *Client) UpdateWorkspace(ctx context.Context, workspaceID string, options otf.UpdateWorkspaceOptions) (*otf.Workspace, error)

UpdateWorkspace updates the settings of an existing workspace.

func (*Client) UploadLockFile added in v0.0.27

func (c *Client) UploadLockFile(ctx context.Context, runID string, lockfile []byte) error

func (*Client) UploadPlanFile added in v0.0.27

func (c *Client) UploadPlanFile(ctx context.Context, runID string, plan []byte, format otf.PlanFormat) error

func (*Client) Watch added in v0.0.27

func (c *Client) Watch(ctx context.Context, opts otf.WatchOptions) (<-chan otf.Event, error)

type ClientFactory added in v0.0.8

type ClientFactory interface {
	NewClient() (otf.Client, error)
}

ClientFactory implementations of capable of constructing new OTF clients

type Config added in v0.0.8

type Config struct {
	// The address of the Terraform Enterprise API.
	Address string
	// The base path on which the API is served.
	BasePath string
	// API token used to access the Terraform Enterprise API.
	Token string
	// Headers that will be added to every request.
	Headers http.Header
	// A custom HTTP client to use.
	HTTPClient *http.Client
	// RetryLogHook is invoked each time a request is retried.
	RetryLogHook RetryLogHook
	// contains filtered or unexported fields
}

Config provides configuration details to the API client.

func NewConfig added in v0.0.8

func NewConfig(opts ...ConfigOption) (*Config, error)

NewConfig constructs a new http client config. Options are only applied when NewClient() is called.

type ConfigOption added in v0.0.8

type ConfigOption func(*Config) error

type ConfigurationVersion added in v0.0.8

type ConfigurationVersion struct {
	*otf.ConfigurationVersion
	*Server
}

func (*ConfigurationVersion) ToJSONAPI added in v0.0.12

func (cv *ConfigurationVersion) ToJSONAPI() any

ToJSONAPI assembles a JSONAPI DTO.

type ConfigurationVersionList added in v0.0.8

type ConfigurationVersionList struct {
	*otf.ConfigurationVersionList
	*Server
}

func (*ConfigurationVersionList) ToJSONAPI added in v0.0.12

func (l *ConfigurationVersionList) ToJSONAPI() any

ToJSONAPI assembles a JSONAPI DTO

type Entitlements added in v0.0.12

type Entitlements struct {
	*otf.Entitlements
}

func (*Entitlements) ToJSONAPI added in v0.0.12

func (e *Entitlements) ToJSONAPI() any

ToJSONAPI assembles a JSONAPI DTO

type Healthz added in v0.0.12

type Healthz struct {
	Version string
	Commit  string
	Built   string
}

type Organization added in v0.0.8

type Organization struct {
	*otf.Organization
}

func (*Organization) ToJSONAPI added in v0.0.12

func (org *Organization) ToJSONAPI() any

ToJSONAPI assembles a JSONAPI DTO

type OrganizationList added in v0.0.8

type OrganizationList struct {
	*otf.OrganizationList
}

func (*OrganizationList) ToJSONAPI added in v0.0.12

func (l *OrganizationList) ToJSONAPI() any

ToJSONAPI assembles a JSON-API DTO.

type RetryLogHook added in v0.0.8

type RetryLogHook func(attemptNum int, resp *http.Response)

RetryLogHook allows a function to run before each retry.

type Route added in v0.0.12

type Route struct {
	*mux.Route
}

Route wraps mux's Route, adding various helper methods

func (*Route) PathPrefix added in v0.0.12

func (r *Route) PathPrefix(prefix string) *Route

func (*Route) Sub added in v0.0.12

func (r *Route) Sub(group func(r *Router))

Sub turns mux into chi (almost)

type Router added in v0.0.12

type Router struct {
	*mux.Router
}

Router wraps mux's Router, adding various helper methods

func NewRouter

func NewRouter() *Router

func (*Router) DEL added in v0.0.12

func (r *Router) DEL(path string, h http.HandlerFunc) *mux.Route

DEL is a helper method for a mux handler with a delete method. Shortened name so that it lines up nicely with get when reading the routing code.

func (*Router) GET added in v0.0.12

func (r *Router) GET(path string, h http.HandlerFunc) *mux.Route

GET is a helper method for a mux handler with a GET method

func (*Router) Headers added in v0.0.12

func (r *Router) Headers(pairs ...string) *Route

func (*Router) PST added in v0.0.12

func (r *Router) PST(path string, h http.HandlerFunc) *mux.Route

PST is a helper method for a mux handler with a post method. Shortened to PST so that it lines up nicely with get when reading the routing code.

func (*Router) PTC added in v0.0.12

func (r *Router) PTC(path string, h http.HandlerFunc) *mux.Route

PTC is a helper method for a mux handler with a patch method. Shortened name so that it lines up nicely with get when reading the routing code.

func (*Router) PUT added in v0.0.12

func (r *Router) PUT(path string, h http.HandlerFunc) *mux.Route

PUT is a helper method for a mux handler with a PUT method.

func (*Router) PathPrefix added in v0.0.12

func (r *Router) PathPrefix(prefix string) *Route

func (*Router) Sub added in v0.0.12

func (r *Router) Sub(group func(r *Router))

Sub turns mux into chi (almost)

type Run added in v0.0.8

type Run struct {
	*otf.Run

	*Server
	// contains filtered or unexported fields
}

func (*Run) ToJSONAPI added in v0.0.12

func (r *Run) ToJSONAPI() any

ToJSONAPI assembles a JSON-API DTO.

type RunList added in v0.0.8

type RunList struct {
	*otf.RunList

	*Server
	// contains filtered or unexported fields
}

func (*RunList) ToJSONAPI added in v0.0.12

func (l *RunList) ToJSONAPI() any

ToJSONAPI assembles a JSON-API DTO.

type Server

type Server struct {
	logr.Logger
	otf.Application // provides access to otf services
	ServerConfig
	*Router      // http router, exported so that other pkgs can add routes
	*surl.Signer // sign and validate signed URLs
	// contains filtered or unexported fields
}

Server provides an HTTP/S server

func NewServer

func NewServer(logger logr.Logger, cfg ServerConfig, app otf.Application, db otf.DB, stateService otf.StateVersionService, variableService otf.VariableService, registrySessionService otf.RegistrySessionService) (*Server, error)

NewServer is the constructor for Server

func (*Server) ApplyRun

func (s *Server) ApplyRun(w http.ResponseWriter, r *http.Request)

func (*Server) CancelRun

func (s *Server) CancelRun(w http.ResponseWriter, r *http.Request)

func (*Server) CreateAgentToken added in v0.0.12

func (s *Server) CreateAgentToken(w http.ResponseWriter, r *http.Request)

func (*Server) CreateConfigurationVersion

func (s *Server) CreateConfigurationVersion(w http.ResponseWriter, r *http.Request)

func (*Server) CreateOrganization

func (s *Server) CreateOrganization(w http.ResponseWriter, r *http.Request)

func (*Server) CreateRun

func (s *Server) CreateRun(w http.ResponseWriter, r *http.Request)

func (*Server) CreateWorkspace

func (s *Server) CreateWorkspace(w http.ResponseWriter, r *http.Request)

func (*Server) DeleteOrganization

func (s *Server) DeleteOrganization(w http.ResponseWriter, r *http.Request)

func (*Server) DeleteWorkspace

func (s *Server) DeleteWorkspace(w http.ResponseWriter, r *http.Request)

func (*Server) DeleteWorkspaceByName added in v0.0.21

func (s *Server) DeleteWorkspaceByName(w http.ResponseWriter, r *http.Request)

func (*Server) DiscardRun

func (s *Server) DiscardRun(w http.ResponseWriter, r *http.Request)

func (*Server) DownloadConfigurationVersion added in v0.0.12

func (s *Server) DownloadConfigurationVersion(w http.ResponseWriter, r *http.Request)

func (*Server) ForceCancelRun

func (s *Server) ForceCancelRun(w http.ResponseWriter, r *http.Request)

func (*Server) GetApply

func (s *Server) GetApply(w http.ResponseWriter, r *http.Request)

func (*Server) GetConfigurationVersion

func (s *Server) GetConfigurationVersion(w http.ResponseWriter, r *http.Request)

func (*Server) GetCurrentAgent added in v0.0.12

func (s *Server) GetCurrentAgent(w http.ResponseWriter, r *http.Request)

func (*Server) GetCurrentUser added in v0.0.12

func (s *Server) GetCurrentUser(w http.ResponseWriter, r *http.Request)

func (*Server) GetEntitlements

func (s *Server) GetEntitlements(w http.ResponseWriter, r *http.Request)

func (*Server) GetOrganization

func (s *Server) GetOrganization(w http.ResponseWriter, r *http.Request)

func (*Server) GetRun

func (s *Server) GetRun(w http.ResponseWriter, r *http.Request)

func (*Server) GetRunsQueue added in v0.0.12

func (s *Server) GetRunsQueue(w http.ResponseWriter, r *http.Request)

func (*Server) GetWorkspace

func (s *Server) GetWorkspace(w http.ResponseWriter, r *http.Request)

func (*Server) GetWorkspaceByName added in v0.0.21

func (s *Server) GetWorkspaceByName(w http.ResponseWriter, r *http.Request)

func (*Server) ListConfigurationVersions

func (s *Server) ListConfigurationVersions(w http.ResponseWriter, r *http.Request)

func (*Server) ListOrganizations

func (s *Server) ListOrganizations(w http.ResponseWriter, r *http.Request)

func (*Server) ListRuns

func (s *Server) ListRuns(w http.ResponseWriter, r *http.Request)

func (*Server) ListWorkspaces

func (s *Server) ListWorkspaces(w http.ResponseWriter, r *http.Request)

func (*Server) LockWorkspace

func (s *Server) LockWorkspace(w http.ResponseWriter, r *http.Request)

func (*Server) Start added in v0.0.19

func (s *Server) Start(ctx context.Context, ln net.Listener) (err error)

Start starts serving http traffic on the given listener and waits until the server exits due to error or the context is cancelled.

func (*Server) UnlockWorkspace

func (s *Server) UnlockWorkspace(w http.ResponseWriter, r *http.Request)

func (*Server) UpdateOrganization

func (s *Server) UpdateOrganization(w http.ResponseWriter, r *http.Request)

func (*Server) UpdateWorkspace

func (s *Server) UpdateWorkspace(w http.ResponseWriter, r *http.Request)

UpdateWorkspace updates a workspace using its ID.

TODO: support updating workspace's vcs repo.

func (*Server) UpdateWorkspaceByName added in v0.0.21

func (s *Server) UpdateWorkspaceByName(w http.ResponseWriter, r *http.Request)

UpdateWorkspaceByName updates a workspace using its name and organization.

TODO: support updating workspace's vcs repo.

func (*Server) UploadConfigurationVersion

func (s *Server) UploadConfigurationVersion() http.HandlerFunc

func (*Server) WellKnown

func (s *Server) WellKnown(w http.ResponseWriter, r *http.Request)

type ServerConfig added in v0.0.12

type ServerConfig struct {
	SSL                  bool
	CertFile, KeyFile    string
	EnableRequestLogging bool
	SiteToken            string // site admin token
	Secret               string // Secret for signing
	MaxConfigSize        int64  // Maximum permitted config upload size in bytes
}

ServerConfig is the http server config

func (*ServerConfig) Validate added in v0.0.12

func (cfg *ServerConfig) Validate() error

type Signer added in v0.0.12

type Signer interface {
	Sign(string, time.Duration) (string, error)
}

Signer is capable of signing URLs with a limited lifespan.

type User added in v0.0.8

type User struct {
	*otf.User
}

func (*User) ToJSONAPI added in v0.0.12

func (u *User) ToJSONAPI() any

ToJSONAPI assembles a JSON-API DTO.

type Verifier added in v0.0.12

type Verifier interface {
	Verify(string) error
}

Verifier is capable of verifying signed URLs

type WebRoute

type WebRoute string

type WellKnown

type WellKnown struct {
	ModulesV1  string `json:"modules.v1"`
	MotdV1     string `json:"motd.v1"`
	StateV2    string `json:"state.v2"`
	TfeV2      string `json:"tfe.v2"`
	TfeV21     string `json:"tfe.v2.1"`
	TfeV22     string `json:"tfe.v2.2"`
	VersionsV1 string `json:"versions.v1"`
}

type Workspace added in v0.0.8

type Workspace struct {
	otf.Application
	*otf.Workspace
	// contains filtered or unexported fields
}

Workspace assembles a workspace JSONAPI DTO

func (*Workspace) ToJSONAPI added in v0.0.12

func (ws *Workspace) ToJSONAPI() any

type WorkspaceList added in v0.0.8

type WorkspaceList struct {
	otf.Application
	*otf.WorkspaceList
	// contains filtered or unexported fields
}

WorkspaceList assembles a workspace list JSONAPI DTO

func (*WorkspaceList) ToJSONAPI added in v0.0.12

func (l *WorkspaceList) ToJSONAPI() any

Directories

Path Synopsis
Package decode contains decoders for various HTTP artefacts
Package decode contains decoders for various HTTP artefacts
Package html provides the otf web app, serving up HTML formatted pages and associated assets (CSS, JS, etc).
Package html provides the otf web app, serving up HTML formatted pages and associated assets (CSS, JS, etc).
paths
Package paths provides rails-style path helpers for use with the web app.
Package paths provides rails-style path helpers for use with the web app.
Package jsonapi handles marshaling/unmarshaling into/from json-api
Package jsonapi handles marshaling/unmarshaling into/from json-api

Jump to

Keyboard shortcuts

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