http

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2022 License: MPL-2.0 Imports: 35 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 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   int
}

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 {
	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
	*signer.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) 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) 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) 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) 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) 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) Open

func (s *Server) Open(ctx context.Context) (err error)

Open begins listening on the bind address and waits until 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)

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 {
	// Listening Address in the form <ip>:<port>
	Addr                 string
	SSL                  bool
	CertFile, KeyFile    string
	EnableRequestLogging bool
	// site admin token
	SiteToken string
	// Secret for signing
	Secret string
}

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 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).

Jump to

Keyboard shortcuts

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