remote

package
v1.0.0-beta6 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProcessStopCommand    = "command"
	ProcessStopSignal     = "signal"
	ProcessStopNativeStop = "stop"
)
View Source
const (
	SftpAuthPassword  = SftpAuthRequestType("password")
	SftpAuthPublicKey = SftpAuthRequestType("public_key")
)

Variables

This section is empty.

Functions

func IsRequestError

func IsRequestError(err error) bool

IsRequestError checks if the given error is of the RequestError type.

Types

type BackupPart

type BackupPart struct {
	ETag       string `json:"etag"`
	PartNumber int    `json:"part_number"`
}

type BackupRemoteUploadResponse

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"`
	Parts        []BackupPart `json:"parts"`
}

type Client

type Client interface {
	GetBackupRemoteUploadURLs(ctx context.Context, backup string, size int64) (BackupRemoteUploadResponse, error)
	GetInstallationScript(ctx context.Context, uuid string) (InstallationScript, error)
	GetServerConfiguration(ctx context.Context, uuid string) (ServerConfigurationResponse, error)
	GetServers(context context.Context, perPage int) ([]RawServerData, error)
	ResetServersState(ctx context.Context) error
	SetArchiveStatus(ctx context.Context, uuid string, successful bool) error
	SetBackupStatus(ctx context.Context, backup string, data BackupRequest) error
	SendRestorationStatus(ctx context.Context, backup string, successful bool) error
	SetInstallationStatus(ctx context.Context, uuid string, data InstallStatusRequest) error
	SetTransferStatus(ctx context.Context, uuid string, successful bool) error
	ValidateSftpCredentials(ctx context.Context, request SftpAuthRequest) (SftpAuthResponse, error)
	SendActivityLogs(ctx context.Context, activity []models.Activity) error
	PushServerStateChange(ctx context.Context, sid string, stateChange ServerStateChange) error
}

func New

func New(base string, opts ...ClientOption) Client

New returns a new HTTP request client that is used for making authenticated requests to the Panel that this instance is running under.

type ClientOption

type ClientOption func(c *client)

func WithCredentials

func WithCredentials(id, token string) ClientOption

WithCredentials sets the credentials to use when making request to the remote API endpoint.

func WithHttpClient

func WithHttpClient(httpClient *http.Client) ClientOption

WithHttpClient sets the underlying HTTP client instance to use when making requests to the Panel API.

type InstallStatusRequest

type InstallStatusRequest struct {
	Successful bool `json:"successful"`
	Reinstall  bool `json:"reinstall"`
}

type InstallationScript

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

InstallationScript 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 []byte) bool

Matches determines if the provided byte string matches the given regex or raw string provided to the matcher.

func (*OutputLineMatcher) String

func (olm *OutputLineMatcher) String() string

String returns the matcher's raw comparison string.

func (*OutputLineMatcher) UnmarshalJSON

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

UnmarshalJSON unmarshals 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"`
}

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"`
}

ProcessConfiguration defines the process configuration for a given server instance. This sets what Wings 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"`
}

ProcessStopConfiguration defines what is used when stopping an instance.

type RawServerData

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

RawServerData is a raw response from the API for a server.

type RequestError

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

func AsRequestError

func AsRequestError(err error) *RequestError

AsRequestError transforms the error into a RequestError if it is currently one, checking the wrap status from the other error handlers. If the error is not a RequestError nil is returned.

func (*RequestError) Error

func (re *RequestError) Error() string

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

func (*RequestError) StatusCode

func (re *RequestError) StatusCode() int

StatusCode returns the status code of the response.

type RequestErrors

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

type Response

type Response struct {
	*http.Response
}

Response is 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) BindJSON

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

BindJSON 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 first error message from the API call as a string. The error message will be formatted similar to the below example. If there is no error that can be parsed out of the API you'll still get a RequestError returned but the RequestError.Code will be "_MissingResponseCode".

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

func (*Response) HasError

func (r *Response) HasError() bool

HasError 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"`
}

ServerConfigurationResponse 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 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 ServerStateChange

type ServerStateChange struct {
	PrevState string `json:"previous_state"`
	NewState  string `json:"new_state"`
}

type SftpAuthRequest

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

SftpAuthRequest defines the request details that are passed along to the Panel when determining if the credentials provided to Wings are valid.

type SftpAuthRequestType

type SftpAuthRequestType string

type SftpAuthResponse

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

SftpAuthResponse is returned by the Panel when a pair of SFTP credentials is successfully validated. This will include the specific server that was matched as well as the permissions that are assigned to the authenticated user for the SFTP subsystem.

type SftpInvalidCredentialsError

type SftpInvalidCredentialsError struct{}

func (SftpInvalidCredentialsError) Error

func (ice SftpInvalidCredentialsError) Error() string

Jump to

Keyboard shortcuts

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