api

package
v1.13.1 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2018 License: BSD-3-Clause, ISC Imports: 11 Imported by: 1

Documentation

Overview

Package api provides a client for using the sloppy.io API.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingAccessToken = errors.New(`Missing "SLOPPY_APITOKEN", please login by exporting your token https://admin.sloppy.io/account/tokens`)
)

Functions

func Bool

func Bool(v bool) *bool

Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.

func Float64

func Float64(v float64) *float64

Float64 is a helper routine that allocates a new float64 value to store v and returns a pointer to it.

func Int

func Int(v int) *int

Int is a helper routine that allocates a new int value to store v and returns a pointer to it.

func RetrieveLogs

func RetrieveLogs(c *Client, urlStr string, limit int, fromDate string, toDate string) (<-chan LogEntry, <-chan error)

func String

func String(v string) *string

String is a helper routine that allocates a new string value to store v and returns a pointer to it.

func Stringify

func Stringify(message interface{}) string

Stringify attempts to create a reasonable string representation of types in the api library. It does things like resolve pointers to their values and omits struct fields with nil values.

func ValidateProject

func ValidateProject(project *Project) error

ValidateProject checks whether project's attributes are missing.

Types

type App

type App struct {
	ID                 *string           `json:"id,omitempty"`
	Status             []string          `json:"status,omitempty"`
	Domain             *Domain           `json:"domain,omitempty"`
	SSL                *bool             `json:"ssl,omitempty"`
	ForceRollingDeploy *bool             `json:"forceRollingDeploy,omitempty"`
	Memory             *int              `json:"mem,omitempty"`
	Instances          *int              `json:"instances,omitempty"`
	Image              *string           `json:"image,omitempty"`
	Version            *string           `json:"version,omitempty"`
	Versions           []string          `json:"versions,omitempty"`
	Command            *string           `json:"cmd,omitempty"`
	PortMappings       []*PortMap        `json:"port_mappings,omitempty"`
	Dependencies       []string          `json:"dependencies,omitempty"`
	EnvVars            map[string]string `json:"env,omitempty"`
	Volumes            []*Volume         `json:"volumes,omitempty"`
	HealthChecks       []*HealthCheck    `json:"health_checks,omitempty"`
	Logging            *Logging          `json:"logging,omitempty"`
}

App represents a sloppy app.

func (*App) StatusCount

func (a *App) StatusCount(s string) (n int)

Returns the count how often the given status was found

func (*App) String

func (a *App) String() string

type AppsDeleter

type AppsDeleter interface {
	Delete(project, service, id string, force bool) (*StatusResponse, *http.Response, error)
}

AppsDeleter is an interface which provides the Delete method.

type AppsEndpoint

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

AppsEndpoint handles communication with the app related methods of the sloppy API.

func (*AppsEndpoint) Delete

func (a *AppsEndpoint) Delete(project, service, app string, force bool) (*StatusResponse, *http.Response, error)

Delete deletes a sloppy app.

func (*AppsEndpoint) Get

func (a *AppsEndpoint) Get(project, service, id string) (*App, *http.Response, error)

Get fetches a sloppy app by id and project, service.

func (*AppsEndpoint) GetLogs

func (a *AppsEndpoint) GetLogs(project, service, app string, limit int, fromDate string, toDate string) (<-chan LogEntry, <-chan error)

GetLogs returns logs for specific app.

func (*AppsEndpoint) GetMetrics

func (a *AppsEndpoint) GetMetrics(project, service, app string) (Metrics, *http.Response, error)

GetMetrics fetches a sloppy app's stats by name and project, service.

func (*AppsEndpoint) List

func (a *AppsEndpoint) List(project, service string) ([]*App, *http.Response, error)

List returns apps of a given project and service.

func (*AppsEndpoint) Restart

func (a *AppsEndpoint) Restart(project, service, app string) (*StatusResponse, *http.Response, error)

Restart sends a restart request for a sloppy app.

