hdsclient

package
v0.1.12 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// The Hagall endpoint.
	HagallEndpoint string

	// The Hagall Discovery Service endpoint.
	HDSEndpoint string

	// The HTTP transport used to communicate with the Hagall Discovery Service.
	// (optional)
	Transport http.RoundTripper

	// The function to encode request bodies.
	Encode Encoder

	// The function to decode response bodies.
	Decode Decoder

	// Setting RemoteAddr to insert a http header x-real-ip=RemoteAddr to request,
	// allows override of client IP address which read from req.RemoteAddr by default
	RemoteAddr string
	// contains filtered or unexported fields
}

Client represents an HTTP client to communicate with Hagall Discovery Service.

func NewClient

func NewClient(opts ...ClientOpts) *Client

NewClient creates new client with optional parameters.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, path string) error

Delete sends a DELETE request to the given path.

func (*Client) DeleteServer

func (c *Client) DeleteServer(ctx context.Context) error

DeleteServer unregisters a server from HDS.

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string, out interface{}) error

Get sends a GET request to the given path and stores result in the given output.

func (*Client) GetRegistrationState

func (c *Client) GetRegistrationState() string

GetRegistrationState returns current registration state.

func (*Client) GetRegistrationStatus

func (c *Client) GetRegistrationStatus() RegistrationStatus

GetRegistrationStatus returns current registration status.

func (*Client) GetServerByEndpoint

func (c *Client) GetServerByEndpoint(ctx context.Context, in GetServerByEndpointIn) (ServerResponse, error)

GetServerByEndpoint returns the server with the given endpoint from HDS.

func (*Client) GetServerByID

func (c *Client) GetServerByID(ctx context.Context, in GetServerByIDIn) (ServerResponse, error)

GetServerByID returns the server with the given id from HDS.

func (*Client) GetServers

func (c *Client) GetServers(ctx context.Context, in GetServersIn) (GetServersResponse, error)

GetServers returns a list of the closest servers.

func (*Client) GetWithAuth

func (c *Client) GetWithAuth(
	ctx context.Context, path, appKey, appSecret string, queries map[string]string, out interface{},
) error

GetWithAuth sends a GET request to the given path and stores result in the given output. It uses app key and app secret for basic authentication.

func (*Client) HandleHealthCheck

func (c *Client) HandleHealthCheck(w http.ResponseWriter, r *http.Request)

HandleHealthCheck handles Hagall server health checks.

This handler is meant to be used by a Hagall server under the /health path.

func (*Client) HandleServerRegistration

func (c *Client) HandleServerRegistration(w http.ResponseWriter, r *http.Request)

HandleServerRegistration handles Hagall server registration.

When a request succeeds, the Hagall server secret is stored within the client and is available by calling the Secret method.

Once the secret is transmitted, further calls to this handler result in a FORBIDDEN response.

This handler is meant to be used by a Hagall server under the /registrations path.

func (*Client) LastHealthCheck

func (c *Client) LastHealthCheck() time.Time

LastHealthCheck returns the time when HDS performed the latest healthcheck.

func (*Client) Pair

func (c *Client) Pair(ctx context.Context, in PairIn) error

Pair pairs the client with HDS, registering an endpoint when necessary.

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, in interface{}) error

Post sends a POST request to the given path with the given input.

func (*Client) PostServer

func (c *Client) PostServer(ctx context.Context, in PostServerIn) error

PostServer registers a server to HDS.

func (*Client) PostSession

func (c *Client) PostSession(ctx context.Context, in PostSessionIn) error

PostSession registers a session to HDS.

func (*Client) Secret

func (c *Client) Secret() string

Secret returns the attributed JWT secret.

func (*Client) SendSmokeTestResult

func (c *Client) SendSmokeTestResult(ctx context.Context, results hsmoketest.SmokeTestResults) error

SendSmokeTestResult sends smoke test results to HDS /smoke-test-results endpoint.

func (*Client) ServerID

func (c *Client) ServerID() string

ServerID returns the attributed server ID.

func (*Client) SetLastHealthCheck

func (c *Client) SetLastHealthCheck(t time.Time)

SetLastHealthCheck set the time when HDS performed the latest healthcheck.

func (*Client) SetServerData

func (c *Client) SetServerData(serverID, secret string)

SetServerData sets internal serverID & server secret state.

func (*Client) Unpair

func (c *Client) Unpair() error

Unpair deregisters Hagall from HDS.

func (*Client) UserAuth

func (c *Client) UserAuth(ctx context.Context, in UserAuthIn) (UserAuthResponse, error)

UserAuth auhenticates a user to a given server.

func (*Client) VerifyUserAuth

