Documentation ¶
Overview ¶
package gatewayclient implements a client for kwild that can also authenticate with a kwil gateway.
Index ¶
- type GatewayAuthSignFunc
- type GatewayClient
- func (c *GatewayClient) Authenticate(ctx context.Context) error
- func (c *GatewayClient) Call(ctx context.Context, dbid string, action string, inputs []any) (*clientType.CallResult, error)
- func (c *GatewayClient) CallAction(ctx context.Context, dbid string, action string, inputs []any) (*clientType.Records, error)
- func (c *GatewayClient) GetAuthCookie() (cookie *http.Cookie, found bool)
- func (c *GatewayClient) SetAuthCookie(cookie *http.Cookie) error
- type GatewayOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GatewayAuthSignFunc ¶
GatewayAuthSignFunc is the function that signs the authentication message.
type GatewayClient ¶
type GatewayClient struct { client.Client // core 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)
NewClient creates a new gateway client. The target should be the root URL of the gateway. It uses core/client as the underlying client to interact with the gateway for kwil-db specific jsonrpc requests, core/rpc/client/gateway/jsonrpc for gateway specific jsonrpc requests, and sharing the same http connection. See GatewayOptions for options that can be set.
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) Call ¶ added in v0.2.0
func (c *GatewayClient) Call(ctx context.Context, dbid string, action string, inputs []any) (*clientType.CallResult, error)
Call call an action. It returns the result records. If authentication is needed, it will call the gatewaySigner to sign the authentication message.
func (*GatewayClient) CallAction ¶
func (c *GatewayClient) CallAction(ctx context.Context, dbid string, action string, inputs []any) (*clientType.Records, error)
CallAction calls an action. It returns the result records. If authentication is needed, Deprecated: Use Call instead.
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. By default, it's set to just sign the message // using the client's signer. AuthSignFunc GatewayAuthSignFunc // AuthCookieHandler is a function that will be called whenever a cookie is // being set to cookie jar. No default is set. 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.