-
Notifications
You must be signed in to change notification settings - Fork 27
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
add option to provide vault flag #71
base: main
Are you sure you want to change the base?
Conversation
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.
Good starting place! Also might want to update tests and README to reflect use case.
onepassword/client.py
Outdated
""" | ||
Helper function to get a certain field, you can find the UUID you need using list_items | ||
|
||
:param uuid: Uuid of the item you wish to get, no vault needed | ||
:param fields: To return only certain detail use either a specific field or list of them | ||
(Optional, default=None which means all fields returned) | ||
:param vault_uuid: When using service account, a vault_uuid must be provided |
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.
It can be name or ID right?
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.
right! I renamed vault_uuid to vault to reflect that.
if isinstance(fields, list): | ||
item_list = json.loads(read_bash_return( | ||
"op item get {} --format=json --fields label={}".format(uuid, ",label=".join(fields)), | ||
"op item get {} --format=json --fields label={} {}".format(uuid, ",label=".join(fields), vault_flag), |
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.
"op item get {} --format=json --fields label={} {}".format(uuid, ",label=".join(fields), vault_flag), | |
"op item get {} --format=json --fields label={} --vault {}".format(uuid, ",label=".join(fields), vault_flag), |
do you mean this?
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.
And since this is an optional you must code for vault being empty - will this command fail in that instance?
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.
no, see line 435: vault_flag already includes the "--vault" and is an empty string is vault is not provided to handle the base case vault=None.
@@ -444,10 +446,10 @@ def get_item(uuid: str | bytes, fields: str | bytes | list | None = None): | |||
elif isinstance(fields, str): | |||
item = { | |||
fields: read_bash_return( | |||
"op item get {} --fields label={}".format(uuid, fields), single=False).rstrip('\n') | |||
"op item get {} --fields label={} {}".format(uuid, fields, vault_flag), single=False).rstrip('\n') |
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.
Same as above plus what if it's empty?
"op item get {} --fields label={} {}".format(uuid, fields, vault_flag), single=False).rstrip('\n') | |
"op item get {} --fields label={} --vault {}".format(uuid, fields, vault_flag), single=False).rstrip('\n') |
} | ||
else: | ||
item = json.loads(read_bash_return("op item get {} --format=json".format(uuid), single=False)) | ||
item = json.loads(read_bash_return("op item get {} --format=json {}".format(uuid, vault_flag), single=False)) |
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.
Same as above plus what if it's empty?
item = json.loads(read_bash_return("op item get {} --format=json {}".format(uuid, vault_flag), single=False)) | |
item = json.loads(read_bash_return("op item get {} --format=json --vault {}".format(uuid, vault_flag), single=False)) |
@dtpryce I couldn't find any tests except for some that look like placeholders, so I also did not add any for this new use case. Happy to adjust existing ones or add additional ones, if you tell me where that could fit in. |
This fixes issue #70