client

package
v3.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddClusterMember

func AddClusterMember(ctx context.Context, c types.Client, args types.ClusterMember) (*types.TokenResponse, error)

AddClusterMember records a new cluster member in the trust store of each current cluster member.

func AddTrustStoreEntry

func AddTrustStoreEntry(ctx context.Context, c types.Client, args types.ClusterMemberLocal) error

AddTrustStoreEntry adds a new record to the truststore on all cluster members.

func CheckReady

func CheckReady(ctx context.Context, c types.Client) error

CheckReady returns once the daemon has signalled to the ready channel that it is done setting up.

func ControlDaemon

func ControlDaemon(ctx context.Context, c types.Client, args types.Control) error

ControlDaemon posts control data to the daemon.

func DeleteClusterMember

func DeleteClusterMember(ctx context.Context, c types.Client, name string, address string, force bool) error

DeleteClusterMember deletes the cluster member with the given name. If `address` is non-empty it is sent as a query parameter to target dqlite removal by address when the truststore cannot map name to address. Dqlite does not track names, so this is useful when the name is no longer resolvable.

func DeleteTokenRecord

func DeleteTokenRecord(ctx context.Context, c types.Client, name string) error

DeleteTokenRecord deletes the token record.

func DeleteTrustStoreEntry

func DeleteTrustStoreEntry(ctx context.Context, c types.Client, name string) error

DeleteTrustStoreEntry deletes the record corresponding to the given cluster member from the trust store.

func GetClusterMembers

func GetClusterMembers(ctx context.Context, c types.Client) ([]types.ClusterMember, error)

GetClusterMembers returns the database record of cluster members.

func GetSQL

func GetSQL(ctx context.Context, c types.Client, schema bool) (*types.SQLDump, error)

GetSQL gets a SQL dump of the database.

func GetTokenRecords

func GetTokenRecords(ctx context.Context, c types.Client) ([]types.TokenRecord, error)

GetTokenRecords returns the token records.

func IsForwardedRequest

func IsForwardedRequest(r *http.Request) bool

IsForwardedRequest determines if this request has been forwarded from another cluster member.

func PostSQL

func PostSQL(ctx context.Context, c types.Client, query types.SQLQuery) (*types.SQLBatch, error)

PostSQL executes a SQL query against the database.

func RequestToken

func RequestToken(ctx context.Context, c types.Client, name string, expireAfter time.Duration) (string, error)

RequestToken requests a join token with the given name.

func ResetClusterMember

func ResetClusterMember(ctx context.Context, c types.Client, name string, force bool) error

ResetClusterMember clears the state directory of the cluster member, and re-execs its daemon.

func RunNewMemberHook

func RunNewMemberHook(ctx context.Context, c types.Client, config types.HookNewMemberOptions) error

RunNewMemberHook executes the OnNewMember hook with the given configuration on the cluster member targeted by this client.

func RunOnDaemonConfigUpdateHook

func RunOnDaemonConfigUpdateHook(ctx context.Context, c types.Client, config *types.DaemonConfig) error

RunOnDaemonConfigUpdateHook executes the OnDaemonConfigUpdate hook with the given configuration on the cluster member targeted by this client.

func RunPostRemoveHook

func RunPostRemoveHook(ctx context.Context, c types.Client, config types.HookRemoveMemberOptions) error

RunPostRemoveHook executes the PostRemove hook with the given configuration on the cluster member targeted by this client.

func RunPreRemoveHook

func RunPreRemoveHook(ctx context.Context, c types.Client, config types.HookRemoveMemberOptions) error

RunPreRemoveHook executes the PreRemove hook with the given configuration on the cluster member targeted by this client.

func ShutdownDaemon

func ShutdownDaemon(ctx context.Context, c types.Client) error

ShutdownDaemon begins the daemon shutdown sequence.

func TLSClientConfig

func TLSClientConfig(clientCert *shared.CertInfo, remoteCert *x509.Certificate) (*tls.Config, error)

TLSClientConfig returns a TLS configuration suitable for establishing horizontal and vertical connections. clientCert contains the private key pair for the client. remoteCert is the public key of the server we are connecting to.

func UpdateCertificate

func UpdateCertificate(ctx context.Context, c types.Client, name types.CertificateName, args types.KeyPair) error

UpdateCertificate sets a new keypair and CA.

func UpdateServers

func UpdateServers(ctx context.Context, c types.Client, config map[string]types.ServerConfig) error

UpdateServers updates the additional servers config.

Types

type Client

type Client struct {
	*http.Client
	// contains filtered or unexported fields
}

Client is a rest client for the daemon.

func New

func New(url *url.URL, clientCert *shared.CertInfo, remoteCert *x509.Certificate, forwarding bool) (*Client, error)

New returns a new client configured with the given url and certificates.

func (*Client) HTTP

func (c *Client) HTTP() *http.Client

HTTP returns the underlying HTTP client to allow direct modification.

func (*Client) MakeRequest

func (c *Client) MakeRequest(r *http.Request) (*api.Response, error)

MakeRequest performs a request and parses the response into an api.Response. This function can be used instead of the QueryStruct if custom settings have to be applied to the request struct.

func (*Client) Query

func (c *Client) Query(ctx context.Context, method string, endpointType types.EndpointPrefix, endpoint *url.URL, data any, target any) error

Query sends a request of the specified method to the provided endpoint (optional) on the API matching the endpointType. The response gets unpacked into the target struct. POST requests can optionally provide raw data to be sent through.

The final URL is that provided as the endpoint combined with the applicable prefix for the endpointType and the scheme and host from the client.

func (*Client) QueryRaw

func (c *Client) QueryRaw(ctx context.Context, method string, prefix types.EndpointPrefix, path *url.URL, in any) (*http.Response, error)

QueryRaw is a helper for initiating a request on any endpoints defined external to microcluster. Unlike Query it returns the raw HTTP response.

func (*Client) QueryStructRaw

func (c *Client) QueryStructRaw(ctx context.Context, method string, endpointType types.EndpointPrefix, endpoint *url.URL, data any) (*http.Response, error)

QueryStructRaw sends a request of the specified method to the provided endpoint (optional) on the API matching the endpointType. The raw response is returned. POST requests can optionally provide raw data to be sent through.

The final URL is that provided as the endpoint combined with the applicable prefix for the endpointType and the scheme and host from the client.

func (*Client) RawWebsocket

func (c *Client) RawWebsocket(ctx context.Context, endpointType types.EndpointPrefix, endpoint *url.URL) (*websocket.Conn, error)

RawWebsocket dials the provided endpoint and tries to upgrade the connection.

The final URL is that provided as the endpoint combined with the applicable prefix for the endpointType and the scheme and host from the client.

func (*Client) SetClusterNotification

func (c *Client) SetClusterNotification()

SetClusterNotification sets the client's proxy to apply the forwarding headers to a request.

func (*Client) URL

func (c *Client) URL() *url.URL

URL returns the address used for the client.

func (*Client) UseTarget

func (c *Client) UseTarget(name string) types.Client

UseTarget returns a new client with the query "?target=name" set.

func (*Client) Websocket

func (c *Client) Websocket(ctx context.Context, prefix types.EndpointPrefix, path *url.URL) (*websocket.Conn, error)

Websocket is a helper for upgrading a request to websocket on any endpoints defined external to microcluster. This function should be used for all client methods defined externally from microcluster.

type CtxKey

type CtxKey string

CtxKey is the type used for all fields stored in the request context by Microcluster.

const (
	// CtxAccess is the access field in request context.
	CtxAccess CtxKey = "access"
)

Jump to

Keyboard shortcuts

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