client

package
v0.0.0-...-07a382d Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: LGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTransportTimeout = 1 * time.Minute
)

Default value for client requests to wait for a reply

Variables

This section is empty.

Functions

func APIPath

func APIPath(path ...string) string

APIPath prefixes API version to a path

Types

type Certificates

type Certificates interface {
	ListCertificates() (certificates []api.Certificate, err error)
	AddCertificate(base64PublicKey, trustPassword string) (err error)
	RetrieveCertificate(fingerprint string) (certificate *api.Certificate, err error)
	DeleteCertificate(fingerprint string) (op Operation, err error)
}

The Certificates interface represents client certificates related API methods

func UpgradeToCertificatesClient

func UpgradeToCertificatesClient(c Client) Certificates

UpgradeToCertificatesClient wraps generic client to implement Operations interface operations

type Client

type Client interface {
	ServiceURL() string
	HTTPTransport() *http.Transport

	SetTransportTimeout(timeout time.Duration)

	QueryStruct(method, path string, params QueryParams, header http.Header, body io.Reader, ETag string, target interface{}) (etag string, err error)
	QueryOperation(method, path string, params QueryParams, header http.Header, body io.Reader, ETag string) (operation Operation, etag string, err error)
	CallAPI(method, path string, params QueryParams, header http.Header, body io.Reader, ETag string) (response *api.Response, etag string, err error)
	DownloadFile(path string, params QueryParams, header http.Header, downloader func(header *http.Header, body io.ReadCloser) error) error

	Websocket(resource string) (conn *websocket.Conn, err error)

	// Event handling functions
	GetEvents() (listener *EventListener, err error)
}

The Client interface represents all available REST client operations

func New

func New(addr interface{}, tlsConfig *tls.Config) (Client, error)

New returns a REST client. Depending on provided addr parameter, it connects to a remote network server or through a unix socket

type Doer

type Doer interface {
	Do(*http.Request) (*http.Response, error)
}

Doer is the implementation of the Client engine

type EventListener

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

The EventListener struct is used to interact with an event stream

func (*EventListener) AddHandler

func (e *EventListener) AddHandler(types []string, function func(interface{})) (*EventTarget, error)

AddHandler adds a function to be called whenever an event is received

func (*EventListener) Disconnect

func (e *EventListener) Disconnect()

Disconnect must be used once done listening for events

func (*EventListener) IsActive

func (e *EventListener) IsActive() bool

IsActive returns true if this listener is still connected, false otherwise.

func (*EventListener) RemoveHandler

func (e *EventListener) RemoveHandler(target *EventTarget) error

RemoveHandler removes a function to be called whenever an event is received

func (*EventListener) Wait

func (e *EventListener) Wait() error

Wait hangs until the server disconnects the connection or Disconnect() is called

type EventTarget

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

The EventTarget struct is returned to the caller of AddHandler and used in RemoveHandler

type Operation

type Operation interface {
	AddHandler(function func(api.Operation)) (target *EventTarget, err error)
	Cancel() (err error)
	Get() (op api.Operation)
	RemoveHandler(target *EventTarget) (err error)
	Refresh() (err error)
	Wait(ctx context.Context) (err error)
}

The Operation interface represents a currently running operation.

type Operations

type Operations interface {
	ListOperationUUIDs() (uuids []string, err error)
	ListOperations() (operations []api.Operation, err error)
	RetrieveOperationByID(uuid string) (op *api.Operation, etag string, err error)
	WaitForOperationToFinish(uuid string, timeout time.Duration) (op *api.Operation, err error)
	GetOperationWebsocket(uuid, secret string) (conn *websocket.Conn, err error)
	DeleteOperation(uuid string) (err error)
}

The Operations interface represents operations exposed API methods

func UpgradeToOperationsClient

func UpgradeToOperationsClient(c Client) Operations

UpgradeToOperationsClient wraps generic client to implement Operations interface operations

type QueryParams

type QueryParams map[string]string

QueryParams request query parameter

Jump to

Keyboard shortcuts

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