raycast / extensions

Everything you need to extend Raycast.
https://developers.raycast.com
MIT License
5.02k stars 2.75k forks source link

[Amazon AWS] Secrets Manager command should have a debounce for keystrokes #13296

Open b0lle opened 3 days ago

b0lle commented 3 days ago

Extension

https://www.raycast.com/Falcon/aws

Description

Hey,

the secrets manager command should have a debounce function to avoid api requests on each keystroke. I find myself in the situation that i regularly got throttling exceptions because of too many requests. Also it would be nice to add the keywords property to the list item by splitting the secret name on -,_,/,|,\= to make search more user friendly

Who will benefit from this feature?

No response

Anything else?

No response

raycastbot commented 3 days ago

Thank you for opening this issue!

🔔 @victor-falcon @Hodglim @JonathanWbn @gebeto @momme-rtf @duboiss @hexpl0it @crisboarna @sidhant92 @DorukAkinci @frese @nagauta @vineus @jfkisafk @srikirank you might want to have a look.

💡 Author and Contributors commands The author and contributors of `Falcon/aws` can trigger bot actions by commenting: - `@raycastbot close this issue` Closes the issue. - `@raycastbot rename this issue to "Awesome new title"` Renames the issue. - `@raycastbot reopen this issue` Reopens the issue. - `@raycastbot assign me` Assigns yourself to the issue. - `@raycastbot good first issue` Adds the "Good first issue" label to the issue. - `@raycastbot keep this issue open` Make sure the issue won't go stale and will be kept open by the bot.
jfkisafk commented 3 days ago

It already has the throttle defined here:

https://github.com/raycast/extensions/blob/dedf880749545861a71cb0083030441f4eae5c3e/extensions/amazon-aws/src/secrets.tsx#L24-L25

This should slow down the requests, are you still receiving throttles?

b0lle commented 3 days ago

yes I face them regularly. Maybe we can increase the throttling time?

jfkisafk commented 2 days ago

Hey @b0lle , since you're a contributor and might have more secrets in your account than I do for testing, can you please try fixing this? I think the problem is coming from the multiple async calls here:

https://github.com/raycast/extensions/blob/d2327f163a4c84b9dd57ef993f0d27474b8776ba/extensions/amazon-aws/src/hooks/use-secrets.ts#L28-L35

Here is the refactoring I would suggest for useSecrets(string):

export const useSecrets = (search: string) => {
  const {
    data: secrets,
    error,
    isLoading,
    revalidate,
    pagination,
  } = useCachedPromise(
    async (query: string) => {
        const { SecretList } = await new SecretsManagerClient({}).send(
          new ListSecretsCommand({
            NextToken: cursor,
            MaxResults: 100,
            ...(query.trim().length > 2 && { Filters: [{ Key: "all", Values: [search] }] }),
          }),
        );

        return secretList;
      },
    [search],
    { execute: isReadyToFetch() },
  );

The reason being we don't need to paginate the result of an already typeahead supported api call. Plus raycast native pagination makes 2 initial calls to the promise for some reason, instead of just one.

Then, we can make corresponding changes to the command List key and metadata (remove resource policy). I think we can add a separate action to display resource policy (as Detail view), just like we do with secret value

https://github.com/raycast/extensions/blob/d2327f163a4c84b9dd57ef993f0d27474b8776ba/extensions/amazon-aws/src/secrets.tsx#L147-L152

That way we can load the resource policy (make the api call) when user triggers the action and not during initial list rendering for all secrets. Try these changes and see if the throttling goes away.

jfkisafk commented 1 day ago

@raycastbot assign me

b0lle commented 1 day ago

thanks, I would have done it but glad you already implemented something