client

package
v0.67.4 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: BSD-3-Clause Imports: 22 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const ConnectTimeout = 10 * time.Second
View Source
const (
	// EnvMaxRecvMsgSize overrides the default gRPC max receive message size (4 MB)
	// for the management client connection. Value is in bytes.
	EnvMaxRecvMsgSize = "NB_MANAGEMENT_GRPC_MAX_MSG_SIZE"
)

Variables

This section is empty.

Functions

func MaxRecvMsgSize added in v0.67.0

func MaxRecvMsgSize() int

MaxRecvMsgSize returns the configured max gRPC receive message size from the environment, or 0 if unset (which uses the gRPC default of 4 MB).

Types

type Client

type Client interface {
	io.Closer
	Sync(ctx context.Context, sysInfo *system.Info, msgHandler func(msg *proto.SyncResponse) error) error
	Job(ctx context.Context, msgHandler func(msg *proto.JobRequest) *proto.JobResponse) error
	GetServerPublicKey() (*wgtypes.Key, error)
	Register(serverKey wgtypes.Key, setupKey string, jwtToken string, sysInfo *system.Info, sshKey []byte, dnsLabels domain.List) (*proto.LoginResponse, error)
	Login(serverKey wgtypes.Key, sysInfo *system.Info, sshKey []byte, dnsLabels domain.List) (*proto.LoginResponse, error)
	GetDeviceAuthorizationFlow(serverKey wgtypes.Key) (*proto.DeviceAuthorizationFlow, error)
	GetPKCEAuthorizationFlow(serverKey wgtypes.Key) (*proto.PKCEAuthorizationFlow, error)
	GetNetworkMap(sysInfo *system.Info) (*proto.NetworkMap, error)
	GetServerURL() string
	IsHealthy() bool
	SyncMeta(sysInfo *system.Info) error
	Logout() error
	CreateExpose(ctx context.Context, req ExposeRequest) (*ExposeResponse, error)
	RenewExpose(ctx context.Context, domain string) error
	StopExpose(ctx context.Context, domain string) error
}

Client is the interface for the management service client.

type ConnStateNotifier

type ConnStateNotifier interface {
	MarkManagementDisconnected(error)
	MarkManagementConnected()
}

ConnStateNotifier is a wrapper interface of the status recorders

type ExposeRequest added in v0.66.0

type ExposeRequest struct {
	NamePrefix string
	Domain     string
	Port       uint16
	Protocol   int
	Pin        string
	Password   string
	UserGroups []string
	ListenPort uint16
}

type ExposeResponse added in v0.66.0

type ExposeResponse struct {
	ServiceName      string
	Domain           string
	ServiceURL       string
	PortAutoAssigned bool
}

type GrpcClient

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

func NewClient

func NewClient(ctx context.Context, addr string, ourPrivateKey wgtypes.Key, tlsEnabled bool) (*GrpcClient, error)

NewClient creates a new client to Management service

func (*GrpcClient) Close

func (c *GrpcClient) Close() error

Close closes connection to the Management Service

func (*GrpcClient) CreateExpose added in v0.66.0

func (c *GrpcClient) CreateExpose(ctx context.Context, req ExposeRequest) (*ExposeResponse, error)

CreateExpose calls the management server to create a new expose service.

func (*GrpcClient) GetDeviceAuthorizationFlow

func (c *GrpcClient) GetDeviceAuthorizationFlow(serverKey wgtypes.Key) (*proto.DeviceAuthorizationFlow, error)

GetDeviceAuthorizationFlow returns a device authorization flow information. It also takes care of encrypting and decrypting messages.

func (*GrpcClient) GetNetworkMap

func (c *GrpcClient) GetNetworkMap(sysInfo *system.Info) (*proto.NetworkMap, error)

GetNetworkMap return with the network map

func (*GrpcClient) GetPKCEAuthorizationFlow

func (c *GrpcClient) GetPKCEAuthorizationFlow(serverKey wgtypes.Key) (*proto.PKCEAuthorizationFlow, error)

GetPKCEAuthorizationFlow returns a pkce authorization flow information. It also takes care of encrypting and decrypting messages.

func (*GrpcClient) GetServerPublicKey

func (c *GrpcClient) GetServerPublicKey() (*wgtypes.Key, error)

GetServerPublicKey returns server's WireGuard public key (used later for encrypting messages sent to the server)

func (*GrpcClient) GetServerURL added in v0.67.0

func (c *GrpcClient) GetServerURL() string

GetServerURL returns the management server URL

func (*GrpcClient) IsHealthy

func (c *GrpcClient) IsHealthy() bool

IsHealthy probes the gRPC connection and returns false on errors

func (*GrpcClient) Job added in v0.64.0

func (c *GrpcClient) Job(ctx context.Context, msgHandler func(msg *proto.JobRequest) *proto.JobResponse) error

Job wraps the real client's Job endpoint call and takes care of retries and encryption/decryption of messages Blocking request. The result will be sent via msgHandler callback function

func (*GrpcClient) Login

func (c *GrpcClient) Login(serverKey wgtypes.Key, sysInfo *system.Info, pubSSHKey []byte, dnsLabels domain.List) (*proto.LoginResponse, error)

Login attempts login to Management Server. Takes care of encrypting and decrypting messages.

func (*GrpcClient) Logout

func (c *GrpcClient) Logout() error

func (*GrpcClient) Register

