-
Notifications
You must be signed in to change notification settings - Fork 496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Implement builtin mode for keepassxc #4149
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this!
Instead of a new set of template functions, I think this different "mode" for opening KeepassXC databases. Currently chemzoi supports "cache-password" and "open" modes. I think this should be a new "builtin" mode.
What do you think?
Sounds reasonable. |
@@ -100,6 +113,18 @@ func (c *Config) keepassxcTemplateFunc(entry string) map[string]string { | |||
} | |||
|
|||
func (c *Config) keepassxcAttributeTemplateFunc(entry, attribute string) string { | |||
if c.Keepassxc.Mode == keepassxcModeBuiltin { | |||
// builtin stores attributes in cache | |||
if data, ok := c.Keepassxc.cache[entry]; ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the library handles default values the same as attributes, both functions use the same cache in builtin mode.
I don't think that i makes sense to keep separate caches in this case.
@@ -329,3 +354,82 @@ func (c *Config) keepassxcClose() error { | |||
} | |||
return nil | |||
} | |||
|
|||
// keepassxcBuiltinExtractValues extract builtin values | |||
func (c *Config) keepassxcBuiltinExtractValues( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation reads all values from the keepass database to reduce access to the file itself.
If this might blow the memory I can change the implementation to only cache the requested values.
5396dc8
to
f42961b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, this is looking excellent, and I will do a full review after the weekend.
Please also check the contributing guide for low-hanging fruit.
But, thank you, this PR is excellent.
@@ -117,6 +117,7 @@ func TestKeepassxcTemplateFuncs(t *testing.T) { | |||
for _, mode := range []keepassxcMode{ | |||
keepassxcModeCachePassword, | |||
keepassxcModeOpen, | |||
keepassxcModeBuiltin, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm having some issues on running this test.
When only keepassxcModeBuiltin
mode is enabled, the test is running.
But when the other 2 are also enabled (or only the 2 other) the test fails.
I can't figure out the issue here. Might be some precondition in my environment.
Enter password to encrypt database (optional):
Repeat password:
Successfully created new database.
Enter password to unlock /tmp/TestKeepassxcTemplateFuncs1798468072/001/KeePassXC Passwords.kdbx:
Successfully added group test group.
Enter password to unlock /tmp/TestKeepassxcTemplateFuncs1798468072/001/KeePassXC Passwords.kdbx:
Enter password for new entry:
Successfully added entry test entry.
Enter password to unlock /tmp/TestKeepassxcTemplateFuncs1798468072/001/KeePassXC Passwords.kdbx:
Successfully imported attachment /tmp/TestKeepassxcTemplateFuncs1798468072/001/import file as test / attachment name to entry test group/test entry.
error: Permission denied
--- FAIL: TestKeepassxcTemplateFuncs (0.37s)
--- FAIL: TestKeepassxcTemplateFuncs/cache-password (0.01s)
--- FAIL: TestKeepassxcTemplateFuncs/cache-password/correct_password (0.01s)
panic: /home/bakito/bin/keepassxc-cli show '/tmp/TestKeepassxcTemplateFuncs1798468072/001/KeePassXC Passwords.kdbx' --quiet --show-protected 'test group/test entry': exit status 1 [recovered]
panic: /home/bakito/bin/keepassxc-cli show '/tmp/TestKeepassxcTemplateFuncs1798468072/001/KeePassXC Passwords.kdbx' --quiet --show-protected 'test group/test entry': exit status 1
goroutine 415 [running]:
testing.tRunner.func1.2({0x17a2560, 0xc006f6e370})
/home/bakito/.gimme/versions/go1.23.4.linux.amd64/src/testing/testing.go:1632 +0x230
testing.tRunner.func1()
/home/bakito/.gimme/versions/go1.23.4.linux.amd64/src/testing/testing.go:1635 +0x35e
panic({0x17a2560?, 0xc006f6e370?})
/home/bakito/.gimme/versions/go1.23.4.linux.amd64/src/runtime/panic.go:785 +0x132
github.com/twpayne/chezmoi/v2/internal/cmd.mustValue[...](...)
/home/bakito/go/src/github.com/bakito/chezmoi/internal/cmd/cmd.go:254
github.com/twpayne/chezmoi/v2/internal/cmd.(*Config).keepassxcTemplateFunc(0xc0073aa008, {0xc008243e18, 0x15})
/home/bakito/go/src/github.com/bakito/chezmoi/internal/cmd/keepassxctemplatefuncs.go:103 +0x24a
github.com/twpayne/chezmoi/v2/internal/cmd.TestKeepassxcTemplateFuncs.func1.1(0xc0072c3380)
/home/bakito/go/src/github.com/bakito/chezmoi/internal/cmd/keepassxctemplatefuncs_test.go:130 +0x1fa
testing.tRunner(0xc0072c3380, 0xc00737b170)
/home/bakito/.gimme/versions/go1.23.4.linux.amd64/src/testing/testing.go:1690 +0xf4
created by testing.(*T).Run in goroutine 414
/home/bakito/.gimme/versions/go1.23.4.linux.amd64/src/testing/testing.go:1743 +0x390
Signed-off-by: bakito <[email protected]>
Implements: #4148
Depends on: #4150