Skip to content

Commit

Permalink
Moved API key to request header
Browse files Browse the repository at this point in the history
For any API request requiring authentication, send the HTTP header
`API-Key: YOURKEY`.

See <https://www.vultr.com/api/#using_the_api>
  • Loading branch information
Daniel S. Reichenbach committed Dec 17, 2017
1 parent e5dad9a commit 9d583af
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions lib/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,6 @@ func apiPath(path string) string {
return fmt.Sprintf("/%s/%s", APIVersion, path)
}

func apiKeyPath(path, apiKey string) string {
if strings.Contains(path, "?") {
return path + "&api_key=" + apiKey
}
return path + "?api_key=" + apiKey
}

func (c *Client) get(path string, data interface{}) error {
req, err := c.newRequest("GET", apiPath(path), nil)
if err != nil {
Expand All @@ -144,7 +137,7 @@ func (c *Client) post(path string, values url.Values, data interface{}) error {
}

func (c *Client) newRequest(method string, path string, body io.Reader) (*http.Request, error) {
relPath, err := url.Parse(apiKeyPath(path, c.APIKey))
relPath, err := url.Parse(path)
if err != nil {
return nil, err
}
Expand All @@ -156,6 +149,7 @@ func (c *Client) newRequest(method string, path string, body io.Reader) (*http.R
return nil, err
}

req.Header.Add("API-Key", c.APIKey)
req.Header.Add("User-Agent", c.UserAgent)
req.Header.Add("Accept", mediaType)

Expand Down

0 comments on commit 9d583af

Please sign in to comment.