Skip to content

Commit

Permalink
feat(cmd): add show token command
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Aug 7, 2023
1 parent 7877184 commit 5b6b2f4
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions cmd/admin.go
Expand Up @@ -4,15 +4,17 @@ Copyright © 2022 NAME HERE <EMAIL ADDRESS>
package cmd

import (
"github.com/alist-org/alist/v3/internal/conf"
"github.com/alist-org/alist/v3/internal/model"
"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/random"
"github.com/spf13/cobra"
)

// PasswordCmd represents the password command
var PasswordCmd = &cobra.Command{
// AdminCmd represents the password command
var AdminCmd = &cobra.Command{
Use: "admin",
Aliases: []string{"password"},
Short: "Show admin user's info and some operations about admin user's password",
Expand Down Expand Up @@ -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) {
Init()
admin, err := op.GetAdmin()
Expand All @@ -70,9 +82,10 @@ func setAdminPassword(pwd string) {
}

func init() {
RootCmd.AddCommand(PasswordCmd)
PasswordCmd.AddCommand(RandomPasswordCmd)
PasswordCmd.AddCommand(SetPasswordCmd)
RootCmd.AddCommand(AdminCmd)
AdminCmd.AddCommand(RandomPasswordCmd)
AdminCmd.AddCommand(SetPasswordCmd)
AdminCmd.AddCommand(ShowTokenCmd)
// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
Expand Down

0 comments on commit 5b6b2f4

Please sign in to comment.