Documentation
¶
Overview ¶
Package client provides API client methods that interact with our API to manage Border0 resources.
Example to create a new client:
api := client.New(
client.WithAuthToken(os.Getenv("BORDER0_AUTH_TOKEN")), // optional, if not provided, Border0 SDK will use BORDER0_AUTH_TOKEN env var
client.WithRetryMax(2), // 1 initial + 2 retries = 3 attempts
)
See Option for more configurable options.
Index ¶
- func ExponentialBackoff(min, max time.Duration, attempt int) time.Duration
- func NotFound(err error) bool
- type APIClient
- func (api *APIClient) Connector(ctx context.Context, id string) (out *Connector, err error)
- func (api *APIClient) ConnectorTokens(ctx context.Context, connectorID string) (out *ConnectorTokens, err error)
- func (api *APIClient) Connectors(ctx context.Context) (out []Connector, err error)
- func (api *APIClient) CreateConnector(ctx context.Context, in *Connector) (out *Connector, err error)
- func (api *APIClient) CreateConnectorToken(ctx context.Context, in *ConnectorToken) (out *ConnectorToken, err error)
- func (api *APIClient) CreateSocket(ctx context.Context, in *Socket) (out *Socket, err error)
- func (api *APIClient) DeleteConnector(ctx context.Context, id string) (err error)
- func (api *APIClient) DeleteConnectorToken(ctx context.Context, connectorID, tokenID string) (err error)
- func (api *APIClient) DeleteSocket(ctx context.Context, idOrName string) (err error)
- func (api *APIClient) SignSocketKey(ctx context.Context, idOrName string, in *SocketKeyToSign) (out *SignedSocketKey, err error)
- func (api *APIClient) Socket(ctx context.Context, idOrName string) (out *Socket, err error)
- func (api *APIClient) SocketConnectors(ctx context.Context, idOrName string) (out *SocketConnectors, err error)
- func (api *APIClient) SocketUpstreamConfigs(ctx context.Context, idOrName string) (out *SocketUpstreamConfigs, err error)
- func (api *APIClient) Sockets(ctx context.Context) (out []Socket, err error)
- func (api *APIClient) TokenClaims() (jwt.MapClaims, error)
- func (api *APIClient) UpdateConnector(ctx context.Context, in *Connector) (out *Connector, err error)
- func (api *APIClient) UpdateSocket(ctx context.Context, idOrName string, in *Socket) (out *Socket, err error)
- type Backoff
- type Connector
- type ConnectorService
- type ConnectorToken
- type ConnectorTokens
- type Error
- type FlexibleTime
- type HTTPClient
- type HTTPRequester
- type Option
- type Requester
- type SignedSocketKey
- type Socket
- type SocketConnector
- type SocketConnectors
- type SocketKeyToSign
- type SocketService
- type SocketUpstreamConfig
- type SocketUpstreamConfigs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExponentialBackoff ¶
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.
Types ¶
type APIClient ¶
type APIClient struct {
// contains filtered or unexported fields
}
APIClient is the client for the Border0 API.
func (*APIClient) Connector ¶ added in v1.0.0
Connector fetches a connector from your Border0 organization by UUID. Connector UUID is globally unique and immutable.
func (*APIClient) ConnectorTokens ¶ added in v1.0.0
func (api *APIClient) ConnectorTokens(ctx context.Context, connectorID string) (out *ConnectorTokens, err error)
ConnectorTokens fetches all tokens for a connector by connector's UUID.
func (*APIClient) Connectors ¶ added in v1.0.0
Connectors fetches all connectors in your Border0 organization.
func (*APIClient) CreateConnector ¶ added in v1.0.0
func (api *APIClient) CreateConnector(ctx context.Context, in *Connector) (out *Connector, err error)
CreateConnector creates a new connector in your Border0 organization. Connector name must be unique within your organization, otherwise API will return an error.
func (*APIClient) CreateConnectorToken ¶ added in v1.0.0
func (api *APIClient) CreateConnectorToken(ctx context.Context, in *ConnectorToken) (out *ConnectorToken, err error)
CreateConnectorToken creates a new token for a connector. Token is used to authenticate connector with Border0 API. Token can be created with or without a expiration date. If ExpiresAt field is not set, token will not expire.
func (*APIClient) CreateSocket ¶
CreateSocket creates a new socket in your Border0 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) DeleteConnector ¶ added in v1.0.0
DeleteConnector deletes a connector from your Border0 organization by connector's UUID.
func (*APIClient) DeleteConnectorToken ¶ added in v1.0.0
func (api *APIClient) DeleteConnectorToken(ctx context.Context, connectorID, tokenID string) (err error)
DeleteConnectorToken deletes a token for a connector by connector's UUID and token's UUID.
func (*APIClient) DeleteSocket ¶ added in v0.1.22
DeleteSocket deletes a socket in your Border0 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 ¶
Socket fetches a socket by socket UUID or name. Socket UUID is globally unique and socket name is unique within a Border0 organization.
func (*APIClient) SocketConnectors ¶ added in v1.0.0
func (api *APIClient) SocketConnectors(ctx context.Context, idOrName string) (out *SocketConnectors, err error)
SocketConnectors fetches all connectors that are linked to a socket.
func (*APIClient) SocketUpstreamConfigs ¶ added in v1.0.0
func (api *APIClient) SocketUpstreamConfigs(ctx context.Context, idOrName string) (out *SocketUpstreamConfigs, err error)
SocketUpstreamConfigs fetches all upstream configurations for a socket.
func (*APIClient) Sockets ¶ added in v0.1.22
Sockets fetches all sockets in your Border0 organization.
func (*APIClient) TokenClaims ¶
TokenClaims returns the claims of the JWT token.
type Backoff ¶
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 Connector ¶ added in v1.0.0
type Connector struct {
// input and output fields
Name string `json:"name"`
Description string `json:"description,omitempty"`
// output field
ConnectorID string `json:"connector_id"`
}
Connector represents a connector in your Border0 organization.
type ConnectorService ¶ added in v1.0.0
type ConnectorService interface {
Connector(ctx context.Context, id string) (out *Connector, err error)
Connectors(ctx context.Context) (out []Connector, err error)
CreateConnector(ctx context.Context, in *Connector) (out *Connector, err error)
UpdateConnector(ctx context.Context, in *Connector) (out *Connector, err error)
DeleteConnector(ctx context.Context, id string) (err error)
ConnectorTokens(ctx context.Context, connectorID string) (out *ConnectorTokens, err error)
CreateConnectorToken(ctx context.Context, in *ConnectorToken) (out *ConnectorToken, err error)
DeleteConnectorToken(ctx context.Context, connectorID, tokenID string) (err error)
}
ConnectorService is an interface for API client methods that interact with Border0 API to manage connectors and connector tokens.
type ConnectorToken ¶ added in v1.0.0
type ConnectorToken struct {
// input and output fields
ConnectorID string `json:"connector_id"`
Name string `json:"name"`
ExpiresAt FlexibleTime `json:"expires_at,omitempty"`
// additional output fields
ID string `json:"id"`
Token string `json:"token"`
CreatedBy string `json:"created_by"`
CreatedAt FlexibleTime `json:"created_at"`
}
ConnectorToken represents a token for a connector.
type ConnectorTokens ¶ added in v1.0.0
type ConnectorTokens struct {
List []ConnectorToken `json:"list"`
Connector Connector `json:"connector"`
}
ConnectorTokens represents a list of tokens for a connector.
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 ¶
APIErrorFrom creates an Error from an HTTP response.
type FlexibleTime ¶ added in v1.0.0
FlexibleTime is a time.Time that can be unmarshalled from either a string (RFC3339) or a number (unix timestamp). On marshalling, it is always marshalled as a number (unix timestamp). FlexibleTime is used for Border0 API connector token's `expires_at` and `created_at` fields.
func FlexibleTimeFrom ¶ added in v1.0.0
func FlexibleTimeFrom(s string) (FlexibleTime, error)
FlexibleTimeFrom returns a new FlexibleTime set to the given time from a string in RFC3339 format. It's a helper function for FlexibleTime.
func (FlexibleTime) MarshalJSON ¶ added in v1.0.0
func (f FlexibleTime) MarshalJSON() ([]byte, error)
MarshalJSON marshals the FlexibleTime as a unix timestamp.
func (FlexibleTime) String ¶ added in v1.0.0
func (f FlexibleTime) String() string
String returns the FlexibleTime as a string in RFC3339 format. If the FlexibleTime is zero, it returns an empty string.
func (*FlexibleTime) UnmarshalJSON ¶ added in v1.0.0
func (f *FlexibleTime) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshals the FlexibleTime from either a string (RFC3339) or a number (unix timestamp).
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.
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 ¶
WithAuthToken sets the auth token for Border0 api calls.
func WithBackoff ¶
WithBackoff sets the backoff function that's used to calculate the wait time between retries of failed api calls.
func WithBaseURL ¶
WithBaseURL sets the base url for Border0 api calls.
func WithRetryMax ¶
WithRetryMax sets the maximum number of retries of failed api calls.
func WithRetryWaitMax ¶
WithRetryWaitMax sets the maximum wait time between retries of failed api calls.
func WithRetryWaitMin ¶
WithRetryWaitMin sets the minimum wait time between retries of failed api calls.
func WithTimeout ¶
WithTimeout sets the timeout for the underlying http client.
type Requester ¶
type Requester interface {
TokenClaims() (jwt.MapClaims, error)
SocketService
ConnectorService
}
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"`
RecordingEnabled bool `json:"recording_enabled"`
ConnectorAuthenticationEnabled bool `json:"connector_authentication_enabled"`
Tags map[string]string `json:"tags,omitempty"`
// link to a connector with upstream config
ConnectorID string `json:"connector_id,omitempty"`
UpstreamConfig *types.ConnectorServiceUpstreamConfig `json:"upstream_configuration,omitempty"`
}
Socket represents a socket in Border0 API. A socket can be linked to a connector with upstream configuration. Use `ConnectorID` to link a socket to a connector, and use `UpstreamConfig` to configure upstream for a socket.
type SocketConnector ¶ added in v1.0.0
type SocketConnector struct {
ID uint64 `json:"id"`
ConnectorID string `json:"connector_id"`
ConnectorName string `json:"connector_name"`
SocketID string `json:"socket_id"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
SocketConnector represents a connector that is linked to a socket.
type SocketConnectors ¶ added in v1.0.0
type SocketConnectors struct {
List []SocketConnector `json:"list"`
}
SocketConnectors represents a list of connectors that are linked to a socket.
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)
SocketConnectors(ctx context.Context, idOrName string) (out *SocketConnectors, err error)
SocketUpstreamConfigs(ctx context.Context, idOrName string) (out *SocketUpstreamConfigs, 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.
type SocketUpstreamConfig ¶ added in v1.0.0
type SocketUpstreamConfig struct {
Config types.ConnectorServiceUpstreamConfig `json:"config"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
SocketUpstreamConfig represents an upstream configuration for a socket.
type SocketUpstreamConfigs ¶ added in v1.0.0
type SocketUpstreamConfigs struct {
List []SocketUpstreamConfig `json:"list"`
}
SocketUpstreamConfigs represents a list of upstream configurations for a socket.