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
c21ffcc6
Commit
c21ffcc6
authored
Nov 22, 2016
by
Tom Kozlowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
generalized database connection cert support and added to postgres
parent
c643466d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
18 deletions
+12
-18
pkg/services/sqlstore/sqlstore.go
+11
-17
pkg/services/sqlstore/tls_mysql.go
+1
-1
No files found.
pkg/services/sqlstore/sqlstore.go
View file @
c21ffcc6
...
@@ -23,8 +23,9 @@ import (
...
@@ -23,8 +23,9 @@ import (
_
"github.com/mattn/go-sqlite3"
_
"github.com/mattn/go-sqlite3"
)
)
type
MySQLConfig
struct
{
SslMode
string
type
DatabaseConfig
struct
{
Type
,
Host
,
Name
,
User
,
Pwd
,
Path
,
SslMode
string
CaCertPath
string
CaCertPath
string
ClientKeyPath
string
ClientKeyPath
string
ClientCertPath
string
ClientCertPath
string
...
@@ -37,11 +38,8 @@ var (
...
@@ -37,11 +38,8 @@ var (
HasEngine
bool
HasEngine
bool
DbCfg
struct
{
DbCfg
DatabaseConfig
Type
,
Host
,
Name
,
User
,
Pwd
,
Path
,
SslMode
string
}
mysqlConfig
MySQLConfig
UseSQLite3
bool
UseSQLite3
bool
sqlog
log
.
Logger
=
log
.
New
(
"sqlstore"
)
sqlog
log
.
Logger
=
log
.
New
(
"sqlstore"
)
)
)
...
@@ -118,8 +116,8 @@ func getEngine() (*xorm.Engine, error) {
...
@@ -118,8 +116,8 @@ func getEngine() (*xorm.Engine, error) {
cnnstr
=
fmt
.
Sprintf
(
"%s:%s@%s(%s)/%s?charset=utf8"
,
cnnstr
=
fmt
.
Sprintf
(
"%s:%s@%s(%s)/%s?charset=utf8"
,
DbCfg
.
User
,
DbCfg
.
Pwd
,
protocol
,
DbCfg
.
Host
,
DbCfg
.
Name
)
DbCfg
.
User
,
DbCfg
.
Pwd
,
protocol
,
DbCfg
.
Host
,
DbCfg
.
Name
)
if
mysqlConfig
.
SslMode
==
"true"
||
mysqlConfi
g
.
SslMode
==
"skip-verify"
{
if
DbCfg
.
SslMode
==
"true"
||
DbCf
g
.
SslMode
==
"skip-verify"
{
tlsCert
,
err
:=
makeCert
(
"custom"
,
mysqlConfi
g
)
tlsCert
,
err
:=
makeCert
(
"custom"
,
DbCf
g
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -141,7 +139,7 @@ func getEngine() (*xorm.Engine, error) {
...
@@ -141,7 +139,7 @@ func getEngine() (*xorm.Engine, error) {
if
DbCfg
.
User
==
""
{
if
DbCfg
.
User
==
""
{
DbCfg
.
User
=
"''"
DbCfg
.
User
=
"''"
}
}
cnnstr
=
fmt
.
Sprintf
(
"user=%s password=%s host=%s port=%s dbname=%s sslmode=%s
"
,
DbCfg
.
User
,
DbCfg
.
Pwd
,
host
,
port
,
DbCfg
.
Name
,
DbCfg
.
SslMode
)
cnnstr
=
fmt
.
Sprintf
(
"user=%s password=%s host=%s port=%s dbname=%s sslmode=%s
sslcert=%s sslkey=%s sslrootcert=%s"
,
DbCfg
.
User
,
DbCfg
.
Pwd
,
host
,
port
,
DbCfg
.
Name
,
DbCfg
.
SslMode
,
DbCfg
.
ClientCertPath
,
DbCfg
.
ClientKeyPath
,
DbCfg
.
CaCertPath
)
case
"sqlite3"
:
case
"sqlite3"
:
if
!
filepath
.
IsAbs
(
DbCfg
.
Path
)
{
if
!
filepath
.
IsAbs
(
DbCfg
.
Path
)
{
DbCfg
.
Path
=
filepath
.
Join
(
setting
.
DataPath
,
DbCfg
.
Path
)
DbCfg
.
Path
=
filepath
.
Join
(
setting
.
DataPath
,
DbCfg
.
Path
)
...
@@ -189,13 +187,9 @@ func LoadConfig() {
...
@@ -189,13 +187,9 @@ func LoadConfig() {
UseSQLite3
=
true
UseSQLite3
=
true
}
}
DbCfg
.
SslMode
=
sec
.
Key
(
"ssl_mode"
)
.
String
()
DbCfg
.
SslMode
=
sec
.
Key
(
"ssl_mode"
)
.
String
()
DbCfg
.
CaCertPath
=
sec
.
Key
(
"ca_cert_path"
)
.
String
()
DbCfg
.
ClientKeyPath
=
sec
.
Key
(
"client_key_path"
)
.
String
()
DbCfg
.
ClientCertPath
=
sec
.
Key
(
"client_cert_path"
)
.
String
()
DbCfg
.
ServerCertName
=
sec
.
Key
(
"server_cert_name"
)
.
String
()
DbCfg
.
Path
=
sec
.
Key
(
"path"
)
.
MustString
(
"data/grafana.db"
)
DbCfg
.
Path
=
sec
.
Key
(
"path"
)
.
MustString
(
"data/grafana.db"
)
if
DbCfg
.
Type
==
"mysql"
{
mysqlConfig
.
SslMode
=
DbCfg
.
SslMode
mysqlConfig
.
CaCertPath
=
sec
.
Key
(
"ca_cert_path"
)
.
String
()
mysqlConfig
.
ClientKeyPath
=
sec
.
Key
(
"client_key_path"
)
.
String
()
mysqlConfig
.
ClientCertPath
=
sec
.
Key
(
"client_cert_path"
)
.
String
()
mysqlConfig
.
ServerCertName
=
sec
.
Key
(
"server_cert_name"
)
.
String
()
}
}
}
pkg/services/sqlstore/tls_mysql.go
View file @
c21ffcc6
...
@@ -7,7 +7,7 @@ import (
...
@@ -7,7 +7,7 @@ import (
"io/ioutil"
"io/ioutil"
)
)
func
makeCert
(
tlsPoolName
string
,
config
MySQL
Config
)
(
*
tls
.
Config
,
error
)
{
func
makeCert
(
tlsPoolName
string
,
config
Database
Config
)
(
*
tls
.
Config
,
error
)
{
rootCertPool
:=
x509
.
NewCertPool
()
rootCertPool
:=
x509
.
NewCertPool
()
pem
,
err
:=
ioutil
.
ReadFile
(
config
.
CaCertPath
)
pem
,
err
:=
ioutil
.
ReadFile
(
config
.
CaCertPath
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
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