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
f157c19e
Unverified
Commit
f157c19e
authored
Jan 28, 2019
by
Marcus Efraimsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extract parsing of datasource tls config to method
parent
7df5e3ce
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
56 deletions
+35
-56
pkg/models/datasource_cache.go
+30
-18
pkg/tsdb/mysql/mysql.go
+5
-38
No files found.
pkg/models/datasource_cache.go
View file @
f157c19e
...
...
@@ -46,19 +46,16 @@ func (ds *DataSource) GetHttpTransport() (*http.Transport, error) {
return
t
.
Transport
,
nil
}
var
tlsSkipVerify
,
tlsClientAuth
,
tlsAuthWithCACert
bool
if
ds
.
JsonData
!=
nil
{
tlsClientAuth
=
ds
.
JsonData
.
Get
(
"tlsAuth"
)
.
MustBool
(
false
)
tlsAuthWithCACert
=
ds
.
JsonData
.
Get
(
"tlsAuthWithCACert"
)
.
MustBool
(
false
)
tlsSkipVerify
=
ds
.
JsonData
.
Get
(
"tlsSkipVerify"
)
.
MustBool
(
false
)
tlsConfig
,
err
:=
ds
.
GetTLSConfig
()
if
err
!=
nil
{
return
nil
,
err
}
tlsConfig
.
Renegotiation
=
tls
.
RenegotiateFreelyAsClient
transport
:=
&
http
.
Transport
{
TLSClientConfig
:
&
tls
.
Config
{
InsecureSkipVerify
:
tlsSkipVerify
,
Renegotiation
:
tls
.
RenegotiateFreelyAsClient
,
},
Proxy
:
http
.
ProxyFromEnvironment
,
TLSClientConfig
:
tlsConfig
,
Proxy
:
http
.
ProxyFromEnvironment
,
Dial
:
(
&
net
.
Dialer
{
Timeout
:
30
*
time
.
Second
,
KeepAlive
:
30
*
time
.
Second
,
...
...
@@ -70,6 +67,26 @@ func (ds *DataSource) GetHttpTransport() (*http.Transport, error) {
IdleConnTimeout
:
90
*
time
.
Second
,
}
ptc
.
cache
[
ds
.
Id
]
=
cachedTransport
{
Transport
:
transport
,
updated
:
ds
.
Updated
,
}
return
transport
,
nil
}
func
(
ds
*
DataSource
)
GetTLSConfig
()
(
*
tls
.
Config
,
error
)
{
var
tlsSkipVerify
,
tlsClientAuth
,
tlsAuthWithCACert
bool
if
ds
.
JsonData
!=
nil
{
tlsClientAuth
=
ds
.
JsonData
.
Get
(
"tlsAuth"
)
.
MustBool
(
false
)
tlsAuthWithCACert
=
ds
.
JsonData
.
Get
(
"tlsAuthWithCACert"
)
.
MustBool
(
false
)
tlsSkipVerify
=
ds
.
JsonData
.
Get
(
"tlsSkipVerify"
)
.
MustBool
(
false
)
}
tlsConfig
:=
&
tls
.
Config
{
InsecureSkipVerify
:
tlsSkipVerify
,
}
if
tlsClientAuth
||
tlsAuthWithCACert
{
decrypted
:=
ds
.
SecureJsonData
.
Decrypt
()
if
tlsAuthWithCACert
&&
len
(
decrypted
[
"tlsCACert"
])
>
0
{
...
...
@@ -78,7 +95,7 @@ func (ds *DataSource) GetHttpTransport() (*http.Transport, error) {
if
!
ok
{
return
nil
,
errors
.
New
(
"Failed to parse TLS CA PEM certificate"
)
}
t
ransport
.
TLSClient
Config
.
RootCAs
=
caPool
t
ls
Config
.
RootCAs
=
caPool
}
if
tlsClientAuth
{
...
...
@@ -86,14 +103,9 @@ func (ds *DataSource) GetHttpTransport() (*http.Transport, error) {
if
err
!=
nil
{
return
nil
,
err
}
t
ransport
.
TLSClient
Config
.
Certificates
=
[]
tls
.
Certificate
{
cert
}
t
ls
Config
.
Certificates
=
[]
tls
.
Certificate
{
cert
}
}
}
ptc
.
cache
[
ds
.
Id
]
=
cachedTransport
{
Transport
:
transport
,
updated
:
ds
.
Updated
,
}
return
transport
,
nil
return
tlsConfig
,
nil
}
pkg/tsdb/mysql/mysql.go
View file @
f157c19e
...
...
@@ -2,15 +2,11 @@ package mysql
import
(
"database/sql"
"errors"
"fmt"
"reflect"
"strconv"
"strings"
"crypto/tls"
"crypto/x509"
"github.com/go-sql-driver/mysql"
"github.com/go-xorm/core"
"github.com/grafana/grafana/pkg/log"
...
...
@@ -37,42 +33,13 @@ func newMysqlQueryEndpoint(datasource *models.DataSource) (tsdb.TsdbQueryEndpoin
datasource
.
Database
,
)
var
tlsSkipVerify
,
tlsAuth
,
tlsAuthWithCACert
bool
if
datasource
.
JsonData
!=
nil
{
tlsAuth
=
datasource
.
JsonData
.
Get
(
"tlsAuth"
)
.
MustBool
(
false
)
tlsAuthWithCACert
=
datasource
.
JsonData
.
Get
(
"tlsAuthWithCACert"
)
.
MustBool
(
false
)
tlsSkipVerify
=
datasource
.
JsonData
.
Get
(
"tlsSkipVerify"
)
.
MustBool
(
false
)
tlsConfig
,
err
:=
datasource
.
GetTLSConfig
()
if
err
!=
nil
{
return
nil
,
err
}
if
tlsAuth
||
tlsAuthWithCACert
{
secureJsonData
:=
datasource
.
SecureJsonData
.
Decrypt
()
tlsConfig
:=
tls
.
Config
{
InsecureSkipVerify
:
tlsSkipVerify
,
}
if
tlsAuthWithCACert
&&
len
(
secureJsonData
[
"tlsCACert"
])
>
0
{
caPool
:=
x509
.
NewCertPool
()
if
ok
:=
caPool
.
AppendCertsFromPEM
([]
byte
(
secureJsonData
[
"tlsCACert"
]));
!
ok
{
return
nil
,
errors
.
New
(
"Failed to parse TLS CA PEM certificate"
)
}
tlsConfig
.
RootCAs
=
caPool
}
if
tlsAuth
{
certs
,
err
:=
tls
.
X509KeyPair
([]
byte
(
secureJsonData
[
"tlsClientCert"
]),
[]
byte
(
secureJsonData
[
"tlsClientKey"
]))
if
err
!=
nil
{
return
nil
,
err
}
clientCert
:=
make
([]
tls
.
Certificate
,
0
,
1
)
clientCert
=
append
(
clientCert
,
certs
)
tlsConfig
.
Certificates
=
clientCert
}
mysql
.
RegisterTLSConfig
(
datasource
.
Name
,
&
tlsConfig
)
if
tlsConfig
.
RootCAs
!=
nil
||
len
(
tlsConfig
.
Certificates
)
>
0
{
mysql
.
RegisterTLSConfig
(
datasource
.
Name
,
tlsConfig
)
cnnstr
+=
"&tls="
+
datasource
.
Name
}
...
...
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