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

List by tag #40

Open
mafrosis opened this issue Mar 23, 2022 · 2 comments
Open

List by tag #40

mafrosis opened this issue Mar 23, 2022 · 2 comments
Labels
enhancement New feature or request tracked Issue is tracked in 1Password's internal ticketing system as well.

Comments

@mafrosis
Copy link

Summary

I have existing CLI scripts which list secrets as k:v pairs by tag, using the v1 version of op. I'd like to be able to do this with v2 and Connect.

Use cases

I don't want to list ALL secrets. I don't want to fetch many by name. I want to list by a specific tag.

Proposed solution

I'm interested in contributing a solution, but I see a bunch of the code is autogenerated somehow. If you can advise then maybe I can implement what I need!

@edif2008 edif2008 added the tracked Issue is tracked in 1Password's internal ticketing system as well. label May 30, 2022
@edif2008
Copy link
Member

edif2008 commented Jun 7, 2022

Hey @mafrosis,

Thank you for raising this. This is an interesting use case and I find it quite handy.

Indeed, a bunch of code has been generated based on the API spec at the beginning to ease the development, but now we're no longer relying on the autogenerated tool. So you don't need to worry too much about it.

We really appreciate your interest in contributing a solution for this. You can fork this repo and try to make a function that achieves your desired result. Then you can open a PR and we will take a look at it.

The API call for filtering the items by tag should have the following endpoint:

v1/vaults/<vault-id>/items?filter=tag eq <tag-name>

Here's an example function I've come up with that may achieve what you want:

    def get_items_by_tags(self, vault_id: str, tag: str):
        """Returns a list of item summaries for the specified vault
           filtered by the provided tags

        Args:
            vault_id (str): The id of the vault in which to get the items from
            tag (str): The list of tags to filter the items returned

        Raises:
            FailedToRetrieveItemException: Thrown when a HTTP error is returned
            from the 1Password Connect API

        Returns:
            List[SummaryItem]: A list of summarized items
        """
        filter_query = f'tag eq "{tag}"'
        url = f"/v1/vaults/{vault_id}/items?filter={filter_query}"

        response = self.build_request("GET", url)
        try:
            response.raise_for_status()
        except HTTPError:
            raise FailedToRetrieveItemException(
                f"Unable to retrieve items. Received {response.status_code} \
                     for {url} with message: {response.json().get('message')}"
            )

        return self.deserialize(response.content, "list[SummaryItem]")

In the meantime, I've also raised this with my team and will let you know when we same something in progress (like a PR) that may tackle this enhancement.

@edif2008 edif2008 added the enhancement New feature or request label Jun 7, 2022
@mjpieters
Copy link
Contributor

Was there any progress on this item?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request tracked Issue is tracked in 1Password's internal ticketing system as well.
Projects
None yet
Development

No branches or pull requests

3 participants