natsutil

package
v0.0.0-...-f0e7813 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthEntity

type AuthEntity struct {
	NKey
	// JWT is the JWT for the entity, signed with the KeyPair.
	JWT        string `json:"jwt"`
	SigningKey *NKey  `json:"signing_key,omitempty"`
}

AuthEntity is an entity that can be authenticated by the NATS server using JWT.

func (*AuthEntity) LoadNKey

func (a *AuthEntity) LoadNKey() error

type NKey

type NKey struct {
	// Seed contains the public and private key in base32.
	// The KeyPair can be extracted from the seed, and used to sign JWTs.
	// Warning: keep this secure!!
	Seed    string        `json:"seed"`
	KeyPair nkeys.KeyPair `json:"-"`
	// PublicKey is used to identify the entity.
	// It acts like an ID in NATS.
	PublicKey string `json:"public_key"`
}

func NewAccountNKey

func NewAccountNKey() (*NKey, error)

func NewOperatorNKey

func NewOperatorNKey() (*NKey, error)

func NewUserNKey

func NewUserNKey() (*NKey, error)

func (*NKey) LoadNKey

func (n *NKey) LoadNKey() error

type Server

type Server struct {
	NS   *server.Server
	Auth ServerJWTAuth
}

func NewServer

func NewServer(opts ...ServerOption) (Server, error)

func (Server) Close

func (s Server) Close() error

func (Server) PublishRootNamespace

func (s Server) PublishRootNamespace() error

PublishRootNamespace publishes the root account JWT to the server. This is required to be able to connect to the server with the root account and therefore needs to happen once the server has been started.

func (Server) RootUserConn

func (s Server) RootUserConn() (*nats.Conn, error)

RootUserConn uses the root user JWT to connect to the server.

func (Server) StartUntilReady

func (s Server) StartUntilReady() error

type ServerConfig

type ServerConfig struct {
	Dir                 string
	Debug               bool
	Host                string
	Port                int
	OperatorJWT         string
	SysAccountPublicKey string
	SysAccountJWT       string
}

type ServerJWTAuth

type ServerJWTAuth struct {
	// AccountServerURL is the configured `account_server_url` for the operator
	AccountServerURL string `json:"account_server_url"`

	Operator AuthEntity `json:"operator"`

	// SysAccount is the NATS system account.
	// It should not be needed outside of bootstrapping.
	SysAccount AuthEntity `json:"sys_account"`
	// SysUser is a user that has access to the the NATS system account.
	// It should not be needed outside of bootstrapping.
	SysUser AuthEntity `json:"sys_user"`

	// RootAccount is the Horizon root account.
	// The root account is where all the data is stored.
	RootAccount AuthEntity `json:"root_account"`
	// RootUser is a user that has access to the the Horizon root account.
	// It should not be needed outside of bootstrapping.
	RootUser AuthEntity `json:"root_user"`
}

func BootstrapServerJWTAuth

func BootstrapServerJWTAuth() (ServerJWTAuth, error)

func LoadServerJWTAuth

func LoadServerJWTAuth(file string) (ServerJWTAuth, error)

LoadServerJWTAuth loads the ServerJWTAuth from the given file. This method is intended to use for testing controllers/actors or other services with a local running instance of the horizon server.

For other use cases, you should create nats credentials via the horizon server and provide those to the services you need to connect to NATS/Horizon.

func (*ServerJWTAuth) LoadKeyPairs

func (s *ServerJWTAuth) LoadKeyPairs() error

type ServerOption

type ServerOption func(*serverOption)

func WithConfigureLogger

func WithConfigureLogger(logger bool) ServerOption

func WithDir

func WithDir(dir string) ServerOption

func WithFindAvailablePort

func WithFindAvailablePort(enabled bool) ServerOption

func WithJWTAuth

func WithJWTAuth(jwtAuth ServerJWTAuth) ServerOption

func WithPort

func WithPort(port int) ServerOption

Jump to

Keyboard shortcuts

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