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",
|
Name: "secret",
|
||||||
Flags: []cli.Flag{AllFlag, PassFlag},
|
Flags: []cli.Flag{AllFlag, PassFlag},
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
passwords, err := passgen.GeneratePassphrases(
|
password, err := secret.GeneratePassphrases(1)
|
||||||
1,
|
|
||||||
passgen.PassphraseWordCountDefault,
|
|
||||||
rune('-'),
|
|
||||||
passgen.PassphraseCasingDefault,
|
|
||||||
passgen.WordListDefault,
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
fmt.Println(password)
|
||||||
for _, password := range passwords {
|
|
||||||
fmt.Println(password)
|
|
||||||
}
|
|
||||||
return nil
|
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…
x
Reference in New Issue
Block a user