gatewayclient

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 16 Imported by: 2

Documentation

Overview

package gatewayclient implements a client for kwild that can also authenticate with a kwil gateway.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GatewayAuthSignFunc

type GatewayAuthSignFunc func(message string, signer auth.Signer) (*auth.Signature, error)

GatewayAuthSignFunc is the function that signs the authentication message.

type GatewayClient

type GatewayClient struct {
	client.Client
	// contains filtered or unexported fields
}

GatewayClient is a client that is made to interact with a kwil gateway. It inherits the functionality of the main Kwil client, but also provides authentication cookies to the gateway. It automatically handles the authentication process with the gateway.

func NewClient

func NewClient(ctx context.Context, target string, opts *GatewayOptions) (*GatewayClient, error)

func (*GatewayClient) Authenticate

func (c *GatewayClient) Authenticate(ctx context.Context) error

Authenticate will authenticate the client with the gateway. This is not necessary, as the client will automatically authenticate when needed, however it can be useful if the client desires to control when the authentication occurs / wants to manually force re-authentication.

func (*GatewayClient) CallAction

func (c *GatewayClient) CallAction(ctx context.Context, dbid string, action string, inputs []any) (*clientType.Records, error)

CallAction call an action. It returns the result records. If authentication is needed, it will call the gatewaySigner to sign the authentication message.

func (*GatewayClient) GetAuthCookie

func (c *GatewayClient) GetAuthCookie() (cookie *http.Cookie, found bool)

GetAuthCookie returns the authentication cookie currently being used. If no authentication cookie is being used, it returns nil, false.

func (*GatewayClient) SetAuthCookie

func (c *GatewayClient) SetAuthCookie(cookie *http.Cookie) error

SetAuthCookie sets the authentication cookie to be used. If the cookie is not valid for the client target, it returns an error. It will overwrite any existing authentication cookie.

type GatewayOptions

type GatewayOptions struct {
	clientType.Options

	// AuthSignFunc is a function that will be used to sign gateway authentication messages.
	AuthSignFunc GatewayAuthSignFunc

	AuthCookieHandler func(*http.Cookie) error
}

GatewayOptions are options that can be set for the gateway client

func DefaultOptions

func DefaultOptions() *GatewayOptions

DefaultOptions returns the default options for the gateway client.

func (*GatewayOptions) Apply

func (c *GatewayOptions) Apply(opt *GatewayOptions)

Apply applies the passed options to the receiver.

Jump to

Keyboard shortcuts

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