mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
grafana-cli: Add ability to read password from stdin to reset admin password (#26016)
* grafana-cli: Add ability to read password from stdin to reset admin password Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com> Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
@@ -111,6 +111,13 @@ var adminCommands = []*cli.Command{
|
|||||||
Name: "reset-admin-password",
|
Name: "reset-admin-password",
|
||||||
Usage: "reset-admin-password <new password>",
|
Usage: "reset-admin-password <new password>",
|
||||||
Action: runDbCommand(resetPasswordCommand),
|
Action: runDbCommand(resetPasswordCommand),
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "password-from-stdin",
|
||||||
|
Usage: "Read the password from stdin",
|
||||||
|
Value: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "data-migration",
|
Name: "data-migration",
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/grafana/grafana/pkg/bus"
|
"github.com/grafana/grafana/pkg/bus"
|
||||||
@@ -16,7 +18,22 @@ import (
|
|||||||
const AdminUserId = 1
|
const AdminUserId = 1
|
||||||
|
|
||||||
func resetPasswordCommand(c utils.CommandLine, sqlStore *sqlstore.SqlStore) error {
|
func resetPasswordCommand(c utils.CommandLine, sqlStore *sqlstore.SqlStore) error {
|
||||||
newPassword := c.Args().First()
|
newPassword := ""
|
||||||
|
|
||||||
|
if c.Bool("password-from-stdin") {
|
||||||
|
logger.Infof("New Password: ")
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(os.Stdin)
|
||||||
|
if ok := scanner.Scan(); !ok {
|
||||||
|
if err := scanner.Err(); err != nil {
|
||||||
|
return fmt.Errorf("can't read password from stdin: %w", err)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("can't read password from stdin")
|
||||||
|
}
|
||||||
|
newPassword = scanner.Text()
|
||||||
|
} else {
|
||||||
|
newPassword = c.Args().First()
|
||||||
|
}
|
||||||
|
|
||||||
password := models.Password(newPassword)
|
password := models.Password(newPassword)
|
||||||
if password.IsWeak() {
|
if password.IsWeak() {
|
||||||
|
|||||||
Reference in New Issue
Block a user