func (*AppsEndpoint) Rollback

func (a *AppsEndpoint) Rollback(project, service, app, version string) (*App, *http.Response, error)

Rollback reverts a sloppy app to a previous version.

func (*AppsEndpoint) Scale

func (a *AppsEndpoint) Scale(project, service, app string, n int) (*App, *http.Response, error)

Scale changes the running instances of a sloppy api.

func (*AppsEndpoint) Update

func (a *AppsEndpoint) Update(project, service, id string, input *App) (*App, *http.Response, error)

Update changes a sloppy app.

type AppsGetMetricer

type AppsGetMetricer interface {
	GetMetrics(project, service, id string) (Metrics, *http.Response, error)
}

AppsGetMetricer is an interface which provides the getMetrics method.

type AppsGetter

type AppsGetter interface {
	Get(project, service, id string) (*App, *http.Response, error)
}

AppsGetter is an interface which provides the Get method.

type AppsLogger

type AppsLogger interface {
	GetLogs(project, service, id string, limit int, fromDate string, toDate string) (<-chan LogEntry, <-chan error)
}

AppsLogger is an interface which provides the GetLogs method.

type AppsRestarter

type AppsRestarter interface {
	Restart(project, service, id string) (*StatusResponse, *http.Response, error)
}

AppsRestarter is an interface which provides the Restart method.

type AppsRollbacker

type AppsRollbacker interface {
	Rollback(project, service, id, version string) (*App, *http.Response, error)
}

AppsRollbacker is an interface which provides the Rollback method.

type AppsScaler

type AppsScaler interface {
	Scale(project, service, id string, n int) (*App, *http.Response, error)
}

AppsScaler is an interface which provides the Scale method.

type AppsUpdater

type AppsUpdater interface {
	Update(project, service, id string, input *App) (*App, *http.Response, error)
}

AppsUpdater is an interface which provides the Update method.

type Client

type Client struct {

	// API endpoints
	Projects            *ProjectsEndpoint
	Services            *ServicesEndpoint
	Apps                *AppsEndpoint
	RegistryCredentials *RegistryCredentialsEndpoint
	// contains filtered or unexported fields
}

A Client handles communication with the sloppy.io API.

func NewClient

func NewClient() *Client

NewClient returns a new Client to handle API requests.

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error)

Do sends an API request and returns an API response. The API response is decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred.

func (*Client) GetBaseURL

func (c *Client) GetBaseURL() string

func (*Client) GetHeader

func (c *Client) GetHeader(h string) []string

func (*Client) NewRequest

func (c *Client) NewRequest(method, path string, body interface{}) (*http.Request, error)

NewRequest returns a new Request given a method, URL, and a value pointed to by body. If a relative URL is provided in urlStr, it is resolved relative to the Client's BaseURL. Relative URLs should never have a preceding slash. If body is specified, body is JSON encoded and included as request body.

func (*Client) SetAccessToken

func (c *Client) SetAccessToken(t string)

SetAccessToken sets Client's access token header.

func (*Client) SetBaseURL

func (c *Client) SetBaseURL(u string) error

SetBaseURL sets client's baseURL and appends version path.

func (*Client) SetUserAgent

func (c *Client) SetUserAgent(ua string)

type DataPoint

type DataPoint struct {
	X Timestamp `json:"x,omitempty"`
	Y *float64  `json:"y,omitempty"`
}

DataPoint represents a value at specific time

type DataPoints

type DataPoints []*DataPoint

DataPoints represents all values of a serie.

type Domain

type Domain struct {
	URI           *string `json:"uri,omitempty"`
	RedirectHttps *bool   `json:"redirectHttps,omitempty"`
	HstsHeader    *bool   `json:"hstsHeader,omitempty"`
	BasicAuth     *string `json:"basicAuth,omitempty"`
}

Domain represents sloppy domain.

type ErrorResponse