func (c *Client) VerifyUserAuth(token string) error

VerifyUserAuth verifies a user's identity.

type ClientOpts

type ClientOpts func(*Client)

func WithClientID

func WithClientID(v string) ClientOpts

func WithDecoder

func WithDecoder(v Decoder) ClientOpts

func WithEncoder

func WithEncoder(v Encoder) ClientOpts

func WithHDSEndpoint

func WithHDSEndpoint(v string) ClientOpts

func WithHagallEndpoint

func WithHagallEndpoint(v string) ClientOpts

func WithPrivateKey

func WithPrivateKey(v *ecdsa.PrivateKey) ClientOpts

func WithRemoteAddr

func WithRemoteAddr(v string) ClientOpts

func WithSecret

func WithSecret(v string) ClientOpts

func WithServerID

func WithServerID(v string) ClientOpts

func WithTransport

func WithTransport(v http.RoundTripper) ClientOpts

type Decoder

type Decoder func([]byte, interface{}) error

type Encoder

type Encoder func(interface{}) ([]byte, error)

type GetServerByEndpointIn

type GetServerByEndpointIn struct {
	Endpoint  string `json:"-"`
	AppKey    string `json:"-"`
	AppSecret string `json:"-"`
}

GetServerByEndpointIn is the input to retrieve a server by it's endpoint from HDS.

type GetServerByIDIn

type GetServerByIDIn struct {
	ServerID  string `json:"-"`
	AppKey    string `json:"-"`
	AppSecret string `json:"-"`
}

GetServerByIDIn is the input to retrieve a server by it's id from HDS.

type GetServersIn

type GetServersIn struct {
	AppKey       string   `json:"-"`
	AppSecret    string   `json:"-"`
	MinVersion   string   `json:"-"`
	Modules      []string `json:"-"`
	FeatureFlags []string `json:"-"`
}

GetServersIn is the input to get a list of the closest servers.

type GetServersResponse

type GetServersResponse []ServerResponse

type GetSessionIn

type GetSessionIn struct {
	ID string
}

GetSessionIn is the input to get a session from HDS.

type PairIn

type PairIn struct {
	// The Hagall server endpoint. Optional.
	Endpoint string

	// The Hagall server version.
	Version string

	// The modules that the server supports.
	Modules []string

	// The feature flags that the server supports.
	FeatureFlags []string

	// The interval between each registration try.
	RegistrationInterval time.Duration

	// The elapsed time required since the last health check to trigger a new
	// registration.
	HealthCheckTTL time.Duration

	// The number of retries before returning with error.
	RegistrationRetries int
}

PairIn is the input to pair the client with HDS.

type PostServerIn

type PostServerIn struct {
	// The Hagall server endpoint. Optional.
	Endpoint string `json:"endpoint"`

	// The endpoint URL signature signed by the wallet.
	EndpointSignature string `json:"endpoint_signature"`

	// The Hagall server version.
	Version string `json:"version"`

	// A string that represents a registration state that is used during Hagall
	// server verification to ensure that the registration request originates
	// from the server that started the registration process.
	State string `json:"state"`

	// The modules that the server supports.
	Modules []string `json:"modules"`

	// Feature flags supported by server.
	FeatureFlags []string `json:"feature_flags"`

	// The timestamp when endpoint signature was signed.
	Timestamp string `json:"timestamp"`
}

PostServerIn represents the input to register a server to HDS.

type PostSessionIn

type PostSessionIn struct {
	ID string `json:"id"`
}

PostSessionIn is the input to register a session to HDS.

type RegistrationStatus

type RegistrationStatus int
const (
	RegistrationStatusInit                RegistrationStatus = 0
	RegistrationStatusRegistering         RegistrationStatus = 1
	RegistrationStatusPendingVerification RegistrationStatus = 2
	RegistrationStatusRegistered          RegistrationStatus = 3
	RegistrationStatusFailed              RegistrationStatus = 4
)

type ServerResponse

type ServerResponse struct {
	ID            string   `json:"id"`
	Endpoint      string   `json:"endpoint"`
	AccessToken   string   `json:"access_token"`
	Version       string   `json:"version"`
	Modules       []string `json:"modules"`
	FeatureFlags  []string `json:"feature_flags"`
	WalletAddress string   `json:"wallet_address"`
}

type UserAuthIn

type UserAuthIn struct {
	Endpoint  string `json:"endpoint"`
	AppKey    string `json:"-"`
	AppSecret string `json:"-"`
}

UserAuthIn represents the input to authenticate to a Hagall server.

type UserAuthResponse

type UserAuthResponse struct {
	AccessToken string `json:"access_token"`
}

Jump to

Keyboard shortcuts

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