client

package
v0.1.23-experimental-2 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2023 License: Apache-2.0 Imports: 13 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExponentialBackoff

func ExponentialBackoff(min, max time.Duration, attempt int) time.Duration

ExponentialBackoff is a Backoff function which will backoff exponentially between the given minimum and maximum durations. The attempt number is used as the exponent base, so the first attempt will backoff by the minimum duration, the second attempt will backoff by twice the minimum duration, the third attempt will backoff by four times the minimum duration, and so on. The maximum duration is used as a cap, so the backoff will never exceed the maximum duration.

func NotFound added in v0.1.22

func NotFound(err error) bool

Types

type APIClient

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

APIClient is the client for the Border0 API.

func New

func New(options ...Option) *APIClient

New creates a new Border0 API client.

func (*APIClient) CreateSocket

func (api *APIClient) CreateSocket(ctx context.Context, in *Socket) (out *Socket, err error)

CreateSocket creates a new socket in your organization. Socket name must be unique within your organization, otherwise, an error will be returned. Socket type is required and must be one of the following: "http", "ssh", "tls" or "database".

func (*APIClient) DeleteSocket added in v0.1.22

func (api *APIClient) DeleteSocket(ctx context.Context, idOrName string) (err error)

DeleteSocket deletes a socket in your organization. If the socket does not exist, no error will be returned.

func (*APIClient) SignSocketKey

func (api *APIClient) SignSocketKey(ctx context.Context, idOrName string, in *SocketKeyToSign) (out *SignedSocketKey, err error)

SignSocketKey generates a signed SSH certificate for a socket. The SSH public key must be in OpenSSH format. The SSH certificate will be valid for 5 minutes. The host key is the public key Border0 server. It can be used to verify the SSH certificate.

func (*APIClient) Socket

func (api *APIClient) Socket(ctx context.Context, idOrName string) (out *Socket, err error)

Socket fetches a socket by socket UUID or name. Socket UUID is globally unique and socket name is unique within an organization.

func (*APIClient) Sockets added in v0.1.22

func (api *APIClient) Sockets(ctx context.Context) (out []Socket, err error)

Sockets fetches all sockets in your organization.

func (*APIClient) TokenClaims

func (api *APIClient) TokenClaims() (jwt.MapClaims, error)

TokenClaims returns the claims of the JWT token.

func (*APIClient) UpdateSocket added in v0.1.22

func (api *APIClient) UpdateSocket(ctx context.Context, idOrName string, in *Socket) (out *Socket, err error)

UpdateSocket updates a socket in your organization.

type Backoff

type Backoff func(min, max time.Duration, attempt int) time.Duration

Backoff is a callback function which will be called by APIClient when performing retries. It is passed the minimum and maximum durations to backoff between, as well as the attempt number (starting at zero)

type Error

type Error struct {
	Code     int    `json:"status_code"`
	Message  string `json:"error_message"`
	Fallback string `json:"message"`
}

Error is an error returned by the API server.

func APIErrorFrom

func APIErrorFrom(resp *http.Response) Error

APIErrorFrom creates an Error from an HTTP response.

func (Error) Error

func (e Error) Error() string

Error returns string representation of an Error.

type HTTPClient

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

HTTPClient is a wrapper around http.Client that handles authentication, request/response encoding/decoding, and error handling.

func (*HTTPClient) Close

func (h *HTTPClient) Close()

Close closes idle connections in the underlying HTTP client.

func (*HTTPClient) Request

func (h *HTTPClient) Request(ctx context.Context, method, path string, input, output any) (int, error)

Request sends an HTTP request to the API server.

type HTTPRequester

type HTTPRequester interface {
	Request(ctx context.Context, method, path string, input, output any) (int, error)
	Close()
}

HTTPRequester is an interface for HTTPClient.

type Option

type Option func(*APIClient)

Option is a function that can be passed to NewAPIClient to configure it.

func WithAuthToken

func WithAuthToken(token string) Option

WithAuthToken sets the auth token for Border0 api calls.

func WithBackoff

func WithBackoff(fn Backoff) Option

WithBackoff sets the backoff function that's used to calculate the wait time between retries of failed api calls.

func WithBaseURL

func WithBaseURL(url string) Option

WithBaseURL sets the base url for Border0 api calls.

func WithRetryMax

func WithRetryMax(attempts int) Option

WithRetryMax sets the maximum number of retries of failed api calls.

func WithRetryWaitMax

func WithRetryWaitMax(wait time.Duration) Option

WithRetryWaitMax sets the maximum wait time between retries of failed api calls.

func WithRetryWaitMin

func WithRetryWaitMin(wait time.Duration) Option

WithRetryWaitMin sets the minimum wait time between retries of failed api calls.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout sets the timeout for the underlying http client.

type Requester

type Requester interface {
	TokenClaims() (jwt.MapClaims, error)
	SocketService
}

Requester is the interface for the Border0 API client.

type SignedSocketKey

type SignedSocketKey struct {
	SignedSSHCert string `json:"signed_ssh_cert"`
	HostKey       string `json:"host_key"`
}

SignedSocketKey represents a signed SSH certificate and the host key.

type Socket

type Socket struct {
	Name                 string            `json:"name"`
	SocketID             string            `json:"socket_id"`
	SocketType           string            `json:"socket_type"`
	Description          string            `json:"description,omitempty"`
	UpstreamType         string            `json:"upstream_type,omitempty"`
	UpstreamHTTPHostname string            `json:"upstream_http_hostname,omitempty"`
	Tags                 map[string]string `json:"tags,omitempty"`

	RecordingEnabled               bool `json:"recording_enabled"`
	ConnectorAuthenticationEnabled bool `json:"connector_authentication_enabled"`

	ConnectorData *SocketConnectorData `json:"connector_data,omitempty"`
}

Socket represents a socket in Border0 API.

type SocketConnectorData added in v0.1.22

type SocketConnectorData struct {
	ConnectorID string                                `json:"connector_id,omitempty"`
	Config      *types.ConnectorServiceUpstreamConfig `json:"config,omitempty"`
}

type SocketKeyToSign

type SocketKeyToSign struct {
	SSHPublicKey string `json:"ssh_public_key"`
}

SocketKeyToSign represents a SSH public key to sign.

type SocketService

type SocketService interface {
	Socket(ctx context.Context, idOrName string) (out *Socket, err error)
	Sockets(ctx context.Context) (out []Socket, err error)
	CreateSocket(ctx context.Context, in *Socket) (out *Socket, err error)
	UpdateSocket(ctx context.Context, idOrName string, in *Socket) (out *Socket, err error)
	DeleteSocket(ctx context.Context, idOrName string) (err error)
	SignSocketKey(ctx context.Context, idOrName string, in *SocketKeyToSign) (out *SignedSocketKey, err error)
}

SocketService is an interface for API client methods that interact with Border0 API to manage sockets.

Jump to

Keyboard shortcuts

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