Update interface Authorization to Authorizer
parent
4720df245b
commit
38f172f84d
|
@ -9,8 +9,8 @@ import (
|
|||
"github.com/influxdata/chronograf"
|
||||
)
|
||||
|
||||
// Authorization adds optional authorization header to request
|
||||
type Authorization interface {
|
||||
// Authorizer adds optional authorization header to request
|
||||
type Authorizer interface {
|
||||
// Set may manipulate the request by adding the Authorization header
|
||||
Set(req *http.Request) error
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ type NoAuthorization struct{}
|
|||
func (n *NoAuthorization) Set(req *http.Request) error { return nil }
|
||||
|
||||
// DefaultAuthorization creates either a shared JWT builder, basic auth or Noop
|
||||
func DefaultAuthorization(src *chronograf.Source) Authorization {
|
||||
func DefaultAuthorization(src *chronograf.Source) Authorizer {
|
||||
// Optionally, add the shared secret JWT token creation
|
||||
if src.Username != "" && src.SharedSecret != "" {
|
||||
return &BearerJWT{
|
||||
|
|
|
@ -28,7 +28,7 @@ var (
|
|||
// Client is a device for retrieving time series data from an InfluxDB instance
|
||||
type Client struct {
|
||||
URL *url.URL
|
||||
Authorization Authorization
|
||||
Authorizer Authorizer
|
||||
InsecureSkipVerify bool
|
||||
Logger chronograf.Logger
|
||||
}
|
||||
|
@ -72,8 +72,8 @@ func (c *Client) query(u *url.URL, q chronograf.Query) (chronograf.Response, err
|
|||
params.Set("epoch", "ms") // TODO(timraymond): set this based on analysis
|
||||
req.URL.RawQuery = params.Encode()
|
||||
|
||||
if c.Authorization != nil {
|
||||
if err := c.Authorization.Set(req); err != nil {
|
||||
if c.Authorizer != nil {
|
||||
if err := c.Authorizer.Set(req); err != nil {
|
||||
logs.Error("Error setting authorization header ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ func (c *Client) Connect(ctx context.Context, src *chronograf.Source) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.Authorization = DefaultAuthorization(src)
|
||||
c.Authorizer = DefaultAuthorization(src)
|
||||
// Only allow acceptance of all certs if the scheme is https AND the user opted into to the setting.
|
||||
if u.Scheme == "https" && src.InsecureSkipVerify {
|
||||
c.InsecureSkipVerify = src.InsecureSkipVerify
|
||||
|
|
|
@ -182,9 +182,9 @@ func Test_Influx_AuthorizationBearerFailure(t *testing.T) {
|
|||
u, _ := url.Parse("http://haxored.net")
|
||||
u.User = url.UserPassword("AzureDiamond", "hunter2")
|
||||
series := &influx.Client{
|
||||
URL: u,
|
||||
Authorization: bearer,
|
||||
Logger: log.New(log.DebugLevel),
|
||||
URL: u,
|
||||
Authorizer: bearer,
|
||||
Logger: log.New(log.DebugLevel),
|
||||
}
|
||||
|
||||
query := chronograf.Query{
|
||||
|
|
Loading…
Reference in New Issue