type ErrorResponse struct {
	Response *http.Response
	StatusResponse
	Reason string `json:"reason,omitempty"`
}

ErrorResponse represents errors caused by an API request.

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

type HealthCheck

type HealthCheck struct {
	Timeout              *int    `json:"timeout_seconds,omitempty"`
	Interval             *int    `json:"interval_seconds,omitempty"`
	MaxConsectiveFailure *int    `json:"max_consecutive_failures,omitempty"`
	Path                 *string `json:"path,omitempty"`
	Type                 *string `json:"type,omitempty"`
	GracePeriod          *int    `json:"grace_period_seconds,omitempty"`
}

HealthCheck represents a sloppy health check.

type LogEntry

type LogEntry struct {
	Project   *string    `json:"project,omitempty"`
	Service   *string    `json:"service,omitempty"`
	App       *string    `json:"app,omitempty"`
	CreatedAt *Timestamp `json:"createdAt,omitempty"`
	Log       *string    `json:"body,omitempty"`
}

LogEntry represents a sloppy log entry.

func (*LogEntry) String

func (e *LogEntry) String() string

String prints a log entry

type Logging

type Logging struct {
	Driver  *string           `json:"driver,omitempty"`
	Options map[string]string `json:"options,omitempty"`
}

Logging represents a sloppy app logging configuration.

type Metrics

type Metrics map[string]Series

Metrics represents all sloppy stats.

func (Metrics) UnmarshalJSON

func (m Metrics) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes sloppy's metric format.

type PortMap

type PortMap struct {
	Port        *int `json:"container_port,omitempty"`
	ServicePort *int `json:"service_port,omitempty"`
}

PortMap represents a sloppy port map.

type Project

type Project struct {
	Name     *string    `json:"project,omitempty"`
	Services []*Service `json:"services,omitempty"`
}

Project represents a sloppy project.

func (*Project) String

func (p *Project) String() string

type ProjectsCreater

type ProjectsCreater interface {
	Create(input *Project) (*Project, *http.Response, error)
}

ProjectsCreater is an interface which provides the Create method.

type ProjectsDeleter

type ProjectsDeleter interface {
	Delete(name string, force bool) (*StatusResponse, *http.Response, error)
}

ProjectsDeleter is an interface which provides the delete method.

type ProjectsEndpoint

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

ProjectsEndpoint handles communication with the project related methods of the sloppy API.

func (*ProjectsEndpoint) Create

func (p *ProjectsEndpoint) Create(input *Project) (*Project, *http.Response, error)

Create creates a new sloppy project.

func (*ProjectsEndpoint) Delete

func (p *ProjectsEndpoint) Delete(name string, force bool) (*StatusResponse, *http.Response, error)

Delete deletes a sloppy project.

func (*ProjectsEndpoint) Get

func (p *ProjectsEndpoint) Get(name string) (*Project, *http.Response, error)

Get fetches a sloppy project by name.

func (*ProjectsEndpoint) GetLogs

func (p *ProjectsEndpoint) GetLogs(name string, limit int, fromDate string, toDate string) (<-chan LogEntry, <-chan error)

GetLogs returns logs for all apps included in a specific project.

func (*ProjectsEndpoint) List

func (p *ProjectsEndpoint) List() ([]Project, *http.Response, error)

List returns user's projects.

func (*ProjectsEndpoint) Update

func (p *ProjectsEndpoint) Update(name string, input *Project, force bool) (*Project, *http.Response, error)

Update changes a sloppy project.

type ProjectsGetLister

type ProjectsGetLister interface {
	ProjectsGetter
	ProjectsLister
}

ProjectsGetLister is an interface which provides the Get and List method.

type ProjectsGetter

type ProjectsGetter interface {
	Get(name string) (*Project, *http.Response, error)
}

ProjectsGetter is an interface which provides the Get method.

type ProjectsLister

type ProjectsLister interface {
	List() ([]Project, *http.Response, error)
}

ProjectsLister is an interface which provides the List method.

type ProjectsLogger

type ProjectsLogger interface {
	GetLogs(project string, limit int, fromDate string, toDate string) (<-chan LogEntry, <-chan error)
}

ProjectsLogger is an interface which provides the getLogs method.

type ProjectsUpdater

type ProjectsUpdater interface {
	Update(name string, input *Project, force bool) (*Project, *http.Response, error)
}

ProjectsUpdater is an interface which provides the update method.

type RegistryCredentialsCheckDeleter

type RegistryCredentialsCheckDeleter interface {
	Check() (*StatusResponse, *http.Response, error)
	Delete() (*StatusResponse, *http.Response, error)
}

RegistryCredentialsCheckDeleter is an interface which combines delete and check.

type RegistryCredentialsEndpoint

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

RegistryCredentialsEndpoint handles communication with the registry credentails related methods of the sloppy API.

func (*RegistryCredentialsEndpoint) Check

Check checks if docker credentials exist.

func (*RegistryCredentialsEndpoint) Delete

Delete removes docker credentials.

func (*RegistryCredentialsEndpoint) Upload

Upload uploads docker credentials.

type RegistryCredentialsUploader

type RegistryCredentialsUploader interface {
	Upload(reader io.Reader) (*StatusResponse, *http.Response, error)
}

RegistryCredentialsUploader is an interface which provides the Upload method.

type Series

type Series map[string]DataPoints

Series represents a named set of datapoints.

type Service

type Service struct {
	ID   *string `json:"id,omitempty"`
	Apps []*App  `json:"apps,omitempty"`
}

Service represents a sloppy service.

func (*Service) String

func (s *Service) String() string

type ServicesDeleter

type ServicesDeleter interface {
	Delete(project, id string, force bool) (*StatusResponse, *http.Response, error)
}

ServicesDeleter is an interface which provides the Delete method.

type ServicesEndpoint

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

ServicesEndpoint handles communication with the service related methods of the sloppy API.

func (*ServicesEndpoint) Delete

func (s *ServicesEndpoint) Delete(project, id string, force bool) (*StatusResponse, *http.Response, error)

Delete deletes a sloppy service by project and id.

func (*ServicesEndpoint) Get

func (s *ServicesEndpoint) Get(project, id string) (*Service, *http.Response, error)

Get fetches a sloppy service by project and id.

func (*ServicesEndpoint) GetLogs

func (s *ServicesEndpoint) GetLogs(project, service string, limit int, fromDate string, toDate string) (<-chan LogEntry, <-chan error)

GetLogs returns logs for all apps included in a specific project.

func (*ServicesEndpoint) List

func (s *ServicesEndpoint) List(project string) ([]*Service, *http.Response, error)

List returns services of a given project.

type ServicesGetter

type ServicesGetter interface {
	Get(project, id string) (*Service, *http.Response, error)
}

ServicesGetter is an interface which provides the Get method.

type ServicesLogger

type ServicesLogger interface {
	GetLogs(project, id string, limit int, fromDate string, toDate string) (<-chan LogEntry, <-chan error)
}

ServicesLogger is an interface which provides the getLogs method.

type StatusResponse

type StatusResponse struct {
	Status  string          `json:"status,omitempty"`
	Message string          `json:"message,omitempty"`
	Data    json.RawMessage `json:"data,omitempty"`
}

StatusResponse represents common API response received by delete or restart requests.

func (*StatusResponse) String

func (s *StatusResponse) String() string

type Timestamp

type Timestamp struct {
	time.Time
}

Timestamp represents a sloppy timestamp.

func (*Timestamp) UnmarshalJSON

func (u *Timestamp) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes sloppy's date format.

type Volume

type Volume struct {
	Path  *string `json:"container_path,omitempty"`
	Label *string `json:"label,omitempty"`
	Size  *string `json:"size,omitempty"`
}

Volume represents a sloppy app volume.

Jump to

Keyboard shortcuts

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