mirror of
https://github.com/hanzoai/deploy.git
synced 2026-10-07 08:44:50 +00:00
* chore: enable unused-parameter from revive Signed-off-by: Matthieu MOREL <[email protected]> * apply recommandations Signed-off-by: Matthieu MOREL <[email protected]> --------- Signed-off-by: Matthieu MOREL <[email protected]>
37 lines
934 B
Go
37 lines
934 B
Go
package commands
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
|
|
"github.com/spf13/cobra"
|
|
"golang.org/x/crypto/bcrypt"
|
|
)
|
|
|
|
// NewBcryptCmd represents the bcrypt command
|
|
func NewBcryptCmd() *cobra.Command {
|
|
var password string
|
|
bcryptCmd := &cobra.Command{
|
|
Use: "bcrypt",
|
|
Short: "Generate bcrypt hash for any password",
|
|
Example: `# Generate bcrypt hash for any password
|
|
argocd account bcrypt --password YOUR_PASSWORD`,
|
|
Run: func(cmd *cobra.Command, _ []string) {
|
|
bytePassword := []byte(password)
|
|
// Hashing the password
|
|
hash, err := bcrypt.GenerateFromPassword(bytePassword, bcrypt.DefaultCost)
|
|
if err != nil {
|
|
log.Fatalf("Failed to genarate bcrypt hash: %v", err)
|
|
}
|
|
fmt.Fprint(cmd.OutOrStdout(), string(hash))
|
|
},
|
|
}
|
|
|
|
bcryptCmd.Flags().StringVar(&password, "password", "", "Password for which bcrypt hash is generated")
|
|
err := bcryptCmd.MarkFlagRequired("password")
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
return bcryptCmd
|
|
}
|