api

package
v1.0.0-beta1 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2020 License: Apache-2.0 Imports: 23 Imported by: 55

Documentation

Index

Constants

View Source
const (
	// RegionPrefix is used when a Region is passed as part of the API config.
	RegionPrefix = "/api/v1/regions/%s"

	// RegionlessPrefix is used when no region is specified, assumed target is
	// most likely an ECE installation or a non federated one.
	RegionlessPrefix = "/api/v1"
)
View Source
const Version = "2.4.3"

Version contains the ECE API version compatibility for the current auto-generated client and models. This needs to be updated every time a new "api/apidocs.json" file added and the client and models are re-generated. Even though the Bugfix version is specified, the general support statement is on the minor version, i.e: 2.4.2 means that all the 2.4 branch is supported, expecting some potentially unfixed bugs when ECE version is the same feature version bug higher bugfix version.

Variables

View Source
var (
	// DefaultTimeout is used when TransportConfig.Transport is not specified.
	DefaultTimeout = 30 * time.Second
)
View Source
var DefaultTransport = new(ErrCatchTransport)

DefaultTransport can be used by clients which rely on the api.UnwrapError Can obtain the underlying http.Response is returned with a StatusCode not defined within the swagger spec from which the models have been generated. Meaning this is a small hack which allows http.Response.Body to be accessed. See error.go in the same package for details on how UnwrapError works. Note that using this variable directly won't allow any of the http.Transport setttings to be overridden. To customize the transport further, please use NewTransport()

Functions

func AddTypeConsumers

func AddTypeConsumers(rtime *client.Runtime) *client.Runtime

AddTypeConsumers adds the missing consumers and producers to the client.Runtime. Even though a pointer is passed it is returned too.

func NewTransport

func NewTransport(rt http.RoundTripper, cfg TransportConfig) http.RoundTripper

NewTransport constructs a new http.RoundTripper from its config. If rt is *http.Transport then it will be wrapped with *ErrCatchTransport. See more information on the GoDoc help for that type.

func UnwrapError

func UnwrapError(err error) error

UnwrapError unpacks an error message returned from autogenerated sdk.

Types

type API

type API struct {
	V1API      *client.Rest
	AuthWriter AuthWriter
}

API contains all of the API clients and authentication objects necessary for the EC API

func NewAPI

func NewAPI(c Config) (*API, error)

NewAPI initializes the API clients from an API config that it receives

func NewDebugMock

func NewDebugMock(o io.Writer, res ...mock.Response) *API

NewDebugMock creates a new api.API from a list of Responses. Defaults to a dummy APIKey for authentication, which is not checked. Additionally adds the DebugTransport so that the responses go to the configured io.Writer.

func NewMock

func NewMock(res ...mock.Response) *API

NewMock creates a new api.API from a list of Responses. Defaults to a dummy APIKey for authentication, which is not checked

type AuthWriter

type AuthWriter interface {
	runtime.ClientAuthInfoWriter
	AuthRequest(req *http.Request) *http.Request
}

AuthWriter wraps the runtime.ClientAuthInfoWriter interface adding a method to Auth generic http.Request.

type CloudClientRuntime

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

CloudClientRuntime wraps runtimeclient.Runtime to allow operations to use a transport depending on the operation which is being performed.

func NewCloudClientRuntime

func NewCloudClientRuntime(c Config) (*CloudClientRuntime, error)

NewCloudClientRuntime creates a CloudClientRuntime from the config. Using the configured region (if any) to instantiate two different client.Runtime. If there's no region specified in the config then both are regionless.

func (*CloudClientRuntime) Submit

func (r *CloudClientRuntime) Submit(op *runtime.ClientOperation) (interface{}, error)

Submit calls either the regionRuntime or the regionless runtime depending on which operation is being performed. Any API call to /deployments will use a regionless runtime while all others will use a region (if specified).

type Config

type Config struct {
	Client     *http.Client
	AuthWriter AuthWriter
	Host       string
	Region     string

	// SkipTLSVerify will not perform any TLS/SSL verification.
	SkipTLSVerify bool

	// ErrorDevice is used to send errors to prevent cluttering the output.
	ErrorDevice io.Writer

	VerboseSettings

	// Timeout for all of the API calls performed through the API structure.
	Timeout time.Duration
}

Config contains the API config

func (*Config) Validate

func (c *Config) Validate() error

Validate returns an error if the config is invalid

type DebugTransport

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

DebugTransport is an http.RoundTripper that keeps track of the in-flight request and implements hooks to report HTTP tracing events.

func NewDebugTransport

func NewDebugTransport(transport http.RoundTripper, o io.Writer) *DebugTransport

NewDebugTransport factory for DebugTransport

func (*DebugTransport) RoundTrip

func (t *DebugTransport) RoundTrip(rreq *http.Request) (*http.Response, error)

RoundTrip wraps http.DefaultTransport.RoundTrip to keep track of the current request.

type ErrCatchTransport

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

ErrCatchTransport is an http.RoundTripper that which allows the http.Response to be accessed in certain types of wrapped errors returned by autogenerated code. See error.go in the same package for details on how UnwrapError works.

func NewErrCatchTransport

func NewErrCatchTransport(rt http.RoundTripper) *ErrCatchTransport

NewErrCatchTransport initialises an ErrCatchTransport. See GoDoc for more help on this type.

func (*ErrCatchTransport) RoundTrip

func (e *ErrCatchTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip wraps http.DefaultTransport.RoundTrip to keep track of the current request.

type TransportConfig

type TransportConfig struct {
	// When SkipTLSVerify the TLS verification is completely skipped.
	SkipTLSVerify bool

	// ErrorDevice where any error or notices will be sent.
	ErrorDevice io.Writer

	// Can enable a debug RoundTripper which dumps the request and responses to
	// the configured device.
	VerboseSettings

	// Timeout for the Transport net.Dialer.
	Timeout time.Duration
}

TransportConfig is meant to be used so an http.RoundTripper is constructed with the appropriate settings.

type VerboseSettings

type VerboseSettings struct {
	Verbose bool
	Device  io.Writer
}

VerboseSettings define the behaviour of verbosity.

func (VerboseSettings) Validate

func (settings VerboseSettings) Validate() error

Validate ensures the settings are usable.

Directories

Path Synopsis
Package mock provides functions and types to help test and stub external calls that the API structures would otherwise perform causing external calls through the network.
Package mock provides functions and types to help test and stub external calls that the API structures would otherwise perform causing external calls through the network.

Jump to

Keyboard shortcuts

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