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
96e8ecfa
Commit
96e8ecfa
authored
Dec 09, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(cli): adds command to reset admin password
closes #5479
parent
cd85e1f6
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
10 deletions
+23
-10
build.go
+4
-0
pkg/api/user.go
+3
-2
pkg/cmd/grafana-cli/commands/commands.go
+6
-6
pkg/cmd/grafana-cli/commands/reset_password_command.go
+4
-2
pkg/models/user.go
+6
-0
No files found.
build.go
View file @
96e8ecfa
...
...
@@ -73,6 +73,10 @@ func main() {
case
"setup"
:
setup
()
case
"build-cli"
:
clean
()
build
(
"grafana-cli"
,
"./pkg/cmd/grafana-cli"
,
[]
string
{})
case
"build"
:
clean
()
for
_
,
binary
:=
range
binaries
{
...
...
pkg/api/user.go
View file @
96e8ecfa
...
...
@@ -157,8 +157,9 @@ func ChangeUserPassword(c *middleware.Context, cmd m.ChangeUserPasswordCommand)
return
ApiError
(
401
,
"Invalid old password"
,
nil
)
}
if
len
(
cmd
.
NewPassword
)
<
4
{
return
ApiError
(
400
,
"New password too short"
,
nil
)
password
:=
m
.
Password
(
cmd
.
NewPassword
)
if
password
.
IsWeak
()
{
return
ApiError
(
400
,
"New password is too short"
,
nil
)
}
cmd
.
UserId
=
c
.
UserId
...
...
pkg/cmd/grafana-cli/commands/commands.go
View file @
96e8ecfa
...
...
@@ -90,10 +90,10 @@ var pluginCommands = []cli.Command{
},
}
var
user
Commands
=
[]
cli
.
Command
{
var
admin
Commands
=
[]
cli
.
Command
{
{
Name
:
"reset-admin"
,
Usage
:
"reset-admin <new password>"
,
Name
:
"reset-admin
-password
"
,
Usage
:
"reset-admin
-password
<new password>"
,
Action
:
runDbCommand
(
resetPasswordCommand
),
},
}
...
...
@@ -105,8 +105,8 @@ var Commands = []cli.Command{
Subcommands
:
pluginCommands
,
},
{
Name
:
"
user
"
,
Usage
:
""
,
Subcommands
:
user
Commands
,
Name
:
"
admin
"
,
Usage
:
"
Grafana admin commands
"
,
Subcommands
:
admin
Commands
,
},
}
pkg/cmd/grafana-cli/commands/reset_password_command.go
View file @
96e8ecfa
...
...
@@ -15,8 +15,9 @@ const AdminUserId = 1
func
resetPasswordCommand
(
c
CommandLine
)
error
{
newPassword
:=
c
.
Args
()
.
First
()
if
len
(
newPassword
)
<
4
{
return
fmt
.
Errorf
(
"New password too short"
)
password
:=
models
.
Password
(
newPassword
)
if
password
.
IsWeak
()
{
return
fmt
.
Errorf
(
"New password is too short"
)
}
userQuery
:=
models
.
GetUserByIdQuery
{
Id
:
AdminUserId
}
...
...
@@ -36,6 +37,7 @@ func resetPasswordCommand(c CommandLine) error {
return
fmt
.
Errorf
(
"Failed to update user password"
)
}
logger
.
Infof
(
"
\n
"
)
logger
.
Infof
(
"Admin password changed successfully %s"
,
color
.
GreenString
(
"✔"
))
return
nil
...
...
pkg/models/user.go
View file @
96e8ecfa
...
...
@@ -10,6 +10,12 @@ var (
ErrUserNotFound
=
errors
.
New
(
"User not found"
)
)
type
Password
string
func
(
p
Password
)
IsWeak
()
bool
{
return
len
(
p
)
<=
4
}
type
User
struct
{
Id
int64
Version
int
...
...
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