client

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnkown is returned when a non-mapped error occurred.
	ErrUnknown = errors.New("unknown error")
	// ErrConnectionFailed is returned when the client could not communicate with the sever.
	ErrConnectionFailed = errors.New("connection failed")
	// ErrNotFound is returned when the resource wasn't found or the route does't exist.
	ErrNotFound = errors.New("not found")
	// ErrBadRequest is returned when the request is malformed or invalid.
	ErrBadRequest = errors.New("bad request")
	// ErrUnauthorized is returned when the client is not authenticated to perform the operation.
	ErrUnauthorized = errors.New("unauthorized")
	// ErrForbidden is returned when the client is authenticated but not allowed to perform the operation.
	ErrForbidden = errors.New("forbidden")
	// ErrMethodNotAllowed is returned when the HTTP method used is not allowed for the resource.
	ErrMethodNotAllowed = errors.New("method not allowed")
	// ErrConflict is returned when there is a conflict with the current state of the resource.
	ErrConflict = errors.New("conflict")
	// ErrPreconditionFailed is returned when a precondition set by the client fails.
	ErrPreconditionFailed = errors.New("precondition failed")
	// ErrTooManyRequests is returned when the client has exceeded its rate limit.
	ErrTooManyRequests = errors.New("too many requests")
	// ErrInternalServerError is returned when the server has cannot response to the request due an error.
	ErrInternalServerError = errors.New("internal server error")
)
View Source
var ErrParseAddress = fmt.Errorf("could not parse the address to the required format")

Functions

func DialContext added in v0.13.6

func DialContext(ctx context.Context, address string, header http.Header) (*websocket.Conn, *http.Response, error)

DialContext creates a websocket connection to ShellHub's SSH server.

It receivees the endpoint to connect and the necessary headers for authentication on the server. If the server redirect the connection with status http.StatusTemporaryRedirect or http.StatusPermanentRedirect, the DialContext method will follow. Any other response from the server will result in an error as result of this function.

func ErrorFromResponse added in v0.13.6

func ErrorFromResponse(response Response) error

ErrorFromResponse returns an error based on the response status code. Each Error is mapped to a specific status code, if the status code is not mapped ErrUnknown is returned.

func SameDomainRedirectPolicy added in v0.13.0

func SameDomainRedirectPolicy() resty.RedirectPolicyFunc

SameDomainRedirectPolicy allows redirect only if the redirected domain is the same as original domain, e.g. redirect to "www.imroc.cc" from "imroc.cc" is allowed, but redirect to "google.com" is not allowed.

Types

type Client

type Client interface {
	// contains filtered or unexported methods
}

func NewClient

func NewClient(address string, opts ...Opt) (Client, error)

NewClient creates a new ShellHub HTTP client.

Server address must contain the scheme, the host and the port. For instance: `https://cloud.shellhub.io:443/`.

type IReverser added in v0.13.6

type IReverser interface {
	Auth(ctx context.Context, token string) error
	NewListener() (*revdial.Listener, error)
}

type LeveledLogger added in v0.6.0

type LeveledLogger struct {
	Logger *logrus.Logger
}

func (*LeveledLogger) Debugf added in v0.9.0

func (l *LeveledLogger) Debugf(msg string, keysAndValues ...interface{})

func (*LeveledLogger) Errorf added in v0.9.0

func (l *LeveledLogger) Errorf(msg string, keysAndValues ...interface{})

func (*LeveledLogger) Warnf added in v0.9.0

func (l *LeveledLogger) Warnf(msg string, keysAndValues ...interface{})

type Opt

type Opt func(*client) error

func WithHost

func WithHost(host string) Opt

func WithLogger added in v0.4.0

func WithLogger(logger *logrus.Logger) Opt

func WithPort

func WithPort(port int) Opt

func WithReverser added in v0.13.6

func WithReverser(reverser IReverser) Opt

func WithScheme added in v0.3.2

func WithScheme(scheme string) Opt

func WithURL added in v0.3.2

func WithURL(u *url.URL) Opt

type Response added in v0.13.6

type Response interface {
	StatusCode() int
}

type Reverser added in v0.13.6

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

func NewReverser added in v0.13.6

func NewReverser(host string) *Reverser

func (*Reverser) Auth added in v0.13.6

func (r *Reverser) Auth(ctx context.Context, token string) error

Auth creates a initial connection to the ShellHub SSH's server and authenticate it with the token received.

func (*Reverser) NewListener added in v0.13.6

func (r *Reverser) NewListener() (*revdial.Listener, error)

NewListener creates a new reverse listener to be used by the Agent to receive connections from the ShellHub's server.

It uses the authenticated connection generate by the [Auth] method to create a new reverse listener. Through this connection, the Agent will be able to receive connections from the ShellHub's server. This connections are, essentially, the SSH operations requested by the user.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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