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

add option to provide vault flag #71

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

KellerLukas
Copy link

This fixes issue #70

Copy link
Collaborator

@dtpryce dtpryce left a 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.

"""
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
Copy link
Collaborator

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?

Copy link
Author

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),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"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?

Copy link
Collaborator

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?

Copy link
Author

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')
Copy link
Collaborator

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?

Suggested change
"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))
Copy link
Collaborator

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?

Suggested change
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))

@KellerLukas
Copy link
Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants