Documentation
¶
Index ¶
- Constants
- func AddAPIVersionToURL(BaseURL, apiVersion string) string
- func SplitVersionedURL(url string) (string, string, bool)
- type ControllerInterface
- type MAASClient
- func (client MAASClient) Delete(uri *url.URL) error
- func (client MAASClient) Get(uri *url.URL, operation string, parameters url.Values) ([]byte, error)
- func (client MAASClient) GetURL(uri *url.URL) *url.URL
- func (client MAASClient) Post(uri *url.URL, operation string, parameters url.Values, files map[string][]byte) ([]byte, error)
- func (client MAASClient) Put(uri *url.URL, parameters url.Values) ([]byte, error)
- type OAuthSigner
- type OAuthToken
- type ServerError
- type SimpleTestServer
- func (s *SimpleTestServer) AddDeleteResponse(path string, status int, body string)
- func (s *SimpleTestServer) AddGetResponse(path string, status int, body string)
- func (s *SimpleTestServer) AddPostResponse(path string, status int, body string)
- func (s *SimpleTestServer) AddPutResponse(path string, status int, body string)
- func (s *SimpleTestServer) LastNRequests(n int) []*http.Request
- func (s *SimpleTestServer) LastRequest() *http.Request
- func (s *SimpleTestServer) RequestCount() int
- func (s *SimpleTestServer) ResetRequests()
Constants ¶
const ( // Number of retries performed when the server returns a 503 // response with a 'Retry-after' header. A request will be issued // at most NumberOfRetries + 1 times. NumberOfRetries = 4 RetryAfterHeaderName = "Retry-After" )
Variables ¶
This section is empty.
Functions ¶
func AddAPIVersionToURL ¶
AddAPIVersionToURL will add the version/<version>/ suffix to the given URL, handling trailing slashes. It shouldn't be called with a URL that already includes a version.
func SplitVersionedURL ¶
SplitVersionedURL splits a versioned API URL (like http://maas.server/MAAS/api/2.0/) into a base URL (http://maas.server/MAAS/) and API version (2.0). If the URL doesn't include a version component the bool return value will be false.
Types ¶
type ControllerInterface ¶
type ControllerInterface interface { Put(path string, params url.Values) ([]byte, error) Post(path string, op string, params url.Values) ([]byte, error) PostFile(path string, op string, params url.Values, fileContent []byte) ([]byte, error) Delete(path string) error Get(path string, op string, params url.Values) ([]byte, error) GetAPIVersionInfo() (set.Strings, error) }
type MAASClient ¶
type MAASClient struct { APIURL *url.URL Signer OAuthSigner }
MAASClient represents a way to communicating with a maas API instance. It is stateless, so it can have concurrent requests in progress.
func NewAnonymousClient ¶
func NewAnonymousClient(BaseURL string, apiVersion string) (*MAASClient, error)
NewAnonymousClient creates a MAASClient that issues anonymous requests. BaseURL should refer to the root of the maas server Path, e.g. http://my.maas.server.example.com/MAAS/ APIVersion should contain the version of the maas API that you want to use.
func NewAuthenticatedMAASClient ¶
func NewAuthenticatedMAASClient(versionedURL, apiKey string) (*MAASClient, error)
NewAuthenticatedMAASClient parses the given maas API key into the individual OAuth tokens and creates an MAASClient that will use these tokens to sign the requests it issues. versionedURL should be the location of the versioned API root of the maas server, e.g.: http://my.maas.server.example.com/MAAS/api/2.0/
func (MAASClient) Delete ¶
func (client MAASClient) Delete(uri *url.URL) error
Delete deletes an object on the API, using an HTTP "DELETE" request.
func (MAASClient) Get ¶
Get performs an HTTP "GET" to the API. This may be either an API method invocation (if you pass its Name in "operation") or plain resource retrieval (if you leave "operation" blank).
func (MAASClient) GetURL ¶
func (client MAASClient) GetURL(uri *url.URL) *url.URL
GetURL returns the URL to a given resource on the API, based on its URI. The resource URI may be absolute or relative; either way the result is a full absolute URL including the network part.
func (MAASClient) Post ¶
func (client MAASClient) Post(uri *url.URL, operation string, parameters url.Values, files map[string][]byte) ([]byte, error)
Post performs an HTTP "POST" to the API. This may be either an API method invocation (if you pass its Name in "operation") or plain resource retrieval (if you leave "operation" blank).
type OAuthSigner ¶
func NewPlainTestOAuthSigner ¶
func NewPlainTestOAuthSigner(token *OAuthToken, realm string) (OAuthSigner, error)
type OAuthToken ¶
type ServerError ¶
type ServerError struct { StatusCode int Header http.Header BodyMessage string // contains filtered or unexported fields }
ServerError is an http error (or at least, a non-2xx result) received from the server. It contains the numerical HTTP status code as well as an error string and the response's headers.
func GetServerError ¶
func GetServerError(err error) (ServerError, bool)
GetServerError returns the ServerError from the cause of the error if it is a ServerError, and also returns the bool to indicate if it was a ServerError or not.
type SimpleTestServer ¶
func NewSimpleServer ¶
func NewSimpleServer() *SimpleTestServer
func (*SimpleTestServer) AddDeleteResponse ¶
func (s *SimpleTestServer) AddDeleteResponse(path string, status int, body string)
func (*SimpleTestServer) AddGetResponse ¶
func (s *SimpleTestServer) AddGetResponse(path string, status int, body string)
func (*SimpleTestServer) AddPostResponse ¶
func (s *SimpleTestServer) AddPostResponse(path string, status int, body string)
func (*SimpleTestServer) AddPutResponse ¶
func (s *SimpleTestServer) AddPutResponse(path string, status int, body string)
func (*SimpleTestServer) LastNRequests ¶
func (s *SimpleTestServer) LastNRequests(n int) []*http.Request
func (*SimpleTestServer) LastRequest ¶
func (s *SimpleTestServer) LastRequest() *http.Request
func (*SimpleTestServer) RequestCount ¶
func (s *SimpleTestServer) RequestCount() int
func (*SimpleTestServer) ResetRequests ¶
func (s *SimpleTestServer) ResetRequests()