add charset modifier to secret generation #521
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "Apfelwurm/abra:feature/special_charset_secret_generation"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
since we need special chars in passwords for a recipe we are working on, i have added the option to specify a charset in the same way as the length can be setted.
i did not change anything in the behaviour, so if length is not specified, the charset gets ignored whether it is there or not.
you can specify the following:
charset=default
- Results in passgen.AlphabetDefault being usedcharset=special
- Results in passgen.AlphabetSpecial being usedcharset=safespecial
- Results in!@#%^&*_-+=
being used (so it is AlphabetSpecial without the dollar sign)charset=default,special
orcharset=special,default
- Results in passgen.AlphabetDefault + passgen.AlphabetSpecial being usedcharset=default,safespecial
orcharset=safespecial,default
- Results in passgen.AlphabetDefault +!@#%^&*_-+=
being used ((so it is AlphabetSpecial without the dollar sign)Also added the charset testing to TestReadSecretsConfig. I thought about implementing tests for the generation itself, but did not really come up with something that made sense for me.
As i'm not that familiar with go, this might need to be reviewed carefully and might need additional work.
Edit: PR for the docs: toolshed/docs.coopcloud.tech#271
@ -45,3 +49,3 @@
// GeneratePasswords generates passwords.
func GeneratePasswords(count, length uint) ([]string, error) {
func GeneratePasswords(count, length uint, charset string) ([]string, error) {
I think GeneratePasswords is only used with
count=1
. If you are up for it, a seperate refactor commit would be nice, that changes the function toGeneratePassword(length uint, charset string) (string, error)
(Same for
GeneratePassphrases
)done :)
@ -152,1 +156,4 @@
}
charset := modifierValues["charset"]
value.Charset = resolveCharset(charset)
This can be combined into one line
Is
"charset"
guaranteed to be present? Otherwise, you might want to do the presence check of the key and otherwise supply a default.It retuens an empty string when not present, which is handled in
resolveCharset
. SO for me its fine to not check for the presencedone :)
Really Cool ™
4795c4d732
tod3c9c39f13
@ -61,3 +65,3 @@
// GeneratePassphrases generates human readable and rememberable passphrases.
func GeneratePassphrases(count uint) ([]string, error) {
func GeneratePassphrases() ([]string, error) {
the return type could also be changed to
(string, error)
done, also changed the name to fit the single generation
@ -44,11 +48,11 @@ type Secret struct {
}
// GeneratePasswords generates passwords.
func GeneratePasswords(count, length uint) ([]string, error) {
the return type could also be changed to
(string, error)
done, also changed the name to fit the single generation
ad032bb89c
tob7d957877a