feat(cmd): add show token command

pull/4964/head
Andy Hsu 2023-08-07 13:49:23 +08:00
parent 7877184bee
commit 5b6b2f427a
1 changed files with 18 additions and 5 deletions

View File

@ -4,15 +4,17 @@ Copyright © 2022 NAME HERE <EMAIL ADDRESS>
package cmd package cmd
import ( import (
"github.com/alist-org/alist/v3/internal/conf"
"github.com/alist-org/alist/v3/internal/model" "github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/op" "github.com/alist-org/alist/v3/internal/op"
"github.com/alist-org/alist/v3/internal/setting"
"github.com/alist-org/alist/v3/pkg/utils" "github.com/alist-org/alist/v3/pkg/utils"
"github.com/alist-org/alist/v3/pkg/utils/random" "github.com/alist-org/alist/v3/pkg/utils/random"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
// PasswordCmd represents the password command // AdminCmd represents the password command
var PasswordCmd = &cobra.Command{ var AdminCmd = &cobra.Command{
Use: "admin", Use: "admin",
Aliases: []string{"password"}, Aliases: []string{"password"},
Short: "Show admin user's info and some operations about admin user's password", Short: "Show admin user's info and some operations about admin user's password",
@ -51,6 +53,16 @@ var SetPasswordCmd = &cobra.Command{
}, },
} }
var ShowTokenCmd = &cobra.Command{
Use: "token",
Short: "Show admin token",
Run: func(cmd *cobra.Command, args []string) {
Init()
token := setting.GetStr(conf.Token)
utils.Log.Infof("Admin token: %s", token)
},
}
func setAdminPassword(pwd string) { func setAdminPassword(pwd string) {
Init() Init()
admin, err := op.GetAdmin() admin, err := op.GetAdmin()
@ -70,9 +82,10 @@ func setAdminPassword(pwd string) {
} }
func init() { func init() {
RootCmd.AddCommand(PasswordCmd) RootCmd.AddCommand(AdminCmd)
PasswordCmd.AddCommand(RandomPasswordCmd) AdminCmd.AddCommand(RandomPasswordCmd)
PasswordCmd.AddCommand(SetPasswordCmd) AdminCmd.AddCommand(SetPasswordCmd)
AdminCmd.AddCommand(ShowTokenCmd)
// Here you will define your flags and configuration settings. // Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command // Cobra supports Persistent Flags which will work for this command