Documentation
¶
Overview ¶
Package http provides an HTTP interface allowing HTTP clients to interact with OTF.
Index ¶
- Constants
- func Absolute(r *http.Request, path string) string
- func ExternalHost(r *http.Request) string
- func GetClientIP(r *http.Request) (string, error)
- func GetHealthz(w http.ResponseWriter, r *http.Request)
- func SanitizeAddress(address string) (string, error)
- func SanitizeHostname(hostname string) (string, error)
- type AgentToken
- type Client
- func (c *Client) CreateAgentToken(ctx context.Context, options otf.CreateAgentTokenOptions) (*otf.AgentToken, error)
- func (c *Client) CreateOrganization(ctx context.Context, options otf.OrganizationCreateOptions) (*otf.Organization, error)
- func (c *Client) CreateWorkspace(ctx context.Context, opts otf.CreateWorkspaceOptions) (*otf.Workspace, error)
- func (c *Client) Do(ctx context.Context, req *retryablehttp.Request, v interface{}) error
- func (c *Client) DownloadConfig(ctx context.Context, cvID string) ([]byte, error)
- func (c *Client) FinishPhase(ctx context.Context, id string, phase otf.PhaseType, ...) (*otf.Run, error)
- func (c *Client) GetAgentToken(ctx context.Context, token string) (*otf.AgentToken, error)
- func (c *Client) GetLockFile(ctx context.Context, runID string) ([]byte, error)
- func (c *Client) GetPlanFile(ctx context.Context, runID string, format otf.PlanFormat) ([]byte, error)
- func (c *Client) GetRun(ctx context.Context, runID string) (*otf.Run, error)
- func (c *Client) GetWorkspace(ctx context.Context, workspaceID string) (*otf.Workspace, error)
- func (c *Client) GetWorkspaceByName(ctx context.Context, organization, workspace string) (*otf.Workspace, error)
- func (c *Client) Hostname() string
- func (c *Client) ListRuns(ctx context.Context, opts otf.RunListOptions) (*otf.RunList, error)
- func (c *Client) ListWorkspaces(ctx context.Context, options otf.WorkspaceListOptions) (*otf.WorkspaceList, error)
- func (c *Client) LockWorkspace(ctx context.Context, workspaceID string, opts otf.WorkspaceLockOptions) (*otf.Workspace, error)
- func (c *Client) NewRequest(method, path string, v interface{}) (*retryablehttp.Request, error)
- func (c *Client) PutChunk(ctx context.Context, chunk otf.Chunk) error
- func (c *Client) RetryServerErrors(retry bool)
- func (c *Client) StartPhase(ctx context.Context, id string, phase otf.PhaseType, ...) (*otf.Run, error)
- func (c *Client) UnlockWorkspace(ctx context.Context, workspaceID string, _ otf.WorkspaceUnlockOptions) (*otf.Workspace, error)
- func (c *Client) UpdateWorkspace(ctx context.Context, workspaceID string, options otf.UpdateWorkspaceOptions) (*otf.Workspace, error)
- func (c *Client) UploadLockFile(ctx context.Context, runID string, lockfile []byte) error
- func (c *Client) UploadPlanFile(ctx context.Context, runID string, plan []byte, format otf.PlanFormat) error
- func (c *Client) Watch(ctx context.Context, opts otf.WatchOptions) (<-chan otf.Event, error)
- type ClientFactory
- type Config
- type ConfigOption
- type ConfigurationVersion
- type ConfigurationVersionList
- type Entitlements
- type Healthz
- type Organization
- type OrganizationList
- type RetryLogHook
- type Route
- type Router
- func (r *Router) DEL(path string, h http.HandlerFunc) *mux.Route
- func (r *Router) GET(path string, h http.HandlerFunc) *mux.Route
- func (r *Router) Headers(pairs ...string) *Route
- func (r *Router) PST(path string, h http.HandlerFunc) *mux.Route
- func (r *Router) PTC(path string, h http.HandlerFunc) *mux.Route
- func (r *Router) PUT(path string, h http.HandlerFunc) *mux.Route
- func (r *Router) PathPrefix(prefix string) *Route
- func (r *Router) Sub(group func(r *Router))
- type Run
- type RunList
- type Server
- func (s *Server) ApplyRun(w http.ResponseWriter, r *http.Request)
- func (s *Server) CancelRun(w http.ResponseWriter, r *http.Request)
- func (s *Server) CreateAgentToken(w http.ResponseWriter, r *http.Request)
- func (s *Server) CreateConfigurationVersion(w http.ResponseWriter, r *http.Request)
- func (s *Server) CreateOrganization(w http.ResponseWriter, r *http.Request)
- func (s *Server) CreateRun(w http.ResponseWriter, r *http.Request)
- func (s *Server) CreateWorkspace(w http.ResponseWriter, r *http.Request)
- func (s *Server) DeleteOrganization(w http.ResponseWriter, r *http.Request)
- func (s *Server) DeleteWorkspace(w http.ResponseWriter, r *http.Request)
- func (s *Server) DeleteWorkspaceByName(w http.ResponseWriter, r *http.Request)
- func (s *Server) DiscardRun(w http.ResponseWriter, r *http.Request)
- func (s *Server) DownloadConfigurationVersion(w http.ResponseWriter, r *http.Request)
- func (s *Server) ForceCancelRun(w http.ResponseWriter, r *http.Request)
- func (s *Server) GetApply(w http.ResponseWriter, r *http.Request)
- func (s *Server) GetConfigurationVersion(w http.ResponseWriter, r *http.Request)
- func (s *Server) GetCurrentAgent(w http.ResponseWriter, r *http.Request)
- func (s *Server) GetCurrentUser(w http.ResponseWriter, r *http.Request)
- func (s *Server) GetEntitlements(w http.ResponseWriter, r *http.Request)
- func (s *Server) GetOrganization(w http.ResponseWriter, r *http.Request)
- func (s *Server) GetRun(w http.ResponseWriter, r *http.Request)
- func (s *Server) GetRunsQueue(w http.ResponseWriter, r *http.Request)
- func (s *Server) GetWorkspace(w http.ResponseWriter, r *http.Request)
- func (s *Server) GetWorkspaceByName(w http.ResponseWriter, r *http.Request)
- func (s *Server) ListConfigurationVersions(w http.ResponseWriter, r *http.Request)
- func (s *Server) ListOrganizations(w http.ResponseWriter, r *http.Request)
- func (s *Server) ListRuns(w http.ResponseWriter, r *http.Request)
- func (s *Server) ListWorkspaces(w http.ResponseWriter, r *http.Request)
- func (s *Server) LockWorkspace(w http.ResponseWriter, r *http.Request)
- func (s *Server) Start(ctx context.Context, ln net.Listener) (err error)
- func (s *Server) UnlockWorkspace(w http.ResponseWriter, r *http.Request)
- func (s *Server) UpdateOrganization(w http.ResponseWriter, r *http.Request)
- func (s *Server) UpdateWorkspace(w http.ResponseWriter, r *http.Request)
- func (s *Server) UpdateWorkspaceByName(w http.ResponseWriter, r *http.Request)
- func (s *Server) UploadConfigurationVersion() http.HandlerFunc
- func (s *Server) WellKnown(w http.ResponseWriter, r *http.Request)
- type ServerConfig
- type Signer
- type User
- type Verifier
- type WebRoute
- type WellKnown
- type Workspace
- type WorkspaceList
Constants ¶
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" )
const (
DefaultAddress = "localhost:8080"
)
Variables ¶
This section is empty.
Functions ¶
func Absolute ¶ added in v0.0.19
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
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
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
SanitizeAddress ensures address is in format https://<host>:<port>
func SanitizeHostname ¶ added in v0.0.8
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 (*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 (*Client) Do ¶ added in v0.0.27
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
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 (*Client) GetAgentToken ¶ added in v0.0.27
func (*Client) GetLockFile ¶ added in v0.0.27
func (*Client) GetPlanFile ¶ added in v0.0.27
func (*Client) GetWorkspace ¶ added in v0.0.27
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) 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 (*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) RetryServerErrors ¶ added in v0.0.27
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 (*Client) UnlockWorkspace ¶ added in v0.0.27
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 (*Client) UploadPlanFile ¶ added in v0.0.27
type ClientFactory ¶ added in v0.0.8
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 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 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
RetryLogHook allows a function to run before each retry.
type Route ¶ added in v0.0.12
Route wraps mux's Route, adding various helper methods
func (*Route) PathPrefix ¶ added in v0.0.12
type Router ¶ added in v0.0.12
Router wraps mux's Router, adding various helper methods
func (*Router) DEL ¶ added in v0.0.12
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) PST ¶ added in v0.0.12
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
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) PathPrefix ¶ added in v0.0.12
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) 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) 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) 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) 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) 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
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
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 Workspace ¶ added in v0.0.8
type Workspace struct { otf.Application *otf.Workspace // contains filtered or unexported fields }
Workspace assembles a workspace JSONAPI DTO
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
Source Files
¶
- agent_token.go
- agent_token_client.go
- apply.go
- client.go
- client_config.go
- client_factory.go
- configuration_version.go
- configuration_version_client.go
- configuration_version_test_helper.go
- events.go
- events_client.go
- healthz.go
- http.go
- log_client.go
- logs.go
- middleware.go
- middleware_test_helper.go
- module.go
- organization.go
- organization_client.go
- plan.go
- router.go
- run.go
- run_client.go
- server.go
- signed_urls.go
- test_helpers.go
- user.go
- well_known.go
- workspace.go
- workspace_client.go
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 |