refactor: abstract secret generation into package
This commit is contained in:
parent
f56ddef6c8
commit
769c5b899b
13
cli/app.go
13
cli/app.go
@ -297,20 +297,11 @@ var appSecretCommand = &cli.Command{
|
||||
Name: "secret",
|
||||
Flags: []cli.Flag{AllFlag, PassFlag},
|
||||
Action: func(c *cli.Context) error {
|
||||
passwords, err := passgen.GeneratePassphrases(
|
||||
1,
|
||||
passgen.PassphraseWordCountDefault,
|
||||
rune('-'),
|
||||
passgen.PassphraseCasingDefault,
|
||||
passgen.WordListDefault,
|
||||
)
|
||||
password, err := secret.GeneratePassphrases(1)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
for _, password := range passwords {
|
||||
fmt.Println(password)
|
||||
}
|
||||
fmt.Println(password)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
35
secret/secret.go
Normal file
35
secret/secret.go
Normal file
@ -0,0 +1,35 @@
|
||||
package secret
|
||||
|
||||
import (
|
||||
"github.com/schultz-is/passgen"
|
||||
)
|
||||
|
||||
func GeneratePasswords(count, length uint) ([]string, error) {
|
||||
passwords, err := passgen.GeneratePasswords(
|
||||
count,
|
||||
length,
|
||||
passgen.AlphabetDefault,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return passwords, nil
|
||||
}
|
||||
|
||||
func GeneratePassphrases(count uint) ([]string, error) {
|
||||
passphrases, err := passgen.GeneratePassphrases(
|
||||
count,
|
||||
passgen.PassphraseWordCountDefault,
|
||||
rune('-'),
|
||||
passgen.PassphraseCasingDefault,
|
||||
passgen.WordListDefault,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return passphrases, nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user