zcutlip / pyonepassword

A python API to query a 1Password account using the 'op' command-line tool
MIT License
68 stars 12 forks source link

type-specific `item_get()` wrapper methods #124

Open zcutlip opened 1 year ago

zcutlip commented 1 year ago

I think it would be useful to have methods that wrap OP.item_get() and return a specific op item type.

This would have at least two benefits:

I'm picturing something like:

def item_get_login(self, item_identifier, vault=None, ...) -> OPLoginItem:
    item = self.item_get(item_identifier, vault=vault, ...)
    if not isinstance(item, OPLoginItem):
        # ValueError or maybe something more specific
        raise ValueError(f"Unexpected item type for item {item_identifier}. Expected OPLoginItem")
    return item
zcutlip commented 1 year ago

existing item_get_ convenience functions will make this somewhat complicated. item_get_password() in particular

Not insurmountable, but worth considering

zcutlip commented 1 year ago

thinking about a couple issues here and how to do this gracefully...

  1. as mentioned above, there's already an item_get_password() convenience method which gets a password from any object type that has a .password property
    • so extending the Item_get naming convention with the item type would result in confusion.
    • Maybe...get_login_item(), get_password_item()...?
    • But then it breaks congruence with the op item get command/subcommand syntax..
  2. The number of methods on an OP object is already getting unwieldy, and this would result in a further explosion in the number of methods