Documentation
¶
Index ¶
- Constants
- Variables
- func NewAPIKeyClient(overmindAPIURL string, apiKey string) (*natsTokenClient, error)
- func NewOAuthTokenClient(oAuthTokenURL string, overmindAPIURL string, account string, ...) *natsTokenClient
- type APIKeyTokenSource
- type BasicTokenClient
- type ClientCredentialsConfig
- type MaxRetriesError
- type NATSOptions
- type TokenClient
Constants ¶
const ConnectionTimeoutDefault = 10 * time.Second
const MaxReconnectsDefault = -1
Defaults
const ReconnectJitterDefault = 5 * time.Second
const ReconnectWaitDefault = 1 * time.Second
const UserAgentVersion = "0.1"
Variables ¶
var ClosedHandlerDefault = func(c *nats.Conn) { fields := log.Fields{} if c != nil { fields["error"] = c.LastError() } log.WithFields(fields).Info("NATS connection closed") }
var DisconnectErrHandlerDefault = func(c *nats.Conn, e error) { fields := log.Fields{ "error": e, } if c != nil { fields["address"] = c.ConnectedAddr() } if e != nil { log.WithFields(fields).Error("NATS disconnected") } else { log.WithFields(fields).Info("NATS disconnected") } }
var ErrorHandlerDefault = func(c *nats.Conn, s *nats.Subscription, e error) { fields := log.Fields{ "error": e, } if c != nil { fields["address"] = c.ConnectedAddr() } if s != nil { fields["subject"] = s.Subject fields["queue"] = s.Queue } log.WithFields(fields).Error("NATS error") }
var LameDuckModeHandlerDefault = func(c *nats.Conn) { fields := log.Fields{} if c != nil { fields["address"] = c.ConnectedAddr() } log.WithFields(fields).Info("NATS server has entered lame duck mode") }
var ReconnectHandlerDefault = func(c *nats.Conn) { fields := log.Fields{} if c != nil { fields["reconnects"] = c.Reconnects fields["ServerID"] = c.ConnectedServerId() fields["URL"] = c.ConnectedUrl() } log.WithFields(fields).Info("NATS reconnected") }
Functions ¶
func NewAPIKeyClient ¶ added in v0.39.0
NewAPIKeyClient Creates a new token client that authenticates to Overmind using an API key. This is exchanged for an OAuth token, which is then used to get a NATS token.
The provided `overmindAPIURL` parameter should be the root URL of the Overmind API, without the /api suffix e.g. https://api.prod.overmind.tech
func NewOAuthTokenClient ¶
func NewOAuthTokenClient(oAuthTokenURL string, overmindAPIURL string, account string, flowConfig ClientCredentialsConfig) *natsTokenClient
NewOAuthTokenClient Generates a token client that authenticates to OAuth using the client credentials flow, then uses that auth to get a NATS token. `clientID` and `clientSecret` are used to authenticate using the client credentials flow with an API at `oAuthTokenURL`. `overmindAPIURL` is the root URL of the NATS token exchange API that will be used e.g. https://api.server.test/v1
Tokens will be minted under the specified account as long as the client has admin permissions, if not, the account that is attached to the client via Auth0 metadata will be used
Types ¶
type APIKeyTokenSource ¶ added in v0.39.0
type APIKeyTokenSource struct {
// The API Key to use to authenticate to the Overmind API
ApiKey string
// contains filtered or unexported fields
}
An OAuth2 token source which uses an Overmind API token as a source for OAuth tokens
func NewAPIKeyTokenSource ¶ added in v0.39.0
func NewAPIKeyTokenSource(apiKey string, overmindAPIURL string) *APIKeyTokenSource
type BasicTokenClient ¶
type BasicTokenClient struct {
// contains filtered or unexported fields
}
BasicTokenClient stores a static token and returns it when called, ignoring any provided NKeys or context since it already has the token and doesn't need to make any requests
func NewBasicTokenClient ¶
func NewBasicTokenClient(token string, keys nkeys.KeyPair) *BasicTokenClient
NewBasicTokenClient Creates a new basic token client that simply returns a static token
func (*BasicTokenClient) GetJWT ¶
func (b *BasicTokenClient) GetJWT() (string, error)
type ClientCredentialsConfig ¶
type ClientCredentialsConfig struct {
// The ClientID of the application that we'll be authenticating as
ClientID string
// ClientSecret that corresponds to the ClientID
ClientSecret string
}
ClientCredentialsConfig Authenticates to Overmind using the Client Credentials flow https://auth0.com/docs/get-started/authentication-and-authorization-flow/client-credentials-flow
type MaxRetriesError ¶
type MaxRetriesError struct{}
func (MaxRetriesError) Error ¶
func (m MaxRetriesError) Error() string
type NATSOptions ¶
type NATSOptions struct {
Servers []string // List of server to connect to
ConnectionName string // The client name
MaxReconnects int // The maximum number of reconnect attempts
ConnectionTimeout time.Duration // The timeout for Dial on a connection
ReconnectWait time.Duration // Wait time between reconnect attempts
ReconnectJitter time.Duration // The upper bound of a random delay added ReconnectWait
TokenClient TokenClient // The client to use to get NATS tokens
DisconnectErrHandler nats.ConnErrHandler // Runs when NATS is diconnected
ReconnectHandler nats.ConnHandler // Runs when NATS has reconnected
ClosedHandler nats.ConnHandler // Runs when a connection has been closed
LameDuckModeHandler nats.ConnHandler // Runs when the connction enters "lame duck mode"
ErrorHandler nats.ErrHandler // Runs when there is a NATS error
AdditionalOptions []nats.Option // Addition options to pass to the connection
NumRetries int // How many times to retry connecting initially, use -1 to retry indefinitely
RetryDelay time.Duration // Delay between connection attempts
}
func (NATSOptions) Connect ¶
func (o NATSOptions) Connect() (sdp.EncodedConnection, error)
ConnectAs Connects to NATS using the supplied options, including retrying if unavailable
func (NATSOptions) Copy ¶ added in v0.42.0
func (o NATSOptions) Copy() NATSOptions
Creates a copy of the NATS options, **excluding** the token client as these should not be re-used
func (NATSOptions) ToNatsOptions ¶
func (o NATSOptions) ToNatsOptions() (string, []nats.Option)
ToNatsOptions Converts the struct to connection string and a set of NATS options
type TokenClient ¶
type TokenClient interface {
// Returns a NATS token that can be used to connect
GetJWT() (string, error)
// Uses the NKeys associated with the token to sign some binary data
Sign([]byte) ([]byte, error)
}
TokenClient Represents something that is capable of getting NATS JWT tokens for a given set of NKeys