api

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2021 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
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"
)

Variables

This section is empty.

Functions

func FreePort

func FreePort() (int, error)

FreePort finds the next free port incrementing upwards. Use for testing.

Types

type API

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

API supports api requests to the cts binary

func NewAPI

func NewAPI(store *event.Store, drivers *driver.Drivers, port int) *API

NewAPI create a new API object

func (*API) Serve

func (api *API) Serve(ctx context.Context) error

Serve starts up and handles shutdown for the http server to serve API requests

type Client

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

Client to make api requests

func NewClient

func NewClient(c *ClientConfig, httpClient httpClient) *Client

NewClient returns a client to make api requests

func (*Client) Status

func (c *Client) Status() *Status

Status returns a handle to the status endpoints

func (*Client) Task

func (c *Client) Task() *Task

Task returns a handle to the task endpoints

type ClientConfig

type ClientConfig struct {
	Port int
}

ClientConfig configures the client to make api requests

type EnabledSummary

type EnabledSummary struct {
	True  int `json:"true"`
	False int `json:"false"`
}

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 OverallStatus

type OverallStatus struct {
	TaskSummary TaskSummary `json:"task_summary"`
}

OverallStatus is the overall status information for cts and across all the tasks

type QueryParam

type QueryParam struct {
	IncludeEvents bool
	Status        string
	Run           string
}

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 Status

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

Status can be used to query the status endpoints

func (*Status) Overall

func (s *Status) Overall() (OverallStatus, error)

Overall is used to query for overall status

func (*Status) Task

func (s *Status) 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 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 Task

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

Task can be used to query the task endpoints

func (*Task) Update

func (t *Task) Update(name string, config UpdateTaskConfig, q *QueryParam) (UpdateTaskResponse, error)

Update is used to patch update task

type TaskStatus

type TaskStatus struct {
	TaskName  string        `json:"task_name"`
	Status    string        `json:"status"`
	Enabled   bool          `json:"enabled"`
	Providers []string      `json:"providers"`
	Services  []string      `json:"services"`
	EventsURL string        `json:"events_url"`
	Events    []event.Event `json:"events,omitempty"`
}

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 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 *driver.InspectPlan `json:"inspect,omitempty"`
}

Jump to

Keyboard shortcuts

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