11package server
22
33import (
4+ "fmt"
5+
46 "github.com/influxdata/chronograf"
57 "github.com/influxdata/chronograf/canned"
68 "github.com/influxdata/chronograf/filestore"
@@ -107,7 +109,7 @@ func (builder *MultiDashboardBuilder) Build(db chronograf.DashboardsStore) (*mul
107109
108110// SourcesBuilder builds a MultiSourceStore
109111type SourcesBuilder interface {
110- Build (chronograf.SourcesStore ) (* multistore.SourcesStore , error )
112+ Build (chronograf.SourcesStore , string ) (* multistore.SourcesStore , error )
111113}
112114
113115// MultiSourceBuilder implements SourcesBuilder
@@ -129,29 +131,27 @@ type MultiSourceBuilder struct {
129131}
130132
131133// Build will return a MultiSourceStore
132- func (fs * MultiSourceBuilder ) Build (db chronograf.SourcesStore ) (* multistore.SourcesStore , error ) {
134+ func (fs * MultiSourceBuilder ) Build (db chronograf.SourcesStore , defaultOrgID string ) (* multistore.SourcesStore , error ) {
133135 // These dashboards are those handled from a directory
134136 files := filestore .NewSources (fs .Path , fs .ID , fs .Logger )
135137
136138 stores := []chronograf.SourcesStore {db , files }
137139
138- // TODO simon: also process fs.InfluxDBType!
139140 if fs .InfluxDBURL != "" {
140141 var influxdbType , username , password string
141142 var clusterID , accountID , mgmtToken , dbToken , tagsCSVPath string
142- if fs .InfluxDBClusterID != "" && fs .InfluxDBAccountID != "" && fs .InfluxDBToken != "" && fs .InfluxDBMgmtToken != "" {
143+ if fs .InfluxDBType == chronograf .InfluxDBv3Core || fs .InfluxDBType == chronograf .InfluxDBv3Enterprise {
144+ // InfluxDB 3 Core, InfluxDB 3 Enterprise
145+ influxdbType = fs .InfluxDBType
146+ dbToken = fs .InfluxDBToken
147+ } else if fs .InfluxDBType == chronograf .InfluxDBv3CloudDedicated {
143148 // InfluxDB Cloud Dedicated
144- influxdbType = chronograf . InfluxDBv3CloudDedicated
149+ influxdbType = fs . InfluxDBType
145150 clusterID = fs .InfluxDBClusterID
146151 accountID = fs .InfluxDBAccountID
147152 mgmtToken = fs .InfluxDBMgmtToken
148153 dbToken = fs .InfluxDBToken
149154 tagsCSVPath = fs .TagsCSVPath
150- } else if fs .InfluxDBToken != "" {
151- // TODO simon: this is not fully correct, it can be either v3 Core or v3 Enterprise
152- // InfluxDB 3 Core/Enterprise
153- influxdbType = chronograf .InfluxDBv3Core
154- dbToken = fs .InfluxDBToken
155155 } else if fs .InfluxDBOrg == "" || fs .InfluxDBToken == "" {
156156 // v1 InfluxDB
157157 username = fs .InfluxDBUsername
@@ -164,24 +164,29 @@ func (fs *MultiSourceBuilder) Build(db chronograf.SourcesStore) (*multistore.Sou
164164 influxdbType = chronograf .InfluxDBv2
165165 }
166166
167- influxStore := & memdb.SourcesStore {
168- // TODO simon: validate the Source before adding, reuse ValidSourceRequest!
169- Source : & chronograf.Source {
170- ID : 0 ,
171- Name : fs .InfluxDBURL ,
172- Type : influxdbType ,
173- Username : username ,
174- Password : password ,
175- ClusterID : clusterID ,
176- AccountID : accountID ,
177- ManagementToken : mgmtToken ,
178- DatabaseToken : dbToken ,
179- TagsCSVPath : tagsCSVPath ,
180- URL : fs .InfluxDBURL ,
181- Default : true ,
182- Version : "unknown" , // a real version is re-fetched at runtime; use "unknown" version as a fallback, empty version would imply OSS 2.x
183- }}
184- stores = append ([]chronograf.SourcesStore {influxStore }, stores ... )
167+ source := chronograf.Source {
168+ ID : 0 ,
169+ Name : fs .InfluxDBURL ,
170+ Type : influxdbType ,
171+ Username : username ,
172+ Password : password ,
173+ ClusterID : clusterID ,
174+ AccountID : accountID ,
175+ ManagementToken : mgmtToken ,
176+ DatabaseToken : dbToken ,
177+ TagsCSVPath : tagsCSVPath ,
178+ URL : fs .InfluxDBURL ,
179+ Default : true ,
180+ Version : "unknown" , // a real version is re-fetched at runtime; use "unknown" version as a fallback, empty version would imply OSS 2.x
181+ }
182+
183+ if err := ValidSourceRequest (& source , defaultOrgID ); err == nil {
184+ influxStore := & memdb.SourcesStore {Source : & source }
185+ stores = append ([]chronograf.SourcesStore {influxStore }, stores ... )
186+ } else {
187+ // Log the error and ignore
188+ fs .Logger .Error (fmt .Sprintf ("Invalid %s source: %s" , influxdbType , err ))
189+ }
185190 }
186191 sources := & multistore.SourcesStore {
187192 Stores : stores ,
0 commit comments