Documentation ¶
Overview ¶
Package ovh provides a HTTP wrapper for the OVH API.
Index ¶
- Constants
- Variables
- type APIError
- type AccessRule
- type CkRequest
- type CkValidationState
- type Client
- func (c *Client) CallAPI(method, path string, reqBody, resType interface{}, needAuth bool) error
- func (c *Client) CallAPIWithContext(ctx context.Context, method, path string, reqBody, resType interface{}, ...) error
- func (c *Client) Delete(url string, resType interface{}) error
- func (c *Client) DeleteUnAuth(url string, resType interface{}) error
- func (c *Client) DeleteUnAuthWithContext(ctx context.Context, url string, resType interface{}) error
- func (c *Client) DeleteWithContext(ctx context.Context, url string, resType interface{}) error
- func (c *Client) Do(req *http.Request) (*http.Response, error)
- func (c *Client) Get(url string, resType interface{}) error
- func (c *Client) GetUnAuth(url string, resType interface{}) error
- func (c *Client) GetUnAuthWithContext(ctx context.Context, url string, resType interface{}) error
- func (c *Client) GetWithContext(ctx context.Context, url string, resType interface{}) error
- func (c *Client) NewCkRequest() *CkRequest
- func (c *Client) NewCkRequestWithRedirection(redirection string) *CkRequest
- func (c *Client) NewRequest(method, path string, reqBody interface{}, needAuth bool) (*http.Request, error)
- func (c *Client) Ping() error
- func (c *Client) Post(url string, reqBody, resType interface{}) error
- func (c *Client) PostUnAuth(url string, reqBody, resType interface{}) error
- func (c *Client) PostUnAuthWithContext(ctx context.Context, url string, reqBody, resType interface{}) error
- func (c *Client) PostWithContext(ctx context.Context, url string, reqBody, resType interface{}) error
- func (c *Client) Put(url string, reqBody, resType interface{}) error
- func (c *Client) PutUnAuth(url string, reqBody, resType interface{}) error
- func (c *Client) PutUnAuthWithContext(ctx context.Context, url string, reqBody, resType interface{}) error
- func (c *Client) PutWithContext(ctx context.Context, url string, reqBody, resType interface{}) error
- func (c *Client) Time() (*time.Time, error)
- func (c *Client) TimeDelta() (time.Duration, error)
- func (c *Client) UnmarshalResponse(response *http.Response, resType interface{}) error
- type Logger
Constants ¶
const ( OvhEU = "https://eu.api.ovh.com/1.0" OvhCA = "https://ca.api.ovh.com/1.0" OvhUS = "https://api.us.ovhcloud.com/1.0" KimsufiEU = "https://eu.api.kimsufi.com/1.0" KimsufiCA = "https://ca.api.kimsufi.com/1.0" SoyoustartEU = "https://eu.api.soyoustart.com/1.0" SoyoustartCA = "https://ca.api.soyoustart.com/1.0" RunaboveCA = "https://api.runabove.com/1.0" )
Endpoints
const DefaultTimeout = 180 * time.Second
DefaultTimeout api requests after 180s
Variables ¶
var ( ReadOnly = []string{"GET"} ReadWrite = []string{"GET", "POST", "PUT", "DELETE"} ReadWriteSafe = []string{"GET", "POST", "PUT"} )
Map user friendly access level names to corresponding HTTP verbs
var Endpoints = map[string]string{ "ovh-eu": OvhEU, "ovh-ca": OvhCA, "ovh-us": OvhUS, "kimsufi-eu": KimsufiEU, "kimsufi-ca": KimsufiCA, "soyoustart-eu": SoyoustartEU, "soyoustart-ca": SoyoustartCA, "runabove-ca": RunaboveCA, }
Endpoints conveniently maps endpoints names to their URI for external configuration
var (
ErrAPIDown = errors.New("go-vh: the OVH API is down, it does't respond to /time anymore")
)
Errors
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct { // Error message. Message string // HTTP code. Code int // ID of the request QueryID string }
APIError represents an error that can occurred while calling the API.
type AccessRule ¶
type AccessRule struct { // Allowed HTTP Method for the requested AccessRule. // Can be set to GET/POST/PUT/DELETE. Method string `json:"method"` // Allowed path. // Can be an exact string or a string with '*' char. // Example : // /me : only /me is authorized // /* : all calls are authorized Path string `json:"path"` }
AccessRule represents a method allowed for a path
type CkRequest ¶
type CkRequest struct { AccessRules []AccessRule `json:"accessRules"` Redirection string `json:"redirection,omitempty"` // contains filtered or unexported fields }
CkRequest represents the parameters to fill in order to ask a new consumerKey.
func (*CkRequest) AddRecursiveRules ¶
AddRecursiveRules adds grant requests on "path" and "path/*", for all methods "ReadOnly", "ReadWrite" and "ReadWriteSafe" should be used for "methods" unless specific access are required.
func (*CkRequest) AddRules ¶
AddRules adds grant requests on "path" for all methods. "ReadOnly", "ReadWrite" and "ReadWriteSafe" should be used for "methods" unless specific access are required.
func (*CkRequest) Do ¶
func (ck *CkRequest) Do() (*CkValidationState, error)
Do executes the request. On success, set the consumer key in the client and return the URL the user needs to visit to validate the key
type CkValidationState ¶
type CkValidationState struct { // Consumer key, which need to be validated by customer. ConsumerKey string `json:"consumerKey"` // Current status, should be always "pendingValidation". State string `json:"state"` // URL to redirect user in order to log in. ValidationURL string `json:"validationUrl"` }
CkValidationState represents the response when asking a new consumerKey.
func (*CkValidationState) String ¶
func (ck *CkValidationState) String() string
type Client ¶
type Client struct { // Self generated tokens. Create one by visiting // https://eu.api.ovh.com/createApp/ // AppKey holds the Application key AppKey string // AppSecret holds the Application secret key AppSecret string // ConsumerKey holds the user/app specific token. It must have been validated before use. ConsumerKey string // Client is the underlying HTTP client used to run the requests. It may be overloaded but a default one is instanciated in “NewClient“ by default. Client *http.Client // Logger is used to log HTTP requests and responses. Logger Logger Timeout time.Duration // contains filtered or unexported fields }
Client represents a client to call the OVH API
func NewDefaultClient ¶
NewDefaultClient will load all it's parameter from environment or configuration files
func NewEndpointClient ¶
NewEndpointClient will create an API client for specified endpoint and load all credentials from environment or configuration files
func (*Client) CallAPI ¶
CallAPI is the lowest level call helper. If needAuth is true, inject authentication headers and sign the request.
Request signature is a sha1 hash on following fields, joined by '+': - applicationSecret (from Client instance) - consumerKey (from Client instance) - capitalized method (from arguments) - full request url, including any query string argument - full serialized request body - server current time (takes time delta into account)
Call will automatically assemble the target url from the endpoint configured in the client instance and the path argument. If the reqBody argument is not nil, it will also serialize it as json and inject the required Content-Type header.
If everything went fine, unmarshall response into resType and return nil otherwise, return the error
func (*Client) CallAPIWithContext ¶
func (c *Client) CallAPIWithContext(ctx context.Context, method, path string, reqBody, resType interface{}, needAuth bool) error
CallAPIWithContext is the lowest level call helper. If needAuth is true, inject authentication headers and sign the request.
Request signature is a sha1 hash on following fields, joined by '+': - applicationSecret (from Client instance) - consumerKey (from Client instance) - capitalized method (from arguments) - full request url, including any query string argument - full serialized request body - server current time (takes time delta into account)
Context is used by http.Client to handle context cancelation ¶
Call will automatically assemble the target url from the endpoint configured in the client instance and the path argument. If the reqBody argument is not nil, it will also serialize it as json and inject the required Content-Type header.
If everything went fine, unmarshall response into resType and return nil otherwise, return the error
func (*Client) DeleteUnAuth ¶
DeleteUnAuth is a wrapper for the unauthenticated DELETE method
func (*Client) DeleteUnAuthWithContext ¶
func (c *Client) DeleteUnAuthWithContext(ctx context.Context, url string, resType interface{}) error
DeleteUnAuthWithContext is a wrapper for the unauthenticated DELETE method
func (*Client) DeleteWithContext ¶
DeleteWithContext is a wrapper for the DELETE method
func (*Client) GetUnAuthWithContext ¶
GetUnAuthWithContext is a wrapper for the unauthenticated GET method
func (*Client) GetWithContext ¶
GetWithContext is a wrapper for the GET method
func (*Client) NewCkRequest ¶
NewCkRequest helps create a new ck request
func (*Client) NewCkRequestWithRedirection ¶
NewCkRequestWithRedirection helps create a new ck request with a redirect URL
func (*Client) NewRequest ¶
func (c *Client) NewRequest(method, path string, reqBody interface{}, needAuth bool) (*http.Request, error)
NewRequest returns a new HTTP request
func (*Client) Ping ¶
Ping performs a ping to OVH API. In fact, ping is just a /auth/time call, in order to check if API is up.
func (*Client) PostUnAuth ¶
PostUnAuth is a wrapper for the unauthenticated POST method
func (*Client) PostUnAuthWithContext ¶
func (c *Client) PostUnAuthWithContext(ctx context.Context, url string, reqBody, resType interface{}) error
PostUnAuthWithContext is a wrapper for the unauthenticated POST method
func (*Client) PostWithContext ¶
func (c *Client) PostWithContext(ctx context.Context, url string, reqBody, resType interface{}) error
PostWithContext is a wrapper for the POST method
func (*Client) PutUnAuthWithContext ¶
func (c *Client) PutUnAuthWithContext(ctx context.Context, url string, reqBody, resType interface{}) error
PutUnAuthWithContext is a wrapper for the unauthenticated PUT method
func (*Client) PutWithContext ¶
func (c *Client) PutWithContext(ctx context.Context, url string, reqBody, resType interface{}) error
PutWithContext is a wrapper for the PUT method