Documentation ¶
Overview ¶
Package client provides a client for interacting with the anxcloud API.
Index ¶
Constants ¶
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 ¶
var ErrConfiguration = errors.New("could not configure client")
ErrConfiguration is raised when the given configuration is insufficient or erroneous.
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
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 ¶
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
AuthFromEnv uses any known environment variables to create a client.
func HTTPClient ¶ added in v0.3.0
HTTPClient lets the client use the given http.Client.
func LogWriter ¶ added in v0.3.21
LogWriter configures the debug writer for logging requests and responses
func TokenFromEnv ¶ added in v0.3.0
TokenFromEnv fetches the API auth token from environment variables.
func TokenFromString ¶ added in v0.3.0
TokenFromString uses the given API auth token.
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