func (c *GrpcClient) Register(serverKey wgtypes.Key, setupKey string, jwtToken string, sysInfo *system.Info, pubSSHKey []byte, dnsLabels domain.List) (*proto.LoginResponse, error)

Register registers peer on Management Server. It actually calls a Login endpoint with a provided setup key Takes care of encrypting and decrypting messages. This method will also collect system info and send it with the request (e.g. hostname, os, etc)

func (*GrpcClient) RenewExpose added in v0.66.0

func (c *GrpcClient) RenewExpose(ctx context.Context, domain string) error

RenewExpose extends the TTL of an active expose session on the management server.

func (*GrpcClient) SetConnStateListener

func (c *GrpcClient) SetConnStateListener(notifier ConnStateNotifier)

SetConnStateListener set the ConnStateNotifier

func (*GrpcClient) StopExpose added in v0.66.0

func (c *GrpcClient) StopExpose(ctx context.Context, domain string) error

StopExpose terminates an active expose session on the management server.

func (*GrpcClient) Sync

func (c *GrpcClient) Sync(ctx context.Context, sysInfo *system.Info, msgHandler func(msg *proto.SyncResponse) error) error

Sync wraps the real client's Sync endpoint call and takes care of retries and encryption/decryption of messages Blocking request. The result will be sent via msgHandler callback function

func (*GrpcClient) SyncMeta

func (c *GrpcClient) SyncMeta(sysInfo *system.Info) error

SyncMeta sends updated system metadata to the Management Service. It should be used if there is changes on peer posture check after initial sync.

type MockClient

type MockClient struct {
	CloseFunc                      func() error
	SyncFunc                       func(ctx context.Context, sysInfo *system.Info, msgHandler func(msg *proto.SyncResponse) error) error
	GetServerPublicKeyFunc         func() (*wgtypes.Key, error)
	RegisterFunc                   func(serverKey wgtypes.Key, setupKey string, jwtToken string, info *system.Info, sshKey []byte, dnsLabels domain.List) (*proto.LoginResponse, error)
	LoginFunc                      func(serverKey wgtypes.Key, info *system.Info, sshKey []byte, dnsLabels domain.List) (*proto.LoginResponse, error)
	GetDeviceAuthorizationFlowFunc func(serverKey wgtypes.Key) (*proto.DeviceAuthorizationFlow, error)
	GetPKCEAuthorizationFlowFunc   func(serverKey wgtypes.Key) (*proto.PKCEAuthorizationFlow, error)
	GetServerURLFunc               func() string
	SyncMetaFunc                   func(sysInfo *system.Info) error
	LogoutFunc                     func() error
	JobFunc                        func(ctx context.Context, msgHandler func(msg *proto.JobRequest) *proto.JobResponse) error
	CreateExposeFunc               func(ctx context.Context, req ExposeRequest) (*ExposeResponse, error)
	RenewExposeFunc                func(ctx context.Context, domain string) error
	StopExposeFunc                 func(ctx context.Context, domain string) error
}

MockClient is a mock implementation of the Client interface for testing.

func (*MockClient) Close

func (m *MockClient) Close() error

func (*MockClient) CreateExpose added in v0.66.0

func (m *MockClient) CreateExpose(ctx context.Context, req ExposeRequest) (*ExposeResponse, error)

func (*MockClient) GetDeviceAuthorizationFlow

func (m *MockClient) GetDeviceAuthorizationFlow(serverKey wgtypes.Key) (*proto.DeviceAuthorizationFlow, error)

func (*MockClient) GetNetworkMap

func (m *MockClient) GetNetworkMap(_ *system.Info) (*proto.NetworkMap, error)

GetNetworkMap mock implementation of GetNetworkMap from Client interface.

func (*MockClient) GetPKCEAuthorizationFlow

func (m *MockClient) GetPKCEAuthorizationFlow(serverKey wgtypes.Key) (*proto.PKCEAuthorizationFlow, error)

func (*MockClient) GetServerPublicKey

func (m *MockClient) GetServerPublicKey() (*wgtypes.Key, error)

func (*MockClient) GetServerURL added in v0.67.0

func (m *MockClient) GetServerURL() string

GetServerURL mock implementation of GetServerURL from mgm.Client interface

func (*MockClient) IsHealthy

func (m *MockClient) IsHealthy() bool

func (*MockClient) Job added in v0.64.0

func (m *MockClient) Job(ctx context.Context, msgHandler func(msg *proto.JobRequest) *proto.JobResponse) error

func (*MockClient) Login

func (m *MockClient) Login(serverKey wgtypes.Key, info *system.Info, sshKey []byte, dnsLabels domain.List) (*proto.LoginResponse, error)

func (*MockClient) Logout

func (m *MockClient) Logout() error

func (*MockClient) Register

func (m *MockClient) Register(serverKey wgtypes.Key, setupKey string, jwtToken string, info *system.Info, sshKey []byte, dnsLabels domain.List) (*proto.LoginResponse, error)

func (*MockClient) RenewExpose added in v0.66.0

func (m *MockClient) RenewExpose(ctx context.Context, domain string) error

func (*MockClient) StopExpose added in v0.66.0

func (m *MockClient) StopExpose(ctx context.Context, domain string) error

func (*MockClient) Sync

func (m *MockClient) Sync(ctx context.Context, sysInfo *system.Info, msgHandler func(msg *proto.SyncResponse) error) error

func (*MockClient) SyncMeta

func (m *MockClient) SyncMeta(sysInfo *system.Info) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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