http

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2021 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeQuery

func DecodeQuery(opts interface{}, query url.Values) error

DecodeQuery unmarshals a query string (k1=v1&k2=v2...) into a struct.

func MarshalPayload

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

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

func NewRouter

func NewRouter(server *Server) *negroni.Negroni

NewRouter constructs a negroni-wrapped HTTP router

func WithCode

func WithCode(code int) func(w http.ResponseWriter)

WithCode is a helper func for writing an HTTP status code to a response stream. For use with WriteResponse.

func WriteError

func WriteError(w http.ResponseWriter, code int, err error)

WriteError writes an HTTP response with a JSON-API marshalled error obj.

func WriteResponse

func WriteResponse(w http.ResponseWriter, r *http.Request, obj interface{}, opts ...func(http.ResponseWriter))

WriteResponse writes an HTTP response with a JSON-API marshalled payload.

Types

type Server

type Server struct {
	logr.Logger

	SSL               bool
	CertFile, KeyFile string

	// Listening Address in the form <ip>:<port>
	Addr string

	// Hostname, used within absolute URL links, defaults to localhost
	Hostname string

	OrganizationService         otf.OrganizationService
	WorkspaceService            otf.WorkspaceService
	StateVersionService         otf.StateVersionService
	ConfigurationVersionService otf.ConfigurationVersionService
	RunService                  otf.RunService
	PlanService                 otf.PlanService
	ApplyService                otf.ApplyService
	// contains filtered or unexported fields
}

Server provides an HTTP/S server

func NewServer

func NewServer() *Server

NewServer is the contructor for Server

func (*Server) ApplyJSONAPIObject

func (s *Server) ApplyJSONAPIObject(a *otf.Apply) *tfe.Apply

ApplyJSONAPIObject converts a Apply to a struct that can be marshalled into a JSON-API object

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

func (s *Server) Close() error

Close gracefully shuts down the server.

func (*Server) ConfigurationVersionJSONAPIObject

func (s *Server) ConfigurationVersionJSONAPIObject(cv *otf.ConfigurationVersion) *tfe.ConfigurationVersion

ConfigurationVersionJSONAPIObject converts a ConfigurationVersion to a struct that can be marshalled into a JSON-API object

func (*Server) ConfigurationVersionListJSONAPIObject

func (s *Server) ConfigurationVersionListJSONAPIObject(cvl *otf.ConfigurationVersionList) *tfe.ConfigurationVersionList

ConfigurationVersionListJSONAPIObject converts a ConfigurationVersionList to a struct that can be marshalled into a JSON-API object

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

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

func (*Server) DiscardRun

func (s *Server) DiscardRun(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) GetApplyLogs

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

func (*Server) GetConfigurationVersion

func (s *Server) GetConfigurationVersion(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) GetPlan

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

func (*Server) GetPlanJSON

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

func (*Server) GetPlanLogs

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

func (*Server) GetRun

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

func (*Server) GetRunPlanJSON

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

func (*Server) GetStateVersion

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

func (*Server) GetURL

func (s *Server) GetURL(route WebRoute, param ...interface{}) string

GetURL returns an absolute URL corresponding to the given route and params

func (*Server) GetWorkspace

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

func (*Server) GetWorkspaceByID

func (s *Server) GetWorkspaceByID(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() (err error)

Open validates the server options and begins listening on the bind address.

func (*Server) OrganizationJSONAPIObject

func (s *Server) OrganizationJSONAPIObject(org *otf.Organization) *tfe.Organization

OrganizationJSONAPIObject converts a Organization to a struct that can be marshalled into a JSON-API object

func (*Server) OrganizationListJSONAPIObject

func (s *Server) OrganizationListJSONAPIObject(cvl *otf.OrganizationList) *tfe.OrganizationList

OrganizationListJSONAPIObject converts a OrganizationList to a struct that can be marshalled into a JSON-API object

func (*Server) PlanJSONAPIObject

func (s *Server) PlanJSONAPIObject(p *otf.Plan) *tfe.Plan

PlanJSONAPIObject converts a Plan to a struct that can be marshalled into a JSON-API object

func (*Server) Port

func (s *Server) Port() int

Port returns the TCP port for the running server. This is useful in tests where we allocate a random port by using ":0".

func (*Server) RunJSONAPIObject

func (s *Server) RunJSONAPIObject(r *otf.Run) *tfe.Run

RunJSONAPIObject converts a Run to a struct that can be marshalled into a JSON-API object

func (*Server) RunListJSONAPIObject

func (s *Server) RunListJSONAPIObject(cvl *otf.RunList) *tfe.RunList

RunListJSONAPIObject converts a RunList to a struct that can be marshalled into a JSON-API object

func (*Server) StateVersionJSONAPIObject

func (s *Server) StateVersionJSONAPIObject(r *otf.StateVersion) *tfe.StateVersion

StateVersionJSONAPIObject converts a StateVersion to a struct that can be marshalled into a JSON-API object

func (*Server) StateVersionListJSONAPIObject

func (s *Server) StateVersionListJSONAPIObject(cvl *otf.StateVersionList) *tfe.StateVersionList

StateVersionListJSONAPIObject converts a StateVersionList to a struct that can be marshalled into a JSON-API object

func (*Server) StateVersionOutputJSONAPIObject

func (s *Server) StateVersionOutputJSONAPIObject(svo *otf.StateVersionOutput) *tfe.StateVersionOutput

StateVersionOutputJSONAPIObject converts a StateVersionOutput to a struct that can be marshalled into a JSON-API object

func (*Server) StateVersionOutputListJSONAPIObject

func (s *Server) StateVersionOutputListJSONAPIObject(svol otf.StateVersionOutputList) []*tfe.StateVersionOutput

StateVersionOutputListJSONAPIObject converts a StateVersionOutputList to a struct that can be marshalled into a JSON-API object

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

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

func (*Server) UploadConfigurationVersion

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

func (*Server) UploadLogs

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

func (*Server) Wait

func (s *Server) Wait(ctx context.Context) error

Wait blocks until server stops listening or context is cancelled.

func (*Server) WellKnown

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

func (*Server) WorkspaceJSONAPIObject

func (s *Server) WorkspaceJSONAPIObject(ws *otf.Workspace) *tfe.Workspace

WorkspaceJSONAPIObject converts a Workspace to a struct that can be marshalled into a JSON-API object

func (*Server) WorkspaceListJSONAPIObject

func (s *Server) WorkspaceListJSONAPIObject(cvl *otf.WorkspaceList) *tfe.WorkspaceList

WorkspaceListJSONAPIObject converts a WorkspaceList to a struct that can be marshalled into a JSON-API object

type WebRoute

type WebRoute string
const (
	// ShutdownTimeout is the time given for outstanding requests to finish
	// before shutdown.
	ShutdownTimeout = 1 * time.Second

	UploadConfigurationVersionRoute WebRoute = "/configuration-versions/%v/upload"
	GetPlanLogsRoute                WebRoute = "/plans/%v/logs"
	GetApplyLogsRoute               WebRoute = "/applies/%v/logs"
)

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"`
}

Jump to

Keyboard shortcuts

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