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
1f3602c7
Unverified
Commit
1f3602c7
authored
Apr 03, 2018
by
Daniel Lee
Committed by
GitHub
Apr 03, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11428 from bergquist/11281_fix
Avoid panic when GF_DATABASE_URL contains illegal chars
parents
a6a08038
45d9bfca
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
7 deletions
+27
-7
pkg/cmd/grafana-server/server.go
+1
-1
pkg/setting/setting.go
+19
-6
pkg/setting/setting_test.go
+7
-0
No files found.
pkg/cmd/grafana-server/server.go
View file @
1f3602c7
...
@@ -111,7 +111,7 @@ func (g *GrafanaServerImpl) initLogging() {
...
@@ -111,7 +111,7 @@ func (g *GrafanaServerImpl) initLogging() {
})
})
if
err
!=
nil
{
if
err
!=
nil
{
g
.
log
.
Error
(
err
.
Error
())
fmt
.
Fprintf
(
os
.
Stderr
,
"Failed to start grafana. error: %s
\n
"
,
err
.
Error
())
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
...
...
pkg/setting/setting.go
View file @
1f3602c7
...
@@ -223,7 +223,7 @@ func shouldRedactURLKey(s string) bool {
...
@@ -223,7 +223,7 @@ func shouldRedactURLKey(s string) bool {
return
strings
.
Contains
(
uppercased
,
"DATABASE_URL"
)
return
strings
.
Contains
(
uppercased
,
"DATABASE_URL"
)
}
}
func
applyEnvVariableOverrides
()
{
func
applyEnvVariableOverrides
()
error
{
appliedEnvOverrides
=
make
([]
string
,
0
)
appliedEnvOverrides
=
make
([]
string
,
0
)
for
_
,
section
:=
range
Cfg
.
Sections
()
{
for
_
,
section
:=
range
Cfg
.
Sections
()
{
for
_
,
key
:=
range
section
.
Keys
()
{
for
_
,
key
:=
range
section
.
Keys
()
{
...
@@ -238,7 +238,10 @@ func applyEnvVariableOverrides() {
...
@@ -238,7 +238,10 @@ func applyEnvVariableOverrides() {
envValue
=
"*********"
envValue
=
"*********"
}
}
if
shouldRedactURLKey
(
envKey
)
{
if
shouldRedactURLKey
(
envKey
)
{
u
,
_
:=
url
.
Parse
(
envValue
)
u
,
err
:=
url
.
Parse
(
envValue
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"could not parse environment variable. key: %s, value: %s. error: %v"
,
envKey
,
envValue
,
err
)
}
ui
:=
u
.
User
ui
:=
u
.
User
if
ui
!=
nil
{
if
ui
!=
nil
{
_
,
exists
:=
ui
.
Password
()
_
,
exists
:=
ui
.
Password
()
...
@@ -252,6 +255,8 @@ func applyEnvVariableOverrides() {
...
@@ -252,6 +255,8 @@ func applyEnvVariableOverrides() {
}
}
}
}
}
}
return
nil
}
}
func
applyCommandLineDefaultProperties
(
props
map
[
string
]
string
)
{
func
applyCommandLineDefaultProperties
(
props
map
[
string
]
string
)
{
...
@@ -377,7 +382,7 @@ func loadSpecifedConfigFile(configFile string) error {
...
@@ -377,7 +382,7 @@ func loadSpecifedConfigFile(configFile string) error {
return
nil
return
nil
}
}
func
loadConfiguration
(
args
*
CommandLineArgs
)
{
func
loadConfiguration
(
args
*
CommandLineArgs
)
error
{
var
err
error
var
err
error
// load config defaults
// load config defaults
...
@@ -395,7 +400,7 @@ func loadConfiguration(args *CommandLineArgs) {
...
@@ -395,7 +400,7 @@ func loadConfiguration(args *CommandLineArgs) {
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
fmt
.
Sprintf
(
"Failed to parse defaults.ini, %v"
,
err
))
fmt
.
Println
(
fmt
.
Sprintf
(
"Failed to parse defaults.ini, %v"
,
err
))
os
.
Exit
(
1
)
os
.
Exit
(
1
)
return
return
err
}
}
Cfg
.
BlockMode
=
false
Cfg
.
BlockMode
=
false
...
@@ -413,7 +418,10 @@ func loadConfiguration(args *CommandLineArgs) {
...
@@ -413,7 +418,10 @@ func loadConfiguration(args *CommandLineArgs) {
}
}
// apply environment overrides
// apply environment overrides
applyEnvVariableOverrides
()
err
=
applyEnvVariableOverrides
()
if
err
!=
nil
{
return
err
}
// apply command line overrides
// apply command line overrides
applyCommandLineProperties
(
commandLineProps
)
applyCommandLineProperties
(
commandLineProps
)
...
@@ -424,6 +432,8 @@ func loadConfiguration(args *CommandLineArgs) {
...
@@ -424,6 +432,8 @@ func loadConfiguration(args *CommandLineArgs) {
// update data path and logging config
// update data path and logging config
DataPath
=
makeAbsolute
(
Cfg
.
Section
(
"paths"
)
.
Key
(
"data"
)
.
String
(),
HomePath
)
DataPath
=
makeAbsolute
(
Cfg
.
Section
(
"paths"
)
.
Key
(
"data"
)
.
String
(),
HomePath
)
initLogging
()
initLogging
()
return
err
}
}
func
pathExists
(
path
string
)
bool
{
func
pathExists
(
path
string
)
bool
{
...
@@ -471,7 +481,10 @@ func validateStaticRootPath() error {
...
@@ -471,7 +481,10 @@ func validateStaticRootPath() error {
func
NewConfigContext
(
args
*
CommandLineArgs
)
error
{
func
NewConfigContext
(
args
*
CommandLineArgs
)
error
{
setHomePath
(
args
)
setHomePath
(
args
)
loadConfiguration
(
args
)
err
:=
loadConfiguration
(
args
)
if
err
!=
nil
{
return
err
}
Env
=
Cfg
.
Section
(
""
)
.
Key
(
"app_mode"
)
.
MustString
(
"development"
)
Env
=
Cfg
.
Section
(
""
)
.
Key
(
"app_mode"
)
.
MustString
(
"development"
)
InstanceName
=
Cfg
.
Section
(
""
)
.
Key
(
"instance_name"
)
.
MustString
(
"unknown_instance_name"
)
InstanceName
=
Cfg
.
Section
(
""
)
.
Key
(
"instance_name"
)
.
MustString
(
"unknown_instance_name"
)
...
...
pkg/setting/setting_test.go
View file @
1f3602c7
...
@@ -37,6 +37,13 @@ func TestLoadingSettings(t *testing.T) {
...
@@ -37,6 +37,13 @@ func TestLoadingSettings(t *testing.T) {
So
(
appliedEnvOverrides
,
ShouldContain
,
"GF_SECURITY_ADMIN_PASSWORD=*********"
)
So
(
appliedEnvOverrides
,
ShouldContain
,
"GF_SECURITY_ADMIN_PASSWORD=*********"
)
})
})
Convey
(
"Should replace password when defined in environment2"
,
func
()
{
os
.
Setenv
(
"GF_DATABASE_URL"
,
"postgres://grafana:sec{ret@postgres:5432/grafana"
)
err
:=
NewConfigContext
(
&
CommandLineArgs
{
HomePath
:
"../../"
})
So
(
err
,
ShouldNotBeNil
)
})
Convey
(
"Should replace password in URL when url environment is defined"
,
func
()
{
Convey
(
"Should replace password in URL when url environment is defined"
,
func
()
{
os
.
Setenv
(
"GF_DATABASE_URL"
,
"mysql://user:secret@localhost:3306/database"
)
os
.
Setenv
(
"GF_DATABASE_URL"
,
"mysql://user:secret@localhost:3306/database"
)
NewConfigContext
(
&
CommandLineArgs
{
HomePath
:
"../../"
})
NewConfigContext
(
&
CommandLineArgs
{
HomePath
:
"../../"
})
...
...
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