Documentation
¶
Index ¶
- Variables
- func DialContext(ctx context.Context, address string, header http.Header) (*websocket.Conn, *http.Response, error)
- func ErrorFromResponse(response Response) error
- func SameDomainRedirectPolicy() resty.RedirectPolicyFunc
- func YamuxConfigFromReverseListenerV2(cfg *ReverseListenerV2Config) *yamux.Config
- type Client
- type LeveledLogger
- type Opt
- type Response
- type ReverseListenerV2Config
- type Reverser
Constants ¶
This section is empty.
Variables ¶
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 = 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") )
var DefaultReverseListenerV2Config = ReverseListenerV2Config{ AcceptBacklog: 256, EnableKeepAlive: true, KeepAliveInterval: 35 * time.Second, ConnectionWriteTimeout: 15 * time.Second, MaxStreamWindowSize: 256 * 1024, StreamCloseTimeout: 5 * time.Minute, StreamOpenTimeout: 75 * time.Second, }
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
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.
func YamuxConfigFromReverseListenerV2 ¶ added in v0.22.0
func YamuxConfigFromReverseListenerV2(cfg *ReverseListenerV2Config) *yamux.Config
Types ¶
type LeveledLogger ¶ added in v0.6.0
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 WithLogger ¶ added in v0.4.0
func WithReverser ¶ added in v0.13.6
func WithScheme ¶ added in v0.3.2
func WithVersion ¶ added in v0.20.1
type ReverseListenerV2Config ¶ added in v0.22.0
type ReverseListenerV2Config struct {
// AcceptBacklog is used to limit how many streams may be
// waiting an accept.
AcceptBacklog int `json:"yamux_accept_backlog"`
// EnableKeepalive is used to do a period keep alive
// messages using a ping.
EnableKeepAlive bool `json:"yamux_enable_keep_alive"`
// KeepAliveInterval is how often to perform the keep alive
KeepAliveInterval time.Duration `json:"yamux_keep_alive_interval"`
// ConnectionWriteTimeout is meant to be a "safety valve" timeout after
// we which will suspect a problem with the underlying connection and
// close it. This is only applied to writes, where's there's generally
// an expectation that things will move along quickly.
ConnectionWriteTimeout time.Duration `json:"yamux_connection_write_timeout"`
// MaxStreamWindowSize is used to control the maximum
// window size that we allow for a stream.
MaxStreamWindowSize uint32 `json:"yamux_max_stream_window_size"`
// StreamOpenTimeout is the maximum amount of time that a stream will
// be allowed to remain in pending state while waiting for an ack from the peer.
// Once the timeout is reached the session will be gracefully closed.
// A zero value disables the StreamOpenTimeout allowing unbounded
// blocking on OpenStream calls.
StreamOpenTimeout time.Duration `json:"yamux_stream_open_timeout"`
// StreamCloseTimeout is the maximum time that a stream will allowed to
// be in a half-closed state when `Close` is called before forcibly
// closing the connection. Forcibly closed connections will empty the
// receive buffer, drop any future packets received for that stream,
// and send a RST to the remote side.
StreamCloseTimeout time.Duration `json:"yamux_stream_close_timeout"`
}
func NewReverseV2ConfigFromMap ¶ added in v0.22.0
func NewReverseV2ConfigFromMap(m map[string]any) *ReverseListenerV2Config
NewReverseV2ConfigFromMap creates a new Config from a map[string]any received from auth data from the server or returns the default config if the map is nil. If a key is missing, the default value is used.
type Reverser ¶ added in v0.13.6
type Reverser struct {
// contains filtered or unexported fields
}
func NewReverser ¶ added in v0.13.6
func (*Reverser) Auth ¶ added in v0.13.6
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
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.