Skip to content
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

Support batch deletion #82

Closed
zcutlip opened this issue Jan 13, 2023 · 2 comments
Closed

Support batch deletion #82

zcutlip opened this issue Jan 13, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@zcutlip
Copy link
Owner

zcutlip commented Jan 13, 2023

A user on the 1Password community forums asked if there was a faster way of using the op CLI tool to delete everything in a vault:
https://1password.community/discussion/comment/664638

I think this is something that pyonepassword could be helpful for without too much work.

The op command can take a list of JSON objects via stdin, which should work with the output (or some modified form) of op item list. We already have item_list(self, categories=[], include_archive=False, tags=[], vault=None), so something like:

def item_delete_batch(self, categories=[], include_archive=False, tags=[], vault=None, batch_size=25):
    ...

... shouldn't be too much trouble

@zcutlip zcutlip self-assigned this Jan 13, 2023
@zcutlip zcutlip added the enhancement New feature or request label Jan 13, 2023
@zcutlip
Copy link
Owner Author

zcutlip commented Jan 13, 2023

I've kinda/sorta prototyped this out

basically, I've added _OPCommandInterface._item_delete_batch(), and tried it out by doing the following:

  • get a list of item descriptors from "Test Data 3"
  • break the list up into the first 25 objects and the rest
  • serialize the first batch to json
  • call _item_delete_batch()
  • serialize the second batch to json
  • call _item_delete_batch()

It seems to work, but it remains to be seen if it's faster than deleting the items one at a time.

In [5]: vault = "Test Data 3"

In [6]: for i in range(0, 30):
   ...:     title=f"Example Login Item {i:02d}"
   ...:     username=f"user_{i:02d}"
   ...:     password = LETTERS_DIGITS_SYMBOLS_20
   ...:     op.login_item_create(title, username, password=password, vault=vault)
   ...:

In [7]: items = op.item_list(vault=vault)

In [13]: batch_1=items[0:25]

In [14]: batch_2=items[25:]

In [16]: batch_str=json.dumps(batch_1)

In [18]: op._item_delete_batch(batch_str, vault)

In [19]: batch_str=json.dumps(batch_2)

In [20]: op._item_delete_batch(batch_str, vault)

@zcutlip
Copy link
Owner Author

zcutlip commented Mar 1, 2023

addressed by #92

@zcutlip zcutlip closed this as completed Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant