-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
keepassxc-cli: Implement attachment handling #5538
keepassxc-cli: Implement attachment handling #5538
Conversation
This PR is almost ready and it brings something towards the CLI as a full alternative to the GUI. I use attachments extensively and in the CLI it appears like they don't even exist. Now the PR is stuck on something that can be debated and should be debated but it definitely looks broader and deeper than the scope of the PR itself. By reading the comments it looks like in this particular instance both the solutions might be safe in the present and only become problematic as the development goes on and the caller changes or new code does not respect the same style. Is there someone willing to unstuck this? Maybe @louib? |
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.
@andreblanke Added a few comments, but overall I think this PR is really close to be ready to merge. The tests are looking good. Thx for the PR! 🙏
I personally don't like that we are introducing new named commands. I would much rather handle this through entry editing with switches for attachment handling.
This is the defined workflow with our cli, by adding new commands you create new workflows and that is generally frowned upon. |
@droidmonkey the main problem that I see with jamming all the attachment commands in Whichever decision we make, I think we should also update the |
Can we just add an "attachment" command and use add/edit/get subcommands? |
@droidmonkey that could be an option, although it would be inconsistent with what we have for the entry commands, the group commands and the db commands, which have dedicated commands for every action. |
Yah I agree, blah... this just sets up bad precedent moving forward for other features. We need to be careful of command creep... already have that problem! |
I'm sorry for this pull request becoming stale, partially due to the discussion. In hindsight I should have just added the additional null safety. However, I mainly remember not being able to resolve the build failures and pausing development due to that. @louib Thanks for the feedback! I will try to implement the changes you suggested in the next few days. I unfortunately don't have too much time on my hands at the moment but will try to get to it soon. Concerning the command design: I tried to stay consistent but agree that an |
@andreblanke let me know when you need another review! |
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.
Almost there!
A few things:
- You can format the codebase using
make format
. This should fix the formatting CI job. - We should add the attachments in the output of the
show
command, otherwise there's no way to see the attachments of an entry from the CLI. - There's a conflict in the
NewDatabase
file, you'll probably need to rebase your branch againstdevelop
and fix the conflict. It'll probably be easier to start from the version ondevelop
and re-apply your changes on it.
Could also merge your version of new database into the develop version using keepassxc merge feature 😃 |
@andreblanke the only thing remaining would be to add some tests to the |
I introduced the Other than that the tests should be good to go with the exception of |
src/cli/AttachmentExport.h
Outdated
|
||
#include "DatabaseCommand.h" | ||
|
||
#include <QFile> |
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 import should be in the cpp only
src/cli/AttachmentExport.cpp
Outdated
*/ | ||
|
||
#include <cstdio> | ||
#include <cstdlib> |
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.
These imports are not necessary, already in the header
src/cli/AttachmentExport.cpp
Outdated
#include <QCommandLineParser> | ||
#include <QFile> | ||
|
||
AttachmentExport::AttachmentExport(FILE* fout) |
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 would prefer some way to also optionally specify the output file name instead of always dumping to stdout.
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 decided to entirely remove dumping to stdout when using attachment-export
for the following reasons:
- Symmetry with
attachment-import
which is only able to import from a file, not from stdin. - Binary output might mess up the terminal.
- I found no good way to output the attachment which could both be checked by the tests using
m_stdout->readAll()
but also actually displayed the content to the user. All solutions I tried so far only allowed one of those things (at least without including some kind of workaround likem_fout
that was used previously inAttachmentExport
, but is now removed).
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 concur with this and it's consistent with how the gui handles attachments... as files.
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.
Thinking this through... there might be value in a --stdout
flag on attachment-export for people who want to pipe the contents of an attachment into another command. When that flag is issued then the export_file positional parameter is ignored/optional. This is coming from #6947
@andreblanke everything is looking good, except for the tests failing. Might need a rebase on |
Alright. I'm a bit busy at the moment but I'll try to get around to it on the weekend. While I'm at it I'll look into adding |
I squashed all the commits, fixed the tests, and found a typo too! This is ready for merge after CI completes. |
@droidmonkey some tests are failing, and apparently it's related to entry history?
|
Yah I have no idea what is going on, could be because the entry was edited in NewDatabase.kdbx |
* Add commands to manipulate entry attachments from the CLI * Closes #4462 * Add the following commands: attachment-export: Exports the content of an attachment to a specified file. attachment-import: Imports the attachment into an entry. An existing attachment with the same name may be overwritten if the -f option is specified. attachment-rm: Removes the named attachment from an entry. * Add --show-attachments to the show command
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #5538 +/- ##
===========================================
+ Coverage 63.87% 64.11% +0.25%
===========================================
Files 330 333 +3
Lines 41838 41992 +154
===========================================
+ Hits 26720 26923 +203
+ Misses 15118 15069 -49 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
The GUI tests were exactly the ones I didn't know how to fix. Glad I wasn't the only one confused by them though. Anyway, thanks @droidmonkey for finishing off the PR. It was a pleasure working with you two and I appreciate the feedback that you gave me regarding my commits |
This pull request implements three new commands and strives to address #4462:
attachment-export database entry name
which exports the contents of an attachment inside a database entry to the command lineattachment-import [-f] database entry name attachment
which imports a fileattachment
into a database entry under a given name. An existing attachment with the same name may be overridden if the-f
option is specifiedattachment-rm database entry name
which removes the attachment with the provided name from the entry inside the databaseDesign decisions
The linked issue suggests modifications to the
add
andedit
commands instead of introducing new commands like I have done but I felt having dedicated commands for it was a cleaner approach then adding additional functionality toadd
andedit
, even though I am a bit unsure about it.A
getattachment
orattachment-export
command would be needed anyway and this way there exists symmetry betweenattachment-export
andattachment-import
.For consistency with
export
,attachment-export
outputs the contents of an attachment to the command line instead of taking an additional file argument.I am unsure whether a command like
attachment-mv
to rename an attachment or to move it from one entry to another would be a worthwhile addition, as that use case can be covered using a combination of the commands implemented in this pull request.Additionally, the
name
argument ofattachment-import
could be made optional, in which case it would default to the name of the attachment file. In that case switching the order of arguments toattachment-import [-f] database entry attachment [name]
might also make sense.Testing strategy
A unit test for each of the new commands has been added in
TestCli.cpp
.Along with that I introduced
tests/data/Attachment.txt
used as a test attachment and added theSample attachment.txt
(with content "Sample content\n") to the/Sample Entry
inNewDatabase.kdbx
.Type of change