2016-10-25 15:20:06 +00:00
|
|
|
package server
|
2016-09-30 20:39:27 +00:00
|
|
|
|
2017-02-24 03:54:20 +00:00
|
|
|
import (
|
2017-02-24 20:48:42 +00:00
|
|
|
"context"
|
|
|
|
"strings"
|
|
|
|
|
2019-01-08 00:37:16 +00:00
|
|
|
"github.com/influxdata/influxdb/chronograf"
|
|
|
|
"github.com/influxdata/influxdb/chronograf/enterprise"
|
|
|
|
"github.com/influxdata/influxdb/chronograf/influx"
|
2017-02-24 03:54:20 +00:00
|
|
|
)
|
2016-09-30 20:39:27 +00:00
|
|
|
|
2016-10-28 16:27:06 +00:00
|
|
|
// Service handles REST calls to the persistence
|
|
|
|
type Service struct {
|
2018-03-23 19:48:34 +00:00
|
|
|
Store DataStore
|
|
|
|
TimeSeriesClient TimeSeriesClient
|
|
|
|
Logger chronograf.Logger
|
|
|
|
UseAuth bool
|
|
|
|
SuperAdminProviderGroups superAdminProviderGroups
|
|
|
|
Env chronograf.Environment
|
|
|
|
Databases chronograf.Databases
|
|
|
|
}
|
|
|
|
|
|
|
|
type superAdminProviderGroups struct {
|
|
|
|
auth0 string
|
2017-02-24 03:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TimeSeriesClient returns the correct client for a time series database.
|
|
|
|
type TimeSeriesClient interface {
|
|
|
|
New(chronograf.Source, chronograf.Logger) (chronograf.TimeSeries, error)
|
2016-09-30 20:39:27 +00:00
|
|
|
}
|
2016-11-19 17:41:06 +00:00
|
|
|
|
|
|
|
// ErrorMessage is the error response format for all service errors
|
|
|
|
type ErrorMessage struct {
|
|
|
|
Code int `json:"code"`
|
|
|
|
Message string `json:"message"`
|
|
|
|
}
|
2017-02-24 03:54:20 +00:00
|
|
|
|
|
|
|
// TimeSeries returns a new client connected to a time series database
|
|
|
|
func (s *Service) TimeSeries(src chronograf.Source) (chronograf.TimeSeries, error) {
|
|
|
|
return s.TimeSeriesClient.New(src, s.Logger)
|
|
|
|
}
|
|
|
|
|
|
|
|
// InfluxClient returns a new client to connect to OSS or Enterprise
|
|
|
|
type InfluxClient struct{}
|
|
|
|
|
|
|
|
// New creates a client to connect to OSS or enterprise
|
|
|
|
func (c *InfluxClient) New(src chronograf.Source, logger chronograf.Logger) (chronograf.TimeSeries, error) {
|
2017-07-15 01:02:13 +00:00
|
|
|
client := &influx.Client{
|
|
|
|
Logger: logger,
|
|
|
|
}
|
|
|
|
if err := client.Connect(context.TODO(), &src); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-03-13 21:45:05 +00:00
|
|
|
if src.Type == chronograf.InfluxEnterprise && src.MetaURL != "" {
|
2017-02-24 20:48:42 +00:00
|
|
|
tls := strings.Contains(src.MetaURL, "https")
|
2018-02-14 19:28:02 +00:00
|
|
|
insecure := src.InsecureSkipVerify
|
|
|
|
return enterprise.NewClientWithTimeSeries(logger, src.MetaURL, influx.DefaultAuthorization(&src), tls, insecure, client)
|
2017-02-24 03:54:20 +00:00
|
|
|
}
|
2017-07-15 01:02:13 +00:00
|
|
|
return client, nil
|
2017-02-24 03:54:20 +00:00
|
|
|
}
|