Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
25142090
Commit
25142090
authored
Aug 05, 2019
by
Elykov Alexandr
Committed by
Marcus Efraimsson
Aug 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MSSQL: Change connectionstring to URL format to fix using passwords with semicolon (#18384)
Fixes #17665
parent
4e1e2209
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
16 deletions
+41
-16
pkg/tsdb/mssql/mssql.go
+14
-16
pkg/tsdb/mssql/mssql_test.go
+27
-0
No files found.
pkg/tsdb/mssql/mssql.go
View file @
25142090
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"database/sql"
"database/sql"
"fmt"
"fmt"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/setting"
"net/url"
"strconv"
"strconv"
_
"github.com/denisenkom/go-mssqldb"
_
"github.com/denisenkom/go-mssqldb"
...
@@ -21,10 +22,7 @@ func init() {
...
@@ -21,10 +22,7 @@ func init() {
func
newMssqlQueryEndpoint
(
datasource
*
models
.
DataSource
)
(
tsdb
.
TsdbQueryEndpoint
,
error
)
{
func
newMssqlQueryEndpoint
(
datasource
*
models
.
DataSource
)
(
tsdb
.
TsdbQueryEndpoint
,
error
)
{
logger
:=
log
.
New
(
"tsdb.mssql"
)
logger
:=
log
.
New
(
"tsdb.mssql"
)
cnnstr
,
err
:=
generateConnectionString
(
datasource
)
cnnstr
:=
generateConnectionString
(
datasource
)
if
err
!=
nil
{
return
nil
,
err
}
if
setting
.
Env
==
setting
.
DEV
{
if
setting
.
Env
==
setting
.
DEV
{
logger
.
Debug
(
"getEngine"
,
"connection"
,
cnnstr
)
logger
.
Debug
(
"getEngine"
,
"connection"
,
cnnstr
)
}
}
...
@@ -43,21 +41,21 @@ func newMssqlQueryEndpoint(datasource *models.DataSource) (tsdb.TsdbQueryEndpoin
...
@@ -43,21 +41,21 @@ func newMssqlQueryEndpoint(datasource *models.DataSource) (tsdb.TsdbQueryEndpoin
return
tsdb
.
NewSqlQueryEndpoint
(
&
config
,
&
rowTransformer
,
newMssqlMacroEngine
(),
logger
)
return
tsdb
.
NewSqlQueryEndpoint
(
&
config
,
&
rowTransformer
,
newMssqlMacroEngine
(),
logger
)
}
}
func
generateConnectionString
(
datasource
*
models
.
DataSource
)
(
string
,
error
)
{
func
generateConnectionString
(
datasource
*
models
.
DataSource
)
string
{
server
,
port
:=
util
.
SplitHostPortDefault
(
datasource
.
Url
,
"localhost"
,
"1433"
)
server
,
port
:=
util
.
SplitHostPortDefault
(
datasource
.
Url
,
"localhost"
,
"1433"
)
encrypt
:=
datasource
.
JsonData
.
Get
(
"encrypt"
)
.
MustString
(
"false"
)
encrypt
:=
datasource
.
JsonData
.
Get
(
"encrypt"
)
.
MustString
(
"false"
)
connStr
:=
fmt
.
Sprintf
(
"server=%s;port=%s;database=%s;user id=%s;password=%s;"
,
server
,
query
:=
url
.
Values
{}
port
,
query
.
Add
(
"database"
,
datasource
.
Database
)
datasource
.
Database
,
query
.
Add
(
"encrypt"
,
encrypt
)
datasource
.
User
,
datasource
.
DecryptedPassword
(),
u
:=
&
url
.
URL
{
)
Scheme
:
"sqlserver"
,
if
encrypt
!=
"false"
{
User
:
url
.
UserPassword
(
datasource
.
User
,
datasource
.
DecryptedPassword
()),
connStr
+=
fmt
.
Sprintf
(
"encrypt=%s;"
,
encrypt
)
Host
:
fmt
.
Sprintf
(
"%s:%s"
,
server
,
port
),
RawQuery
:
query
.
Encode
(),
}
}
return
connStr
,
nil
return
u
.
String
()
}
}
type
mssqlRowTransformer
struct
{
type
mssqlRowTransformer
struct
{
...
...
pkg/tsdb/mssql/mssql_test.go
View file @
25142090
...
@@ -27,6 +27,33 @@ import (
...
@@ -27,6 +27,33 @@ import (
// If needed, change the variable below to the IP address of the database.
// If needed, change the variable below to the IP address of the database.
var
serverIP
=
"localhost"
var
serverIP
=
"localhost"
func
TestGenerateConnectionString
(
t
*
testing
.
T
)
{
encrypted
,
_
:=
simplejson
.
NewJson
([]
byte
(
`{"encrypt":"false"}`
))
testSet
:=
[]
struct
{
ds
*
models
.
DataSource
expected
string
}{
{
&
models
.
DataSource
{
User
:
"user"
,
Database
:
"db"
,
Url
:
"localhost:1433"
,
SecureJsonData
:
securejsondata
.
GetEncryptedJsonData
(
map
[
string
]
string
{
"password"
:
"pass;word"
,
}),
JsonData
:
encrypted
,
},
"sqlserver://user:pass;word@localhost:1433?database=db&encrypt=false"
,
},
}
for
i
:=
range
testSet
{
got
:=
generateConnectionString
(
testSet
[
i
]
.
ds
)
if
got
!=
testSet
[
i
]
.
expected
{
t
.
Errorf
(
"mssql connString error for testCase %d got: %s expected: %s"
,
i
,
got
,
testSet
[
i
]
.
expected
)
}
}
}
func
TestMSSQL
(
t
*
testing
.
T
)
{
func
TestMSSQL
(
t
*
testing
.
T
)
{
SkipConvey
(
"MSSQL"
,
t
,
func
()
{
SkipConvey
(
"MSSQL"
,
t
,
func
()
{
x
:=
InitMSSQLTestDB
(
t
)
x
:=
InitMSSQLTestDB
(
t
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment