fix(influx): Ensure credentials are passed for Flux queries

Fixes #11710
pull/13025/head
Stuart Carnie 2019-03-29 16:39:34 -07:00
parent ba2f72075f
commit 09a9d34430
No known key found for this signature in database
GPG Key ID: 848D9C9718D78B4F
3 changed files with 10 additions and 3 deletions

View File

@ -207,7 +207,7 @@ func (c *CommandLine) Run() error {
c.Version()
if c.Type == QueryLanguageFlux {
repl, err := getFluxREPL(c.Host, c.Port, c.Ssl)
repl, err := getFluxREPL(c.Host, c.Port, c.Ssl, c.ClientConfig.Username, c.ClientConfig.Password)
if err != nil {
return err
}
@ -1194,7 +1194,7 @@ func (c *CommandLine) ExecuteFluxQuery(query string) error {
}()
}
repl, err := getFluxREPL(c.Host, c.Port, c.Ssl)
repl, err := getFluxREPL(c.Host, c.Port, c.Ssl, c.ClientConfig.Username, c.ClientConfig.Password)
if err != nil {
return err
}

View File

@ -30,10 +30,12 @@ func (q *replQuerier) Query(ctx context.Context, compiler flux.Compiler) (flux.R
return q.client.Query(ctx, req)
}
func getFluxREPL(host string, port int, ssl bool) (*repl.REPL, error) {
func getFluxREPL(host string, port int, ssl bool, username, password string) (*repl.REPL, error) {
c, err := client.NewHTTP(host, port, ssl)
if err != nil {
return nil, err
}
c.Username = username
c.Password = password
return repl.New(&replQuerier{client: c}), nil
}

View File

@ -36,6 +36,8 @@ var (
// API endpoint.
type HTTP struct {
Addr string
Username string
Password string
InsecureSkipVerify bool
url *url.URL
}
@ -66,6 +68,9 @@ func (s *HTTP) Query(ctx context.Context, r *ProxyRequest) (flux.ResultIterator,
if err != nil {
return nil, err
}
if s.Username != "" {
hreq.SetBasicAuth(s.Username, s.Password)
}
hreq.Header.Set("Content-Type", "application/json")
hreq.Header.Set("Accept", "text/csv")