apiclient

package
v0.10.5 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package apiclient implements a client for connecting to Kopia HTTP API server.

Index

Constants

View Source
const CSRFTokenHeader = "X-Kopia-Csrf-Token"

CSRFTokenHeader is the name of CSRF token header that must be sent for most API calls. nolint:gosec

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPStatusError added in v0.8.0

type HTTPStatusError struct {
	HTTPStatusCode int
	ErrorMessage   string
}

HTTPStatusError encapsulates HTTP status error.

func (HTTPStatusError) Error added in v0.8.0

func (e HTTPStatusError) Error() string

type KopiaAPIClient

type KopiaAPIClient struct {
	BaseURL    string
	HTTPClient *http.Client

	CSRFToken string
}

KopiaAPIClient provides helper methods for communicating with Kopia API server.

func NewKopiaAPIClient

func NewKopiaAPIClient(options Options) (*KopiaAPIClient, error)

NewKopiaAPIClient creates a client for connecting to Kopia HTTP API.

func (*KopiaAPIClient) Delete

func (c *KopiaAPIClient) Delete(ctx context.Context, urlSuffix string, onNotFound error, reqPayload, respPayload interface{}) error

Delete is a helper that performs HTTP DELETE on a URL with the specified body from reqPayload and decodes the response onto respPayload which must be a pointer to byte slice or JSON-serializable structure.

func (*KopiaAPIClient) FetchCSRFTokenForTesting added in v0.10.0

func (c *KopiaAPIClient) FetchCSRFTokenForTesting(ctx context.Context) error

FetchCSRFTokenForTesting fetches the CSRF token and session cookie for use when making subsequent calls to the API. This simulates the browser behavior of downloading the "/" and is required to call the UI-only methods.

func (*KopiaAPIClient) Get

func (c *KopiaAPIClient) Get(ctx context.Context, urlSuffix string, onNotFound error, respPayload interface{}) error

Get is a helper that performs HTTP GET on a URL with the specified suffix and decodes the response onto respPayload which must be a pointer to byte slice or JSON-serializable structure.

func (*KopiaAPIClient) Post

func (c *KopiaAPIClient) Post(ctx context.Context, urlSuffix string, reqPayload, respPayload interface{}) error

Post is a helper that performs HTTP POST on a URL with the specified body from reqPayload and decodes the response onto respPayload which must be a pointer to byte slice or JSON-serializable structure.

func (*KopiaAPIClient) Put

func (c *KopiaAPIClient) Put(ctx context.Context, urlSuffix string, reqPayload, respPayload interface{}) error

Put is a helper that performs HTTP PUT on a URL with the specified body from reqPayload and decodes the response onto respPayload which must be a pointer to byte slice or JSON-serializable structure.

type Options

type Options struct {
	BaseURL string

	Username string
	Password string

	TrustedServerCertificateFingerprint string

	LogRequests bool
}

Options encapsulates all optional parameters for KopiaAPIClient.

Jump to

Keyboard shortcuts

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