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
aa064b18
Commit
aa064b18
authored
Jun 28, 2016
by
Soulou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test environment override for secret and url with credentials
parent
e2c5fac9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
0 deletions
+30
-0
pkg/setting/setting.go
+16
-0
pkg/setting/setting_test.go
+14
-0
No files found.
pkg/setting/setting.go
View file @
aa064b18
...
...
@@ -183,6 +183,11 @@ func shouldRedactKey(s string) bool {
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
()
{
appliedEnvOverrides
=
make
([]
string
,
0
)
for
_
,
section
:=
range
Cfg
.
Sections
()
{
...
...
@@ -197,6 +202,17 @@ func applyEnvVariableOverrides() {
if
shouldRedactKey
(
envKey
)
{
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
))
}
}
...
...
pkg/setting/setting_test.go
View file @
aa064b18
...
...
@@ -29,6 +29,20 @@ func TestLoadingSettings(t *testing.T) {
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
()
{
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