Skip to content

Commit

Permalink
use basic auth instead of the uri
Browse files Browse the repository at this point in the history
  • Loading branch information
corylanou committed Apr 13, 2015
1 parent ec33228 commit 425acd7
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions client/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,17 @@ func NewClient(c Config) (*Client, error) {
return &client, nil
}

// SetAuth will update the username and passwords
func (c *Client) SetAuth(u, p string) {
c.username = u
c.password = p
}

// Query sends a command to the server and returns the Response
func (c *Client) Query(q Query) (*Response, error) {
u := c.url

u.Path = "query"
if c.username != "" {
u.User = url.UserPassword(c.username, c.password)
}
values := u.Query()
values.Set("q", q.Command)
values.Set("db", q.Database)
Expand All @@ -72,6 +75,10 @@ func (c *Client) Query(q Query) (*Response, error) {
return nil, err
}
req.Header.Set("User-Agent", c.userAgent)
if c.username != "" {
req.SetBasicAuth(c.username, c.password)
}

resp, err := c.httpClient.Do(req)
if err != nil {
return nil, err
Expand Down

0 comments on commit 425acd7

Please sign in to comment.