add charset modifier to secret generation #521

Merged
p4u1 merged 4 commits from Apfelwurm/abra:feature/special_charset_secret_generation into main 2025-03-21 10:29:21 +00:00
Member

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 used
charset=special - Results in passgen.AlphabetSpecial being used
charset=safespecial - Results in !@#%^&*_-+= being used (so it is AlphabetSpecial without the dollar sign)
charset=default,special or charset=special,default - Results in passgen.AlphabetDefault + passgen.AlphabetSpecial being used
charset=default,safespecial or charset=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

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 used `charset=special` - Results in passgen.AlphabetSpecial being used `charset=safespecial` - Results in `!@#%^&*_-+=` being used (so it is AlphabetSpecial without the dollar sign) `charset=default,special` or `charset=special,default` - Results in passgen.AlphabetDefault + passgen.AlphabetSpecial being used `charset=default,safespecial` or `charset=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: https://git.coopcloud.tech/toolshed/docs.coopcloud.tech/pulls/271
Apfelwurm added 1 commit 2025-03-17 17:15:14 +00:00
add charset to secret generation
All checks were successful
continuous-integration/drone/pr Build is passing
4795c4d732
p4u1 approved these changes 2025-03-18 07:45:41 +00:00
Dismissed
@ -45,3 +49,3 @@
// GeneratePasswords generates passwords.
func GeneratePasswords(count, length uint) ([]string, error) {
func GeneratePasswords(count, length uint, charset string) ([]string, error) {
Member

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 to GeneratePassword(length uint, charset string) (string, error)

(Same for GeneratePassphrases)

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 to `GeneratePassword(length uint, charset string) (string, error)` (Same for `GeneratePassphrases`)
Author
Member

done :)

done :)
Apfelwurm marked this conversation as resolved
@ -152,1 +156,4 @@
}
charset := modifierValues["charset"]
value.Charset = resolveCharset(charset)
Member

This can be combined into one line

This can be combined into one line
Owner

Is "charset" guaranteed to be present? Otherwise, you might want to do the presence check of the key and otherwise supply a default.

Is `"charset"` guaranteed to be present? Otherwise, you might want to do the presence check of the key and otherwise supply a default.
Member

It retuens an empty string when not present, which is handled in resolveCharset. SO for me its fine to not check for the presence

It retuens an empty string when not present, which is handled in `resolveCharset`. SO for me its fine to not check for the presence
Author
Member

done :)

done :)
Apfelwurm marked this conversation as resolved
Owner

Really Cool ™

Really Cool ™
Apfelwurm force-pushed feature/special_charset_secret_generation from 4795c4d732 to d3c9c39f13 2025-03-18 11:32:58 +00:00 Compare
Apfelwurm requested review from p4u1 2025-03-18 12:18:36 +00:00
p4u1 reviewed 2025-03-21 07:59:55 +00:00
@ -61,3 +65,3 @@
// GeneratePassphrases generates human readable and rememberable passphrases.
func GeneratePassphrases(count uint) ([]string, error) {
func GeneratePassphrases() ([]string, error) {
Member

the return type could also be changed to (string, error)

the return type could also be changed to `(string, error)`
Author
Member

done, also changed the name to fit the single generation

done, also changed the name to fit the single generation
Apfelwurm marked this conversation as resolved
p4u1 reviewed 2025-03-21 08:00:05 +00:00
@ -44,11 +48,11 @@ type Secret struct {
}
// GeneratePasswords generates passwords.
func GeneratePasswords(count, length uint) ([]string, error) {
Member

the return type could also be changed to (string, error)

the return type could also be changed to `(string, error)`
Author
Member

done, also changed the name to fit the single generation

done, also changed the name to fit the single generation
Apfelwurm marked this conversation as resolved
Apfelwurm added 1 commit 2025-03-21 08:25:46 +00:00
Apfelwurm force-pushed feature/special_charset_secret_generation from ad032bb89c to b7d957877a 2025-03-21 08:27:28 +00:00 Compare
p4u1 approved these changes 2025-03-21 08:40:28 +00:00
decentral1se added this to the abra v0.10.0 project 2025-03-21 10:05:11 +00:00
p4u1 added 1 commit 2025-03-21 10:27:01 +00:00
p4u1 merged commit d0f982456e into main 2025-03-21 10:29:21 +00:00
p4u1 deleted branch feature/special_charset_secret_generation 2025-03-21 10:29:21 +00:00
decentral1se moved this to Done in abra v0.10.0 on 2025-04-14 22:00:59 +00:00
decentral1se moved this to Done in abra v0.10.0 on 2025-04-14 22:01:01 +00:00
decentral1se moved this to Done in abra v0.10.0 on 2025-04-16 05:16:08 +00:00
decentral1se moved this to Done in abra v0.10.0 on 2025-04-16 05:16:10 +00:00
decentral1se moved this to Done in abra v0.10.0 on 2025-04-19 07:28:29 +00:00
decentral1se moved this to Done in abra v0.10.0 on 2025-04-21 17:48:16 +00:00
Sign in to join this conversation.
No description provided.