client

package
v0.3.28 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package client provides a client for interacting with the anxcloud API.

Index

Constants

View Source
const (
	// TokenEnvName is the name of the environment variable that should contain the API token.
	TokenEnvName = "ANEXIA_TOKEN" //nolint:gosec // This is a name, not a secret.
	// VsphereLocationEnvName is the name of the environment variable that should contain a test location for paths that need a provisioning location.
	VsphereLocationEnvName = "ANEXIA_VSPHERE_LOCATION_ID"
	// CoreLocationEnvName is the name of the environment variable that should contain a test location for paths that need a core location.
	CoreLocationEnvName = "ANEXIA_CORE_LOCATION_ID"
	// VLANEnvName is the name of the environment variable that should contain the VLAN of VMs to manage.
	VLANEnvName = "ANEXIA_VLAN_ID"
	// IntegrationTestEnvName is the name of the environment variable that enables integration tests if present.
	IntegrationTestEnvName = "ANEXIA_INTEGRATION_TESTS_ON"
	// DefaultBaseURL is the default base URL used for requests.
	DefaultBaseURL = "https://engine.anexia-it.com"
	// DefaultRequestTimeout is a suggested timeout for API calls.
	DefaultRequestTimeout = 10 * time.Second
)

Variables

View Source
var ErrConfiguration = errors.New("could not configure client")

ErrConfiguration is raised when the given configuration is insufficient or erroneous.

View Source
var ErrEnvMissing = errors.New("environment variable missing")

ErrEnvMissing indicates an environment variable is missing.

Functions

This section is empty.

Types

type Client

type Client interface {
	// Do fires a given http.Request against the API.
	// This method behaves as http.Client.Do, but signs the request prior to sending it out
	// and returns an error is the response status is not OK.
	Do(req *http.Request) (*http.Response, error)
	BaseURL() string
}

Client interacts with the anxcloud API.

func New added in v0.3.0

func New(options ...Option) (Client, error)

New creates a new client with the given options.

The options need to contain a method of authentication with the API. If you are unsure what to use pass AuthFromEnv.

func NewTestClient

func NewTestClient(c Client, handler http.Handler) (Client, *httptest.Server)

NewTestClient creates a new client for testing.

c may be used to specify an other client implementation that needs to be tested or may be nil. handler is a http.Handler that mocks parts of the API functionality that shall be tested.

Returned will be a client.Client that can be passed to the method under test and the used httptest.Server that should be closed after test completion.

type Option added in v0.3.0

type Option func(o *optionSet) error

Option is a optional parameter for the New method.

func AuthFromEnv added in v0.3.0

func AuthFromEnv(unset bool) Option

AuthFromEnv uses any known environment variables to create a client.

func HTTPClient added in v0.3.0

func HTTPClient(c *http.Client) Option

HTTPClient lets the client use the given http.Client.

func LogWriter added in v0.3.21

func LogWriter(w io.Writer) Option

LogWriter configures the debug writer for logging requests and responses

func TokenFromEnv added in v0.3.0

func TokenFromEnv(unset bool) Option

TokenFromEnv fetches the API auth token from environment variables.

func TokenFromString added in v0.3.0

func TokenFromString(token string) Option

TokenFromString uses the given API auth token.

func UserAgent added in v0.3.25

func UserAgent(userAgent string) Option

type ResponseError

type ResponseError struct {
	Request   *http.Request  `json:"-"`
	Response  *http.Response `json:"-"`
	ErrorData struct {
		Code       int               `json:"code"`
		Message    string            `json:"message"`
		Validation map[string]string `json:"validation"`
	} `json:"error"`
	Debug struct {
		Source string `json:"source"`
	} `json:"debug"`
}

ResponseError is a response from the API that indicates an error.

func (ResponseError) Error

func (r ResponseError) Error() string

Jump to

Keyboard shortcuts

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