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

Prompt occurs multiple times if re-used in request #118

Open
LucasPickering opened this issue Mar 17, 2024 · 0 comments
Open

Prompt occurs multiple times if re-used in request #118

LucasPickering opened this issue Mar 17, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@LucasPickering
Copy link
Owner

LucasPickering commented Mar 17, 2024

If the same chained prompt value is used multiple times in a request, it prompts once per usage. It should only prompt once per request.

chains:
  username:
    source: !command ["sh", "-c", "whoami | tr -d '\n'"]
  password:
    source: !prompt Password
    sensitive: true

requests:
  login:
    method: POST
    url: "{{host}}/anything/login"
    query:
      sudo: yes_please
      password: "{{chains.password}}"
    body: |
      {
        "username": "{{username}}",
        "password": "{{chains.password}}"
      }

This is a tough one to fix because each template render is executed independently and in parallel during request build. The solution would probably be to scan all parsed templates at the start of the request, and collect all used chains into a de-duplicated pool. Then resolve those chain values first, before finally rendering the templates themselves. This has the added benefit of de-duplicating other chain types too (e.g. if a slow shell command is chained, it won't have to execute multiple times).

It's very possible, just requires rearchitecting the template code a fair amount.

futures::future::shared may be helpful for caching the futures.

@LucasPickering LucasPickering added the bug Something isn't working label Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant