api

package
v0.0.0-...-1568502 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2020 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProcessStopCommand    = "command"
	ProcessStopSignal     = "signal"
	ProcessStopNativeStop = "stop"
)

Variables

This section is empty.

Functions

func IsRequestError

func IsRequestError(err error) bool

Types

type BackupRemoteUploadResponse

type BackupRemoteUploadResponse struct {
	CompleteMultipartUpload string   `json:"complete_multipart_upload"`
	AbortMultipartUpload    string   `json:"abort_multipart_upload"`
	Parts                   []string `json:"parts"`
	PartSize                int64    `json:"part_size"`
}

type BackupRequest

type BackupRequest struct {
	Checksum     string `json:"checksum"`
	ChecksumType string `json:"checksum_type"`
	Size         int64  `json:"size"`
	Successful   bool   `json:"successful"`
}

type D

type D map[string]interface{}

A generic type allowing for easy binding use when making requests to API endpoints that only expect a singular argument or something that would not benefit from being a typed struct.

Inspired by gin.H, same concept.

type InstallationScript

type InstallationScript struct {
	ContainerImage string `json:"container_image"`
	Entrypoint     string `json:"entrypoint"`
	Script         string `json:"script"`
}

Defines installation script information for a server process. This is used when a server is installed for the first time, and when a server is marked for re-installation.

type OutputLineMatcher

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

func (*OutputLineMatcher) Matches

func (olm *OutputLineMatcher) Matches(s string) bool

Determine if a given string "s" matches the given line.

func (*OutputLineMatcher) String

func (olm *OutputLineMatcher) String() string

Return the matcher's raw comparison string.

func (*OutputLineMatcher) UnmarshalJSON

func (olm *OutputLineMatcher) UnmarshalJSON(data []byte) error

Unmarshal the startup lines into individual structs for easier matching abilities.

type Pagination

type Pagination struct {
	CurrentPage uint `json:"current_page"`
	From        uint `json:"from"`
	LastPage    uint `json:"last_page"`
	PerPage     uint `json:"per_page"`
	To          uint `json:"to"`
	Total       uint `json:"total"`
}

A pagination struct matching the expected pagination response from the Panel API.

type ProcessConfiguration

type ProcessConfiguration struct {
	Startup struct {
		Done            []*OutputLineMatcher `json:"done"`
		UserInteraction []string             `json:"user_interaction"`
		StripAnsi       bool                 `json:"strip_ansi"`
	} `json:"startup"`

	Stop ProcessStopConfiguration `json:"stop"`

	ConfigurationFiles []parser.ConfigurationFile `json:"configs"`
}

Defines the process configuration for a given server instance. This sets what the daemon is looking for to mark a server as done starting, what to do when stopping, and what changes to make to the configuration file for a server.

type ProcessStopConfiguration

type ProcessStopConfiguration struct {
	Type  string `json:"type"`
	Value string `json:"value"`
}

type Q

type Q map[string]string

Same concept as D, but a map of strings, used for querying GET requests.

type RawServerData

type RawServerData struct {
	Uuid                 string          `json:"uuid"`
	Settings             json.RawMessage `json:"settings"`
	ProcessConfiguration json.RawMessage `json:"process_configuration"`
}

type Request

type Request struct{}

A custom API requester struct for Claws.

func New

func New() *Request

Initializes the requester instance.

func (*Request) Client

func (r *Request) Client() *http.Client

Builds the base request instance that can be used with the HTTP client.

func (*Request) Endpoint

func (r *Request) Endpoint(endpoint string) string

Returns the given endpoint formatted as a URL to the Panel API.

func (*Request) Get

func (r *Request) Get(url string, data Q) (*Response, error)

Makes a GET request to the given Panel API endpoint. If any data is passed as the second argument it will be passed through on the request as URL parameters.

func (*Request) GetBackupRemoteUploadURLs

