-
-
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
[CLI] Add and Edit attributes of an entry #7462
base: develop
Are you sure you want to change the base?
[CLI] Add and Edit attributes of an entry #7462
Conversation
…attributes in cli for command add or edit
Codecov Report
@@ Coverage Diff @@
## develop #7462 +/- ##
===========================================
- Coverage 64.29% 64.26% -0.03%
===========================================
Files 339 339
Lines 43364 43413 +49
===========================================
+ Hits 27879 27898 +19
- Misses 15485 15515 +30
Continue to review full report at Codecov.
|
@olszeww0 thanks for the PR. From what I understand, only 1 attribute can be added or edited at a time. Is that correct? Regarding the testing strategy, all the cases you outlined should be translated into unit tests. See |
Yes, only 1 attribute can be added or edited at a time. |
We should allow more than one, just allow multiple instances of the flag(s). |
I can see the following disadvantages of this solution:
For the advanced user, yes, this can be convenient. |
I'm not sure that would work with the current implementation, because the attribute name is specified separately from the attribute value. I thought about that a bit more, and I can't think of an elegant solution to address the problem. Maybe we could allow specifying the attribute name and value together, as such:
That would allow editing multiple attributes using a single
Fair point, but I'm not sure this is relevant in our case. I doubt that a significant number of attributes will be edited in a single invocation, and users can always make multiple calls to |
@olszeww0 I'm planning to implement the |
@louib do we still want to merge this one? |
After about a year of creating this PR, my thinking is that the proposed solution may not be optimal for various reasons. What do you think about using only one attribute for example "-a" with the following syntax:
attribute-name - mandatory attribute name {SEPARATOR1} and {SEPARATOR2} - always required, to distinguish between the name, value, and protection flag of an attribute. Or maybe change the order:
and in this case {SEPARATOR} is also always required and it is enough that it is outside the range of base64 characters. What do you think? I also see that the add and edit options are redundant, so you could only opt for the "edit" option. In this case, if the argument didn't exist, it would be created. However, there is a risk here that a user who would make a mistake in the name of an existing attribute would create a new unwanted attribute. Maybe it would be better to tell the user that the attribute doesn't exist when he thinks it does and return an error.
-A means edit existing attribute or create new if it not exists.
|
Generally speaking, the CLI is not fault tolerant to perceived user errors, I wouldn't worry too much about that. It is not meant for daily/sole use and very much meant for scripted use cases. I like your idea to collapse to just an edit command. If you really wanted to you could add a flag like Additionally, for the multiple attributes you could just accept a json string which has it's own escaping rules.
|
Would you be so kind to support a way other that passing attributes' value from a CLI option (or a environment variable) , to avoid leaking secret (such as TOTP secrets) in the shell's history or the OS process table? A solution would be to be able to specify such value from a pipe or a prompt or a file. |
Any insight on when it will be available in releases ? |
It has some challenges so those need to be resolved first. |
Closes #9212
Lack of add or edit attribute in the entry
Testing strategy
some password for a new database
read -s PK
create a new database
printf "%s\n%s\n" "$PW" "$PW" | keepassxc-cli db-create -p test.kdbx
create group
printf "%s\n" "$PW" | keepassxc-cli mkdir -q test.kdbx a
create entry 'e1' in group 'a' with empty unprotected attribute 'custom'
printf "%s\n%s\n" "$PW" "$PW" | keepassxc-cli add -q -u test --url 'http://example.net' -p -a custom test.kdbx a/e1
create entry 'e2' in group 'a' with unprotected attribute 'custom' with attribute's value 'custom value'
printf "%s\n%s\n" "$PW" "$PW" | keepassxc-cli add -q -u test --url 'http://example.net' -p -a custom -A $( echo -n "custom value" | base64 -w 0) test.kdbx a/e2
create entry 'e3' in group 'a' with protected attribute 'custom' with attribute's value 'custom value'
printf "%s\n%s\n" "$PW" "$PW" | keepassxc-cli add -q -u test --url 'http://example.net' -p -a custom -A $( echo -n "custom value" | base64 -w 0) -P test.kdbx a/e3
create empty unprotected attribute 'custom2' in a/e1
printf "%s\n" "$PW" | keepassxc-cli edit -q -a custom2 test.kdbx a/e1
create empty protected attribute 'custom3' in a/e1
printf "%s\n" "$PW" | keepassxc-cli edit -q -a custom3 -P test.kdbx a/e1
set attribute 'custom3' in a/e1 to be unprotected
printf "%s\n" "$PW" | keepassxc-cli edit -q -a custom3 --unprotect test.kdbx a/e1
set value of attribute 'custom3' in a/e1
printf "%s\n" "$PW" | keepassxc-cli edit -q -a custom3 -A $( echo -n "custom value" | base64 -w 0) test.kdbx a/e1
show things
printf "%s\n" "$PW" | keepassxc-cli ls -q test.kdbx a
printf "%s\n" "$PW" | keepassxc-cli show -q -s -a custom test.kdbx a/e1
printf "%s\n" "$PW" | keepassxc-cli show -q -s -a custom test.kdbx a/e2
printf "%s\n" "$PW" | keepassxc-cli show -q -s -a custom test.kdbx a/e3
printf "%s\n" "$PW" | keepassxc-cli show -q -a custom2 test.kdbx a/e1
printf "%s\n" "$PW" | keepassxc-cli show -q -a custom3 test.kdbx a/e1
In edit command if atribute exists and some option like -P,--unprotect or -A is not used, appropriately attribute's protection and attribute's value remain unchanged. So It is possible to use -a and any option from ( -A, -P, --unprotect ) in any combination.
Add command hasn't option --unprotect, because default action is unprotect - you only set protection with -P option. Of course, -P and --unprotect cann't bu used together.
Only one attribute can be added or edited at once. If you have more than one attributes and entry does not exists, you can(not must) add first with add command, then use edit command to add rest. If entry exist, use edit command to add all attributes.