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 client.Items.ListByTags(string[] tags) #154

Open
davidolrik opened this issue Nov 18, 2024 · 4 comments
Open

Add client.Items.ListByTags(string[] tags) #154

davidolrik opened this issue Nov 18, 2024 · 4 comments

Comments

@davidolrik
Copy link

Use Case

I would like to find all items in a vault that has a specific list of tags.

items, err := client.Items.ListByTags(string[]{"tag1", "tag2"})

This would save me from fetching all items in the vault.

Requirements and desired behavior

No response

Additional information

No response

@MOmarMiraj
Copy link
Contributor

Hey @davidolrik ! This looks like something that is indeed useful for the SDKs.

We will consider adding this to the SDKs in the future.

@hculea
Copy link
Member

hculea commented Dec 3, 2024

@davidolrik also worth calling out: such filtering still needs to happen client-side, since everything in 1Password is end-to-end encrypted. So even if the SDK would expose such utility functions, these would be no more performant than fetching and decrypting all the items and searching through them.

You can already achieve this today by client.Items.ListAll which returns the item overviews containing the item tags already, which you then can filter in your code.

@manubouton
Copy link

manubouton commented Dec 5, 2024

@hculea in the API, it seems that on GET /v1/vaults/{vaultUUID}/items we can pass a filter parameter using SCIM-style filters, so I assume that the filtering can be performed on the server side ? Am I missing something ?

Here is a possible implementation :

// List all items
func (s ItemsSource) ListAll(ctx context.Context, vaultId string) (*Iterator[ItemOverview], error) {
	return s.ListAlBy(ctx, vaultId, "")
}

// List all filtered items
func (s ItemsSource) ListAllBy(ctx context.Context, vaultId, filter string) (*Iterator[ItemOverview], error) {
	params := map[string]interface{}{ "vault_id": vaultId }
	if filter != "" {
		params["filter"] = filter
	}
	resultString, err := clientInvoke(ctx, s.InnerClient, "ItemsListAll", params)
	if err != nil {
		return nil, err
	}
	var result []ItemOverview
	err = json.Unmarshal([]byte(*resultString), &result)
	if err != nil {
		return nil, err
	}
	return NewIterator(result), nil
}

WDYT ?

@manubouton
Copy link

OK the API reference that I mentioned is the connect server one ... I assume that the filter param is not available in the Service accounts one, isn't it ?

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

No branches or pull requests

4 participants