func (r *Request) GetBackupRemoteUploadURLs(backup string, size int64) (*BackupRemoteUploadResponse, error)

func (*Request) GetInstallationScript

func (r *Request) GetInstallationScript(uuid string) (InstallationScript, error)

Fetches installation information for the server process.

func (*Request) GetServerConfiguration

func (r *Request) GetServerConfiguration(uuid string) (ServerConfigurationResponse, error)

Fetches the server configuration and returns the struct for it.

func (*Request) GetServers

func (r *Request) GetServers() ([]RawServerData, error)

Fetches all of the server configurations from the Panel API. This will initially load the first 50 servers, and then check the pagination response to determine if more pages should be loaded. If so, those requests are spun-up in additional routines and the final resulting slice of all servers will be returned.

func (*Request) Make

func (r *Request) Make(method, url string, body io.Reader, opts ...func(r *http.Request)) (*Response, error)

Makes a HTTP request to the given endpoint, attaching the necessary request headers from Claws to ensure that the request is properly handled by the Panel.

func (*Request) Post

func (r *Request) Post(url string, data interface{}) (*Response, error)

Makes a POST request to the given Panel API endpoint.

func (*Request) SendArchiveStatus

func (r *Request) SendArchiveStatus(uuid string, successful bool) error

func (*Request) SendBackupStatus

func (r *Request) SendBackupStatus(backup string, data BackupRequest) error

Notifies the panel that a specific backup has been completed and is now available for a user to view and download.

func (*Request) SendInstallationStatus

func (r *Request) SendInstallationStatus(uuid string, successful bool) error

Marks a server as being installed successfully or unsuccessfully on the panel.

func (*Request) SendTransferFailure

func (r *Request) SendTransferFailure(uuid string) error

func (*Request) SendTransferSuccess

func (r *Request) SendTransferSuccess(uuid string) error

type RequestError

type RequestError struct {
	Code   string `json:"code"`
	Status string `json:"status"`
	Detail string `json:"detail"`
	// contains filtered or unexported fields
}

func (*RequestError) Error

func (re *RequestError) Error() string

Returns the error response in a string form that can be more easily consumed.

type RequestErrorBag

type RequestErrorBag struct {
	Errors []RequestError `json:"errors"`
}

type Response

type Response struct {
	*http.Response
}

A custom response type that allows for commonly used error handling and response parsing from the Panel API. This just embeds the normal HTTP response from Go and we attach a few helper functions to it.

func (*Response) Bind

func (r *Response) Bind(v interface{}) error

Binds a given interface with the data returned in the response. This is a shortcut for calling Read and then manually calling json.Unmarshal on the raw bytes.

func (*Response) Error

func (r *Response) Error() error

Returns the error message from the API call as a string. The error message will be formatted similar to the below example:

HttpNotFoundException: The requested resource does not exist. (HTTP/404)

func (*Response) HasError

func (r *Response) HasError() bool

Determines if the API call encountered an error. If no request has been made the response will be false. This function will evaluate to true if the response code is anything 300 or higher.

func (*Response) Read

func (r *Response) Read() ([]byte, error)

Reads the body from the response and returns it, then replaces it on the response so that it can be read again later. This does not close the response body, so any functions calling this should be sure to manually defer a Body.Close() call.

type ServerConfigurationResponse

type ServerConfigurationResponse struct {
	Settings             json.RawMessage       `json:"settings"`
	ProcessConfiguration *ProcessConfiguration `json:"process_configuration"`
}

Holds the server configuration data returned from the Panel. When a server process is started, Claws communicates with the Panel to fetch the latest build information as well as get all of the details needed to parse the given Egg.

This means we do not need to hit Claws each time part of the server is updated, and the Panel serves as the source of truth at all times. This also means if a configuration is accidentally wiped on Claws we can self-recover without too much hassle, so long as Claws is aware of what servers should exist on it.

Jump to

Keyboard shortcuts

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