diff --git a/pkg/api/datasources.go b/pkg/api/datasources.go index 38a4004c241..e393ad3e820 100644 --- a/pkg/api/datasources.go +++ b/pkg/api/datasources.go @@ -65,6 +65,7 @@ func GetDataSourceById(c *middleware.Context) Response { BasicAuth: ds.BasicAuth, BasicAuthUser: ds.BasicAuthUser, BasicAuthPassword: ds.BasicAuthPassword, + WithCredentials: ds.WithCredentials, IsDefault: ds.IsDefault, JsonData: ds.JsonData, }) diff --git a/pkg/api/dtos/models.go b/pkg/api/dtos/models.go index 7af4c84f56d..50db279b25b 100644 --- a/pkg/api/dtos/models.go +++ b/pkg/api/dtos/models.go @@ -61,6 +61,7 @@ type DataSource struct { BasicAuth bool `json:"basicAuth"` BasicAuthUser string `json:"basicAuthUser"` BasicAuthPassword string `json:"basicAuthPassword"` + WithCredentials bool `json:"withCredentials"` IsDefault bool `json:"isDefault"` JsonData map[string]interface{} `json:"jsonData"` } diff --git a/pkg/api/frontendsettings.go b/pkg/api/frontendsettings.go index cc07b9cfb49..65a863f548a 100644 --- a/pkg/api/frontendsettings.go +++ b/pkg/api/frontendsettings.go @@ -62,6 +62,9 @@ func getFrontendSettingsMap(c *middleware.Context) (map[string]interface{}, erro if ds.BasicAuth { dsMap["basicAuth"] = util.GetBasicAuthHeader(ds.BasicAuthUser, ds.BasicAuthPassword) } + if ds.WithCredentials { + dsMap["withCredentials"] = ds.WithCredentials + } if ds.Type == m.DS_INFLUXDB_08 { dsMap["username"] = ds.User diff --git a/pkg/models/datasource.go b/pkg/models/datasource.go index 38273598ab1..88abd03c319 100644 --- a/pkg/models/datasource.go +++ b/pkg/models/datasource.go @@ -40,6 +40,7 @@ type DataSource struct { BasicAuth bool BasicAuthUser string BasicAuthPassword string + WithCredentials bool IsDefault bool JsonData map[string]interface{} @@ -83,6 +84,7 @@ type AddDataSourceCommand struct { BasicAuth bool `json:"basicAuth"` BasicAuthUser string `json:"basicAuthUser"` BasicAuthPassword string `json:"basicAuthPassword"` + WithCredentials bool `json:"withCredentials"` IsDefault bool `json:"isDefault"` JsonData map[string]interface{} `json:"jsonData"` @@ -103,6 +105,7 @@ type UpdateDataSourceCommand struct { BasicAuth bool `json:"basicAuth"` BasicAuthUser string `json:"basicAuthUser"` BasicAuthPassword string `json:"basicAuthPassword"` + WithCredentials bool `json:"withCredentials"` IsDefault bool `json:"isDefault"` JsonData map[string]interface{} `json:"jsonData"` diff --git a/pkg/services/sqlstore/datasource.go b/pkg/services/sqlstore/datasource.go index ebb2ad977b1..4e1292afaa6 100644 --- a/pkg/services/sqlstore/datasource.go +++ b/pkg/services/sqlstore/datasource.go @@ -114,12 +114,14 @@ func UpdateDataSource(cmd *m.UpdateDataSourceCommand) error { BasicAuth: cmd.BasicAuth, BasicAuthUser: cmd.BasicAuthUser, BasicAuthPassword: cmd.BasicAuthPassword, + WithCredentials: cmd.WithCredentials, JsonData: cmd.JsonData, Updated: time.Now(), } sess.UseBool("is_default") sess.UseBool("basic_auth") + sess.UseBool("with_credentials") _, err := sess.Where("id=? and org_id=?", ds.Id, ds.OrgId).Update(ds) if err != nil { diff --git a/pkg/services/sqlstore/migrations/datasource_mig.go b/pkg/services/sqlstore/migrations/datasource_mig.go index 4f046b1f8e9..90f7dac85e6 100644 --- a/pkg/services/sqlstore/migrations/datasource_mig.go +++ b/pkg/services/sqlstore/migrations/datasource_mig.go @@ -96,4 +96,9 @@ func addDataSourceMigration(mg *Migrator) { })) mg.AddMigration("Drop old table data_source_v1 #2", NewDropTableMigration("data_source_v1")) + + // add column to activate withCredentials option + mg.AddMigration("Add column with_credentials", NewAddColumnMigration(tableV2, &Column{ + Name: "with_credentials", Type: DB_Bool, Nullable: false, Default: "0", + })) } diff --git a/pkg/services/sqlstore/migrator/migrations.go b/pkg/services/sqlstore/migrator/migrations.go index a65c7ec7e81..7d97abb6bb9 100644 --- a/pkg/services/sqlstore/migrator/migrations.go +++ b/pkg/services/sqlstore/migrator/migrations.go @@ -64,6 +64,10 @@ type AddColumnMigration struct { column *Column } +func NewAddColumnMigration(table Table, col *Column) *AddColumnMigration { + return &AddColumnMigration{tableName: table.Name, column: col} +} + func (m *AddColumnMigration) Table(tableName string) *AddColumnMigration { m.tableName = tableName return m