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
c663e32e
Commit
c663e32e
authored
Aug 19, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'database_url' of
https://github.com/Scalingo/grafana
into Scalingo-database_url
parents
28ac05b1
aa064b18
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
7 deletions
+60
-7
conf/defaults.ini
+3
-0
pkg/services/sqlstore/sqlstore.go
+27
-7
pkg/setting/setting.go
+16
-0
pkg/setting/setting_test.go
+14
-0
No files found.
conf/defaults.ini
View file @
c663e32e
...
@@ -65,6 +65,9 @@ host = 127.0.0.1:3306
...
@@ -65,6 +65,9 @@ host = 127.0.0.1:3306
name
=
grafana
name
=
grafana
user
=
root
user
=
root
password
=
password
=
# Use either URL or the previous fields to configure the database
# Example: mysql://user:secret@host:port/database
url
=
# For "postgres", use either "disable", "require" or "verify-full"
# For "postgres", use either "disable", "require" or "verify-full"
# For "mysql", use either "true", "false", or "skip-verify".
# For "mysql", use either "true", "false", or "skip-verify".
...
...
pkg/services/sqlstore/sqlstore.go
View file @
c663e32e
...
@@ -2,6 +2,7 @@ package sqlstore
...
@@ -2,6 +2,7 @@ package sqlstore
import
(
import
(
"fmt"
"fmt"
"net/url"
"os"
"os"
"path"
"path"
"path/filepath"
"path/filepath"
...
@@ -155,16 +156,35 @@ func getEngine() (*xorm.Engine, error) {
...
@@ -155,16 +156,35 @@ func getEngine() (*xorm.Engine, error) {
func
LoadConfig
()
{
func
LoadConfig
()
{
sec
:=
setting
.
Cfg
.
Section
(
"database"
)
sec
:=
setting
.
Cfg
.
Section
(
"database"
)
DbCfg
.
Type
=
sec
.
Key
(
"type"
)
.
String
()
cfgURL
:=
sec
.
Key
(
"url"
)
.
String
()
if
len
(
cfgURL
)
!=
0
{
dbURL
,
_
:=
url
.
Parse
(
cfgURL
)
DbCfg
.
Type
=
dbURL
.
Scheme
DbCfg
.
Host
=
dbURL
.
Host
pathSplit
:=
strings
.
Split
(
dbURL
.
Path
,
"/"
)
if
len
(
pathSplit
)
>
1
{
DbCfg
.
Name
=
pathSplit
[
1
]
}
userInfo
:=
dbURL
.
User
if
userInfo
!=
nil
{
DbCfg
.
User
=
userInfo
.
Username
()
DbCfg
.
Pwd
,
_
=
userInfo
.
Password
()
}
}
else
{
DbCfg
.
Type
=
sec
.
Key
(
"type"
)
.
String
()
DbCfg
.
Host
=
sec
.
Key
(
"host"
)
.
String
()
DbCfg
.
Name
=
sec
.
Key
(
"name"
)
.
String
()
DbCfg
.
User
=
sec
.
Key
(
"user"
)
.
String
()
if
len
(
DbCfg
.
Pwd
)
==
0
{
DbCfg
.
Pwd
=
sec
.
Key
(
"password"
)
.
String
()
}
}
if
DbCfg
.
Type
==
"sqlite3"
{
if
DbCfg
.
Type
==
"sqlite3"
{
UseSQLite3
=
true
UseSQLite3
=
true
}
}
DbCfg
.
Host
=
sec
.
Key
(
"host"
)
.
String
()
DbCfg
.
Name
=
sec
.
Key
(
"name"
)
.
String
()
DbCfg
.
User
=
sec
.
Key
(
"user"
)
.
String
()
if
len
(
DbCfg
.
Pwd
)
==
0
{
DbCfg
.
Pwd
=
sec
.
Key
(
"password"
)
.
String
()
}
DbCfg
.
SslMode
=
sec
.
Key
(
"ssl_mode"
)
.
String
()
DbCfg
.
SslMode
=
sec
.
Key
(
"ssl_mode"
)
.
String
()
DbCfg
.
Path
=
sec
.
Key
(
"path"
)
.
MustString
(
"data/grafana.db"
)
DbCfg
.
Path
=
sec
.
Key
(
"path"
)
.
MustString
(
"data/grafana.db"
)
...
...
pkg/setting/setting.go
View file @
c663e32e
...
@@ -183,6 +183,11 @@ func shouldRedactKey(s string) bool {
...
@@ -183,6 +183,11 @@ func shouldRedactKey(s string) bool {
return
strings
.
Contains
(
uppercased
,
"PASSWORD"
)
||
strings
.
Contains
(
uppercased
,
"SECRET"
)
return
strings
.
Contains
(
uppercased
,
"PASSWORD"
)
||
strings
.
Contains
(
uppercased
,
"SECRET"
)
}
}
func
shouldRedactURLKey
(
s
string
)
bool
{
uppercased
:=
strings
.
ToUpper
(
s
)
return
strings
.
Contains
(
uppercased
,
"DATABASE_URL"
)
}
func
applyEnvVariableOverrides
()
{
func
applyEnvVariableOverrides
()
{
appliedEnvOverrides
=
make
([]
string
,
0
)
appliedEnvOverrides
=
make
([]
string
,
0
)
for
_
,
section
:=
range
Cfg
.
Sections
()
{
for
_
,
section
:=
range
Cfg
.
Sections
()
{
...
@@ -197,6 +202,17 @@ func applyEnvVariableOverrides() {
...
@@ -197,6 +202,17 @@ func applyEnvVariableOverrides() {
if
shouldRedactKey
(
envKey
)
{
if
shouldRedactKey
(
envKey
)
{
envValue
=
"*********"
envValue
=
"*********"
}
}
if
shouldRedactURLKey
(
envKey
)
{
u
,
_
:=
url
.
Parse
(
envValue
)
ui
:=
u
.
User
if
ui
!=
nil
{
_
,
exists
:=
ui
.
Password
()
if
exists
{
u
.
User
=
url
.
UserPassword
(
ui
.
Username
(),
"-redacted-"
)
envValue
=
u
.
String
()
}
}
}
appliedEnvOverrides
=
append
(
appliedEnvOverrides
,
fmt
.
Sprintf
(
"%s=%s"
,
envKey
,
envValue
))
appliedEnvOverrides
=
append
(
appliedEnvOverrides
,
fmt
.
Sprintf
(
"%s=%s"
,
envKey
,
envValue
))
}
}
}
}
...
...
pkg/setting/setting_test.go
View file @
c663e32e
...
@@ -29,6 +29,20 @@ func TestLoadingSettings(t *testing.T) {
...
@@ -29,6 +29,20 @@ func TestLoadingSettings(t *testing.T) {
So
(
LogsPath
,
ShouldEqual
,
filepath
.
Join
(
DataPath
,
"log"
))
So
(
LogsPath
,
ShouldEqual
,
filepath
.
Join
(
DataPath
,
"log"
))
})
})
Convey
(
"Should replace password when defined in environment"
,
func
()
{
os
.
Setenv
(
"GF_SECURITY_ADMIN_PASSWORD"
,
"supersecret"
)
NewConfigContext
(
&
CommandLineArgs
{
HomePath
:
"../../"
})
So
(
appliedEnvOverrides
,
ShouldContain
,
"GF_SECURITY_ADMIN_PASSWORD=*********"
)
})
Convey
(
"Should replace password in URL when url environment is defined"
,
func
()
{
os
.
Setenv
(
"GF_DATABASE_URL"
,
"mysql://user:secret@localhost:3306/database"
)
NewConfigContext
(
&
CommandLineArgs
{
HomePath
:
"../../"
})
So
(
appliedEnvOverrides
,
ShouldContain
,
"GF_DATABASE_URL=mysql://user:-redacted-@localhost:3306/database"
)
})
Convey
(
"Should get property map from command line args array"
,
func
()
{
Convey
(
"Should get property map from command line args array"
,
func
()
{
props
:=
getCommandLineProperties
([]
string
{
"cfg:test=value"
,
"cfg:map.test=1"
})
props
:=
getCommandLineProperties
([]
string
{
"cfg:test=value"
,
"cfg:map.test=1"
})
...
...
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