Documentation ¶
Index ¶
- Constants
- func CTSCommand(t *testing.T, configPath string, opts ...string) (*exec.Cmd, *bytes.Buffer, int)
- func CheckStatusCodeCategory(category int, statusCode int) bool
- func WaitForEvent(t *testing.T, client *Client, taskName string, start time.Time, ...)
- type API
- type Client
- func NewClient(c *ClientConfig, httpClient httpClient) (*Client, error)
- func RunCTS(t *testing.T, configPath string, opts ...string) (*Client, func(t *testing.T))
- func StartCTS(t *testing.T, configPath string, opts ...string) (*Client, func(t *testing.T))
- func StartCTSSecure(t *testing.T, configPath string, tlsConfig TLSConfig, opts ...string) (*Client, func(t *testing.T))
- type ClientConfig
- type Config
- type EnabledSummary
- type ErrorObject
- type ErrorResponse
- type Handlers
- type HealthHandler
- type InspectPlan
- type Interceptor
- type OverallStatus
- type QueryParam
- type Server
- type StatusClient
- type StatusHandler
- type StatusHandlerDefault
- type StatusSummary
- type TLSConfig
- type TaskClient
- type TaskLifeCycleHandler
- func (h *TaskLifeCycleHandler) CreateTask(w http.ResponseWriter, r *http.Request, params oapigen.CreateTaskParams)
- func (h *TaskLifeCycleHandler) DeleteTaskByName(w http.ResponseWriter, r *http.Request, name string)
- func (h *TaskLifeCycleHandler) GetAllTasks(w http.ResponseWriter, r *http.Request)
- func (h *TaskLifeCycleHandler) GetTaskByName(w http.ResponseWriter, r *http.Request, name string)
- type TaskLifecycleClient
- type TaskLifecycleHTTPClient
- type TaskRequest
- type TaskResponse
- type TaskStatus
- type TaskSummary
- type TasksResponse
- type UpdateTaskConfig
- type UpdateTaskResponse
Constants ¶
const ( // StatusSuccessful is the successful status. This is determined based on status // type. // // Task Status: Determined by the success of a task updating. The 5 most // recent task updates are stored as an ‘event’ in CTS. A task is successful // when the most recent stored event is successful. StatusSuccessful = "successful" // StatusErrored is the errored status. This is determined based on status // type. // // Task Status: Determined by the success of a task updating. The 5 most // recent task updates are stored as an ‘event’ in CTS. A task is errored // when the most recent stored event is not successful but all prior stored // events are successful. StatusErrored = "errored" // StatusCritical is the critical status. This is determined based on status // type. // // Task Status: Determined by the success of a task updating. The 5 most // recent task updates are stored as an ‘event’ in CTS. A task is critical // when the most recent stored event is not successful and at least one prior // stored event is all not successful. StatusCritical = "critical" // StatusUnknown is when the status is unknown. This is determined // based on status type. // // Task Status: Determined by the success of a task updating. The 5 most // recent task updates are stored as an ‘event’ in CTS. A task is // unknown when no event data has been collected yet. StatusUnknown = "unknown" )
const ( HTTPScheme = "http" HTTPSScheme = "https" DefaultURL = "http://localhost:8558" DefaultSSLVerify = true // Environment variable names EnvAddress = "CTS_ADDRESS" // The address of the CTS daemon, supports http or https by specifying as part of the address (e.g. https://localhost:8558) // TLS environment variable names EnvTLSCACert = "CTS_CACERT" // Path to a directory of CA certificates to use for TLS when communicating with Consul-Terraform-Sync EnvTLSCAPath = "CTS_CAPATH" // Path to a CA file to use for TLS when communicating with Consul-Terraform-Sync EnvTLSClientCert = "CTS_CLIENT_CERT" // Path to a client cert file to use for TLS when verify_incoming is enabled EnvTLSClientKey = "CTS_CLIENT_KEY" // Path to a client key file to use for TLS when verify_incoming is enabled EnvTLSSSLVerify = "CTS_SSL_VERIFY" // Boolean to verify SSL or not. Set to true to verify SSL. Default is true )
const ( ClientErrorResponseCategory = 4 // category for http status codes from 400-499 ServerErrorResponseCategory = 5 // category for http status codes from 500-599 )
const ( RunOptionInspect = "inspect" RunOptionNow = "now" )
const ( // CTSOnceModeFlag is an optional flag to run CTS CTSOnceModeFlag = "-once" // CTSDevModeFlag is an optional flag to run CTS with development client CTSDevModeFlag = "--client-type=development" // CTSInspectFlag is an optional flag to run CTS in inspect mode CTSInspectFlag = "-inspect" )
Variables ¶
This section is empty.
Functions ¶
func CTSCommand ¶ added in v0.7.0
CTSCommand constructs the command to start CTS, sets the command to output to a buffer, and modifies the configuration file to use a free port for the CTS API. It does not execute the command.
func CheckStatusCodeCategory ¶ added in v0.6.0
CheckStatusCodeCategory checks if a given status code matches a particular category. It does this by taking the first digit of a category (i.e. 4 for 400, 401, etc.) and checking if the first digit of the status code matches. E.g. category = 4, statusCode = 401 CheckStatusCodeCategory returns true
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API supports api requests to the cts binary
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client to make api requests
func NewClient ¶
func NewClient(c *ClientConfig, httpClient httpClient) (*Client, error)
NewClient returns a client to make api requests
func RunCTS ¶ added in v0.7.0
RunCTS executes the CTS from binary and returns a function to stop CTS. If running once-mode, the function will block until complete so no need to use stop function
func StartCTS ¶ added in v0.1.3
StartCTS executes the CTS binary with the "start" subcommand and returns a function to stop CTS. If running once-mode, the function will block until complete so no need to use stop function
func StartCTSSecure ¶ added in v0.4.2
func StartCTSSecure(t *testing.T, configPath string, tlsConfig TLSConfig, opts ...string) (*Client, func(t *testing.T))
StartCTSSecure executes the CTS binary with the "start" subcommand using the https scheme for connections and returns a function to stop CTS. If running once-mode, the function will block until complete so no need to use stop function
func (*Client) FullAddress ¶ added in v0.4.2
FullAddress returns the client address including the scheme. E.g. http://localhost:8558
func (*Client) Status ¶
func (c *Client) Status() *StatusClient
Status returns a handle to the status endpoints
func (*Client) Task ¶
func (c *Client) Task() *TaskClient
Task returns a handle to the task endpoints
func (*Client) WaitForTestReadiness ¶ added in v0.6.0
WaitForTestReadiness is used by tests that start CTS to determine how long to wait until CTS is in a state to be tested. Currently this is determined by when all enabled tasks have been run once by polling the /v1/status/tasks endpoint. Tasks that have not run will have an unknown status. This should only be use if no runtime changes are being actively made.
Note: this does not wait for disabled tasks to initialize. Tests that start up with only a disabled task and then modify the disabled tasks will need to add an extra wait. This can be fixed after we support more task status information e.g. task initialization.
type ClientConfig ¶
ClientConfig configures the client to make api requests
func BaseClientConfig ¶ added in v0.5.0
func BaseClientConfig() *ClientConfig
BaseClientConfig returns a base configuration for the client using defaults and env var values
type Config ¶ added in v0.5.0
type Config struct { Port int TLS *config.CTSTLSConfig Controller Server Health health.Checker Interceptor Interceptor StatusHandler StatusHandler }
Config is used to configure the API
type EnabledSummary ¶
EnabledSummary is the count of how many tasks are enabled vs. disabled
type ErrorObject ¶
type ErrorObject struct {
Message string `json:"message"`
}
ErrorObject is the object to represent an error object from the API server
type ErrorResponse ¶
type ErrorResponse struct {
Error *ErrorObject `json:"error,omitempty"`
}
ErrorResponse is the object to represent an error response from the API server
func NewErrorResponse ¶
func NewErrorResponse(err error) ErrorResponse
NewErrorResponse creates a new API response for an error
func (ErrorResponse) ErrorMessage ¶
func (resp ErrorResponse) ErrorMessage() (string, bool)
ErrorMessage returns the error message if there is an error.
type Handlers ¶ added in v0.5.0
type Handlers struct { *TaskLifeCycleHandler *HealthHandler StatusHandler }
Handlers is composed of CTS server handlers which allows the handler to adhere to the generated server interface
type HealthHandler ¶ added in v0.6.0
type HealthHandler struct {
// contains filtered or unexported fields
}
HealthHandler handles the health endpoints
func NewHealthHandler ¶ added in v0.6.0
func NewHealthHandler(hc health.Checker) *HealthHandler
NewHealthHandler creates a new health handler using the provided health manager to determine health
func (*HealthHandler) GetHealth ¶ added in v0.6.0
func (hh *HealthHandler) GetHealth(w http.ResponseWriter, r *http.Request)
GetHealth returns the health status Logging is explicitly left out of this method to avoid flooding the logs as this endpoint is expected to be hit often by external entities
type InspectPlan ¶ added in v0.5.0
type Interceptor ¶ added in v0.7.0
type Interceptor interface { ShouldIntercept(*http.Request) bool Intercept(http.ResponseWriter, *http.Request) }
Interceptor is an interface for determining when a request needs to be intercepted and how that request handled instead.
type OverallStatus ¶
type OverallStatus struct {
TaskSummary TaskSummary `json:"task_summary"`
}
OverallStatus is the overall status information for cts and across all the tasks
type QueryParam ¶
QueryParam sets query parameters for the api client
func (*QueryParam) Encode ¶
func (q *QueryParam) Encode() string
Encode returns QueryParameter values as a URL encoded string. No preceding '?' e.g. "include=events&status=critical"
type Server ¶ added in v0.5.0
type Server interface { Config() config.Config Events(ctx context.Context, taskName string) (map[string][]event.Event, error) Task(ctx context.Context, taskName string) (config.TaskConfig, error) TaskCreate(context.Context, config.TaskConfig) (config.TaskConfig, error) TaskCreateAndRun(context.Context, config.TaskConfig) (config.TaskConfig, error) TaskDelete(ctx context.Context, taskName string) error // TODO: update signatures to return a new run object TaskInspect(context.Context, config.TaskConfig) (bool, string, string, error) // TODO: update signature with an update config object since only a subset of // options can be changed and determine the location of sharable objects // across packages TaskUpdate(ctx context.Context, updateConf config.TaskConfig, runOp string) (bool, string, string, error) Tasks(context.Context) config.TaskConfigs }
Server represents the Controller methods used for the API server
type StatusClient ¶ added in v0.5.0
type StatusClient struct {
*Client
}
StatusClient can be used to query the status endpoints
func (*StatusClient) Overall ¶ added in v0.5.0
func (s *StatusClient) Overall() (OverallStatus, error)
Overall is used to query for overall status
func (*StatusClient) Task ¶ added in v0.5.0
func (s *StatusClient) Task(name string, q *QueryParam) (map[string]TaskStatus, error)
Task is used to query for task status(es).
name: task name or empty string for all tasks q: nil if no query parameters
type StatusHandler ¶ added in v0.7.0
type StatusHandler interface {
GetClusterStatus(w http.ResponseWriter, r *http.Request)
}
StatusHandler is an interface for handling all status related endpoints
type StatusHandlerDefault ¶ added in v0.7.0
type StatusHandlerDefault struct{}
StatusHandlerDefault is the default status handler
func (StatusHandlerDefault) GetClusterStatus ¶ added in v0.7.0
func (StatusHandlerDefault) GetClusterStatus(w http.ResponseWriter, r *http.Request)
GetClusterStatus returns an error message that this endpoint is not supported by non HA configured CTS instances
type StatusSummary ¶
type StatusSummary struct { Successful int `json:"successful"` Errored int `json:"errored"` Critical int `json:"critical"` Unknown int `json:"unknown"` }
StatusSummary is the count of how many tasks have which status
type TaskClient ¶ added in v0.5.0
type TaskClient struct {
*Client
}
TaskClient can be used to query the task endpoints
func (*TaskClient) Update ¶ added in v0.5.0
func (t *TaskClient) Update(name string, config UpdateTaskConfig, q *QueryParam) (UpdateTaskResponse, error)
Update is used to patch update task
type TaskLifeCycleHandler ¶ added in v0.5.0
type TaskLifeCycleHandler struct {
// contains filtered or unexported fields
}
func NewTaskLifeCycleHandler ¶ added in v0.5.0
func NewTaskLifeCycleHandler(ctrl Server) *TaskLifeCycleHandler
func (*TaskLifeCycleHandler) CreateTask ¶ added in v0.5.0
func (h *TaskLifeCycleHandler) CreateTask(w http.ResponseWriter, r *http.Request, params oapigen.CreateTaskParams)
CreateTask creates a task
func (*TaskLifeCycleHandler) DeleteTaskByName ¶ added in v0.5.0
func (h *TaskLifeCycleHandler) DeleteTaskByName(w http.ResponseWriter, r *http.Request, name string)
DeleteTaskByName deletes an existing task and its events asynchronously. Does not delete until the task is inactive and not running.
func (*TaskLifeCycleHandler) GetAllTasks ¶ added in v0.6.0
func (h *TaskLifeCycleHandler) GetAllTasks(w http.ResponseWriter, r *http.Request)
GetAllTasks retrieves all tasks currently managed by CTS, and returns their information
func (*TaskLifeCycleHandler) GetTaskByName ¶ added in v0.5.0
func (h *TaskLifeCycleHandler) GetTaskByName(w http.ResponseWriter, r *http.Request, name string)
GetTaskByName retrieves a task's information by the task's name
type TaskLifecycleClient ¶ added in v0.5.0
type TaskLifecycleClient struct { *oapigen.ClientWithResponses // contains filtered or unexported fields }
TaskLifecycleClient defines a client for task lifecycle requests Currently non task lifecycle requests use the client in api/client.go, but eventually all endpoint may use this new client. In that case TaskLifecycleClient should be renamed
func NewTaskLifecycleClient ¶ added in v0.5.0
func NewTaskLifecycleClient(c *ClientConfig, httpClient httpClient) (*TaskLifecycleClient, error)
NewTaskLifecycleClient returns a client to make api requests
func (*TaskLifecycleClient) Scheme ¶ added in v0.5.0
func (c *TaskLifecycleClient) Scheme() string
Scheme returns the scheme being used by the client
type TaskLifecycleHTTPClient ¶ added in v0.5.0
type TaskLifecycleHTTPClient struct {
// contains filtered or unexported fields
}
TaskLifecycleHTTPClient is an httpClient for task life cycle requests and allows for wrapping the base http.Do function
func NewTaskLifecycleHTTPClient ¶ added in v0.5.0
func NewTaskLifecycleHTTPClient(httpClient httpClient) *TaskLifecycleHTTPClient
NewTaskLifecycleHTTPClient creates a new http client wrapper around the passed httpClient
type TaskRequest ¶ added in v0.5.0
type TaskRequest oapigen.TaskRequest
TaskRequest is a wrapper around the generated TaskRequest this allows for the task request to be extended
func TaskRequestFromTaskConfig ¶ added in v0.5.0
func TaskRequestFromTaskConfig(tc config.TaskConfig) TaskRequest
TaskRequestFromTaskConfig converts a taskRequest object to a Config TaskConfig object.
func (TaskRequest) String ¶ added in v0.5.0
func (tr TaskRequest) String() string
String writes out the task request in an easily readable way useful for logging
func (TaskRequest) ToTaskConfig ¶ added in v0.5.0
func (tr TaskRequest) ToTaskConfig() (config.TaskConfig, error)
ToTaskConfig converts a TaskRequest object to a Config TaskConfig object.
type TaskResponse ¶ added in v0.5.0
type TaskResponse oapigen.TaskResponse
func (TaskResponse) String ¶ added in v0.5.0
func (tresp TaskResponse) String() string
type TaskStatus ¶
type TaskStatus struct { TaskName string `json:"task_name"` Status string `json:"status"` Enabled bool `json:"enabled"` EventsURL string `json:"events_url"` Events []event.Event `json:"events,omitempty"` // Providers and Services are deprecated in v0.5. These are configuration // details about the task rather than status information. Users should // switch to using the Get Task API to request the task's provider and // services (and more!) information. // - Providers should be removed in 0.8 // - Services should be removed in a future major release after 0.8 to align // with the removal of CTS config task.services Providers []string `json:"providers"` Services []string `json:"services"` }
TaskStatus is the status for a single task
type TaskSummary ¶
type TaskSummary struct { Status StatusSummary `json:"status"` Enabled EnabledSummary `json:"enabled"` }
TaskSummary holds data that summarizes the tasks configured with CTS
type TasksResponse ¶ added in v0.6.0
type TasksResponse oapigen.TasksResponse
type UpdateTaskConfig ¶
type UpdateTaskConfig struct {
Enabled *bool `mapstructure:"enabled"`
}
UpdateTaskConfig contains the fields available for patch updating a task. Not all task configuration is available for update
type UpdateTaskResponse ¶
type UpdateTaskResponse struct {
Inspect *InspectPlan `json:"inspect,omitempty"`
}