http

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2023 License: MPL-2.0 Imports: 38 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 GetHealthz added in v0.0.12

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

func MarshalPayload

func MarshalPayload(w io.Writer, r *http.Request, models interface{}) error

MarshalPayload marshals the models object into a JSON-API response.

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
}

func (*AgentToken) ToJSONAPI added in v0.0.12

func (t *AgentToken) ToJSONAPI() any

ToJSONAPI assembles a JSON-API DTO.

type AnsiStripper added in v0.0.11

type AnsiStripper struct {
	io.Reader
}

AnsiStripper strips ANSI codes and makes the stripped output available via Read()

func NewAnsiStripper added in v0.0.11

func NewAnsiStripper(input io.Reader) *AnsiStripper

NewAnsiStripper constructs an ANSI stripper, stripping ANSI codes from the input stream.

type Client added in v0.0.8

type Client interface {
	otf.Application
}

Client implements all the application services, for client-side usage.

type ClientFactory added in v0.0.8

type ClientFactory interface {
	NewClient() (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.

func (*Config) NewClient added in v0.0.8

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

NewClient creates a new Terraform Enterprise API client.

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 RegistrySession added in v0.0.19

type RegistrySession struct {
	*otf.RegistrySession
}

func (*RegistrySession) ToJSONAPI added in v0.0.19

func (t *RegistrySession) 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 {
	ServerConfig

	logr.Logger

	// provides access to otf services
	otf.Application

	CacheService *bigcache.BigCache

	// the http router, exported so that other pkgs can add routes
	*Router
	*surl.Signer
	// 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, cache *bigcache.BigCache) (*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) CreateRegistrySession added in v0.0.19

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

func (*Server) CreateRun

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

func (*Server) CreateStateVersion

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

func (*Server) CreateVariable added in v0.0.20

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

func (*Server) CreateWorkspace

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

func (*Server) CurrentStateVersion

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

func (*Server) DeleteOrganization

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

func (*Server) DeleteVariable added in v0.0.20

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

func (*Server) DeleteWorkspace

func (s *Server) DeleteWorkspace(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) DownloadStateVersion

func (s *Server) DownloadStateVersion(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) GetStateVersion

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

func (*Server) GetVariable added in v0.0.20

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

func (*Server) GetWorkspace

func (s *Server) GetWorkspace(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) ListStateVersions

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

func (*Server) ListVariables added in v0.0.20

func (s *Server) ListVariables(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) UpdateVariable added in v0.0.20

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

func (*Server) UpdateWorkspace

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

UpdateWorkspace updates a workspace.

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 StateVersion added in v0.0.8

type StateVersion struct {
	*otf.StateVersion
}

func (*StateVersion) ToJSONAPI added in v0.0.12

func (sv *StateVersion) ToJSONAPI() any

ToJSONAPI assembles a JSON-API DTO.

type StateVersionList added in v0.0.8

type StateVersionList struct {
	*otf.StateVersionList
}

func (*StateVersionList) ToJSONAPI added in v0.0.12

func (l *StateVersionList) ToJSONAPI() any

ToJSONAPI assembles a JSON-API DTO.

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 Variable added in v0.0.20

type Variable struct {
	*otf.Variable
}

Variable assembles a workspace JSONAPI DTO

func (*Variable) ToJSONAPI added in v0.0.20

func (v *Variable) ToJSONAPI() any

type VariableList added in v0.0.20

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

VariableList assembles a workspace list JSONAPI DTO

func (*VariableList) ToJSONAPI added in v0.0.20

func (l *VariableList) ToJSONAPI() any

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 dto provides DTO models for serialization/deserialization to/from JSON-API
Package dto provides DTO models for serialization/deserialization to/from JSON-API
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.

Jump to

Keyboard shortcuts

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