api

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2021 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 IsInvalidCredentialsError

func IsInvalidCredentialsError(err error) bool

func IsRequestError

func IsRequestError(err error) bool

Types

type BackupRemoteUploadResponse added in v1.1.0

type BackupRemoteUploadResponse struct {
	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 added in v1.1.0

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 added in v1.1.0

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 added in v1.1.0

type Q map[string]string

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

type RawServerData added in v1.1.0

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

type Request added in v1.1.0

type Request struct{}

A custom API requester struct for Wings.

func New added in v1.1.0

func New() *Request

Initializes the requester instance.

func (*Request) Client added in v1.1.0

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

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

func (*Request) Endpoint added in v1.1.0

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

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

func (*Request) Get added in v1.1.0

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 added in v1.1.0

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

func (*Request) GetInstallationScript added in v1.1.0

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

Fetches installation information for the server process.

func (*Request) GetServerConfiguration added in v1.1.0

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

Fetches the server configuration and returns the struct for it.

func (*Request) GetServers added in v1.1.0

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 added in v1.1.0

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 Wings to ensure that the request is properly handled by the Panel.

func (*Request) Post added in v1.1.0

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

Makes a POST request to the given Panel API endpoint.

func (*Request) SendArchiveStatus added in v1.1.0

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

func (*Request) SendBackupStatus added in v1.1.0

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 added in v1.1.0

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

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

func (*Request) SendTransferStatus added in v1.2.0

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

func (*Request) ValidateSftpCredentials added in v1.1.0

func (r *Request) ValidateSftpCredentials(request SftpAuthRequest) (*SftpAuthResponse, 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 added in v1.1.0

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 added in v1.1.0

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 added in v1.1.0

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 added in v1.1.0

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 added in v1.1.0

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, Wings 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 Wings 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 Wings we can self-recover without too much hassle, so long as Wings is aware of what servers should exist on it.

type SftpAuthRequest

type SftpAuthRequest struct {
	User          string `json:"username"`
	Pass          string `json:"password"`
	IP            string `json:"ip"`
	SessionID     []byte `json:"session_id"`
	ClientVersion []byte `json:"client_version"`
}

type SftpAuthResponse

type SftpAuthResponse struct {
	Server      string   `json:"server"`
	Token       string   `json:"token"`
	Permissions []string `json:"permissions"`
}

Jump to

Keyboard shortcuts

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