Skip to content
This repository was archived by the owner on Aug 15, 2018. It is now read-only.

contact delete and list added #78

Merged
merged 11 commits into from
Jul 5, 2018
Merged

contact delete and list added #78

merged 11 commits into from
Jul 5, 2018

Conversation

diveshuttam
Copy link
Contributor

@diveshuttam diveshuttam commented Jul 3, 2018

closes #35 closes #40

@diveshuttam diveshuttam added this to the Second Evaluations milestone Jul 3, 2018
@diveshuttam diveshuttam self-assigned this Jul 3, 2018
gpg --delete-keys "$@"
else
gpg --batch --no-tty --yes --delete-keys "$@"
yesno "Delete contact(s). Are you sure?" || return 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is does not preserve the original behavior.
The question itself is meaningless and does not add any extra protection, without showing the contacts that are going to be deleted.

Copy link
Member

@sourabhtk37 sourabhtk37 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@diveshuttam diveshuttam changed the title contact delete added [WIP:DNM] contact delete added Jul 4, 2018
Copy link
Member

@dashohoxha dashohoxha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of the files __init.py__?

src/egpg.sh Outdated
@@ -124,6 +124,7 @@ call_fn() {
call_gpg() {
local file=$1; shift
local pyfile="$LIBDIR/gpg/$file"
export PYTHONPATH=$PYTHONPATH:"$LIBDIR/gpg/"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should be better moved down, before the python3 call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok done.

for key in keys:
if(not force):
print_key(key.fpr)
ans = input("Delete this key from the keyring? (y/N)")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are deleting contacts, not keys. Why do you print a key? Why do you ask for a key?

Copy link
Contributor Author

@diveshuttam diveshuttam Jul 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am currently somewhat imitating what egpg did earlier. This is one of the ways it could be done. I pushed it here to discuss more about it.

So here is what gpg commands (egpg) originally did:

  • If I pass a egpg delete contact1 without --force
    • For each key of the contact gpg asked if you want to delete the key (with the exact same message)
    • it exited as soon as one key was deleted
  • If I pass egpg delete contact1 --force
    • it deletes all keys matching contact1

What i am doing right now is:

  • delete all keys matching the contact in case of --force without any messages
  • for all matching keys with the contact ask one by one and let the user choose to delete or not (y/N) (I feel it is helpful if he wants to delete specific keys corresponding to a contact name).

Would like your suggestions.

Copy link
Contributor Author

@diveshuttam diveshuttam Jul 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way to approach this could be:

  • by default doing a cmd_contact_list contact1 first and asking delete all these keys matching contact1 (y/N). If these are more keys let the user him/herself delete these by using keyids instead.

  • we might add a option --interactive which has the current behavior as mentioned in the above comment.

  • --force dominates over --interactive

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am currently somewhat imitating what egpg did earlier.

You can stick to the gpg behavior if you want. But I don't think it is right to delete single subkeys of a given contact (in case he has different encryption subkeys).

Actually I think that we are talking about different contacts, although they may have the same name and the same email address. So what you are doing may be right. You are actually deleting all the matching contacts (the contacts that match with the given search string), not all the keys of the given contact. I am not sure if I am explaining myself clearly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we talk about contact1, as an argument to the delete command, it can be an email address, or a full name, or a first name, etc. So, it is actually a search pattern which may match more than one contact (called key in the gpg language, which is an overloaded term according to me). It makes sense to ask for each of these matching contacts whether they should be deleted or not. But when we delete a contact, we delete it completely, not only one subkey of it. I believe this is also the current behavior of gpg.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup I think I got it : a contact in egpg is identified as a key (with subkeys) in gpg / gpgme.

I am deleting all subkeys with the key at once only.
I was actually talking about the case of multiple contact matches occur corresponding to the string passed.

Copy link
Contributor Author

@diveshuttam diveshuttam Jul 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had borrowed the message Delete this key from the keyring? (y/N) from gpg only. If it seems confusing I can change key to contact.
It does delete a key with all subkeys together as mentioned above.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should be confusing for the user, because as far as the user knows there is only one key, his own private key. All the rest are contacts.

@dashohoxha
Copy link
Member

Sorry, I just notice the label "work in progress". Otherwise I would not have made a review.

print_key modified
@diveshuttam diveshuttam changed the title [WIP:DNM] contact delete added contact delete and list added Jul 4, 2018
@diveshuttam
Copy link
Contributor Author

diveshuttam commented Jul 4, 2018

The purpose of __init__.py here is to allow imports like from fn.print_key import print_key etc.
It is basically used to tell python that the directory contains python modules and packages.

@diveshuttam
Copy link
Contributor Author

@dashohoxha the PR can be reviewed now.

@diveshuttam
Copy link
Contributor Author

diveshuttam commented Jul 4, 2018

Since this required quite some changes with the print_key functionality I also addressed contact list in this PR only.

some minor changes in contact list
@diveshuttam
Copy link
Contributor Author

Sorry, I just notice the label "work in progress". Otherwise I would not have made a review.

Its fine and I am sorry too, I hadn't updated my progress for the day so pushed whatever I had done by that time.

@dashohoxha
Copy link
Member

The purpose of init.py here is to allow imports like from fn.print_key import print_key etc.
It is basically used to tell python that the directory contains python modules and packages.

Now I understand it. I guess that you can merge this PR as soon as @sourabhtk37 reviews the code style etc.

@diveshuttam diveshuttam dismissed dashohoxha’s stale review July 5, 2018 01:01

requested changes addressed.

Copy link
Member

@sourabhtk37 sourabhtk37 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few pointers here and there. Great job 👏

keys = list(c.keylist(contact))
ans = "n"
for key in keys:
if(not force):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why still use brackets for if expr? Please keep it consistent.

Copy link
Contributor Author

@diveshuttam diveshuttam Jul 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool I have addressed this and also opened #79 also for this. This gets missed as I am using flake8 which doesn't detect this by default.

try:
c = gpg.Context()

key_set = set({})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simply initialise a set as set().

key_set = set({})

for contact in contact_list:
key_set.update(set(c.keylist(contact)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you might want to use the set.add() method or are we missing some use-case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A contact (contact string) can have multiple matches. This is intended to list all of them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set is required as in case of multiple arguments, like egpg contact ls divesh $MYKEYID i want to list each contact only once.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if c.keylist returns a list, you don't need to convert it into a set is what I'm inferring, it will do that on its own afaik.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It returns a generator but yup it will do the job I guess.

from fn.print_key import print_key


def ls(contact_list):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe have a bit more descriptive function name like: list_contact, you can do away with comments with this.
Tip: Your code should be such that it doesn't required comments to describe what it is doing. I think it's pretty clear with the function name.
Something to read:https://blog.codinghorror.com/coding-without-comments/

Copy link
Member

@sourabhtk37 sourabhtk37 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dashohoxha Good to go imo.

@diveshuttam diveshuttam merged commit a3a74de into gnupg-2.2 Jul 5, 2018
@diveshuttam diveshuttam deleted the issue35 branch July 6, 2018 03:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update contact/list.sh Update contact/delete.sh
3 participants