|
|
@@ -38,27 +38,38 @@ func NewMssqlQueryEndpoint(datasource *models.DataSource) (tsdb.TsdbQueryEndpoin
|
|
|
MacroEngine: NewMssqlMacroEngine(),
|
|
|
}
|
|
|
|
|
|
+ cnnstr := generateConnectionString(datasource)
|
|
|
+ endpoint.log.Debug("getEngine", "connection", cnnstr)
|
|
|
+
|
|
|
+ if err := endpoint.sqlEngine.InitEngine("mssql", datasource, cnnstr); err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return endpoint, nil
|
|
|
+}
|
|
|
+
|
|
|
+func generateConnectionString(datasource *models.DataSource) string {
|
|
|
+ password := ""
|
|
|
+ for key, value := range datasource.SecureJsonData.Decrypt() {
|
|
|
+ if key == "password" {
|
|
|
+ password = value
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
hostParts := strings.Split(datasource.Url, ":")
|
|
|
if len(hostParts) < 2 {
|
|
|
hostParts = append(hostParts, "1433")
|
|
|
}
|
|
|
|
|
|
server, port := hostParts[0], hostParts[1]
|
|
|
- endpoint.log.Debug("cnnstr", "hostParts len", len(hostParts))
|
|
|
- cnnstr := fmt.Sprintf("server=%s;port=%s;database=%s;user id=%s;password=%s;",
|
|
|
+ return fmt.Sprintf("server=%s;port=%s;database=%s;user id=%s;password=%s;",
|
|
|
server,
|
|
|
port,
|
|
|
datasource.Database,
|
|
|
datasource.User,
|
|
|
- datasource.Password,
|
|
|
+ password,
|
|
|
)
|
|
|
- endpoint.log.Debug("getEngine", "connection", cnnstr)
|
|
|
-
|
|
|
- if err := endpoint.sqlEngine.InitEngine("mssql", datasource, cnnstr); err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
-
|
|
|
- return endpoint, nil
|
|
|
}
|
|
|
|
|
|
// Query is the main function for the MssqlQueryEndpoint
|