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

Global Variables #265

Open
camilamaia opened this issue Sep 1, 2020 · 7 comments · May be fixed by #507
Open

Global Variables #265

camilamaia opened this issue Sep 1, 2020 · 7 comments · May be fixed by #507
Assignees
Labels
Feature New feature or request

Comments

@camilamaia
Copy link
Member

camilamaia commented Sep 1, 2020

Global Variables

Enable the possibility to have global variables. Sometimes we need to access a variable from outside the scope, for example:

endpoints:
  - name: owner
    headers:
      Authorization: ${OWNER_TOKEN}
    requests:
      - name: register a book
        path: register/book
        method: post
        body:
          title: My Little Book
          author: John P.
        vars:
          book_id: ${{ request.json()["data"]["id"] }}
      - ...
      - ...
  - name: client
    headers:
      Authorization: ${CLIENT_TOKEN}
    requests:
      - name: rent a book
        path: rent/book/${book_id}
        method: POST
      - ...
      - ...

It would be nice to have a way to store book_id globally. Currently, the example above wouldn't work because the second request is not in the same scope as the first one.

@camilamaia camilamaia added the Feature New feature or request label Sep 1, 2020
@camilamaia camilamaia added the Hacktoberfest http://hacktoberfest.digitalocean.com/ label Sep 29, 2020
@camilamaia camilamaia added this to To do in Hacktoberfest 2020 Oct 8, 2020
@camilamaia camilamaia changed the title Global Variables Enable vars key at the Endpoint level Oct 8, 2020
@camilamaia camilamaia changed the title Enable vars key at the Endpoint level Global Variables Oct 8, 2020
@gillianomenezes
Copy link
Contributor

Hi @camilamaia! Can I assign it to myself?

@camilamaia
Copy link
Member Author

@gillianomenezes yes sure!!

@BrunoPontesLira
Copy link

BrunoPontesLira commented May 4, 2021

Hi.
It is already running?

I am trying:

endpoints:
  - name: Cliente Credentials
    path: https://cloud.ihf
    endpoints:
      - name: GET access_token
        requests:
          - name: credencial
            path: api/oauth/token
            method: POST
            headers: {
              'x-x-correlationID': xxxxxxx,
              'x-x-flowID': xxxxxxxxxx,
              'User-Agent': Apache-HttpClient/4.5.5 (Java/11.0.5),
              'Content-Type': application/x-www-form-urlencoded
            }
            body: "xxxxxxxxxxxx"
            vars:
              access_token: ${{ response.json()['access_token'] }}
            tests:
              - name: Status code = 200
                assert: ${{ response.status_code == 200 }}

  - name: Titular
    path: https://mbi.cloud.ihf
    endpoints:
      - name: GET access_token
        requests:
          - name: credencial
            path: seguranca/v1
            method: POST
            headers: {
              'x-x-correlationID': xxxxxxxxxxxxx,
              'x-x-flowid': xxxxxxxxxxx,
              'x-x-apikey': xxxxxxxxxxxxxxxxx,
              'Authorization': ${access_token},
              'Content-Type': application/json
            }
            tests:
              - name: credencial status code = 200
                assert: ${{ response.status_code == 200 }}


@camilamaia
Copy link
Member Author

@BrunoPontesLira not yet. There is a PR opened for it, but we did not merge it: #328. We need to test it first and ensure it works properly.

@camilamaia camilamaia removed the Hacktoberfest http://hacktoberfest.digitalocean.com/ label Jul 30, 2021
@camilamaia
Copy link
Member Author

Actually, the PR #328 does not solve it, my bad. It only makes it possible to create vars at endpoint level. This is still an open issue

@gabrieltron
Copy link
Member

I'd like to work on this issue, but since it's a non-simple change I'd like to discuss if you already have an intended approach to solve this problem. I was reading through the yaml specification and it says keys don't have a specific order. Considering that, we couldn't just run request nodes without ordering them. The way I'm thinking to approach the issue is building a dependency graph of request nodes, and we execute nodes without dependencies or with solved dependencies.

What are your thoughts?

@gabrieltron gabrieltron linked a pull request Sep 12, 2021 that will close this issue
8 tasks
@gabrieltron
Copy link
Member

Ok, I admit that the first suggestion was the first thought without deeply studying the code hahaha
After doing that, I have a suggestion that I believe better fits with the tree-like structure, and it is much simpler. Looking forward for your feedback :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature or request
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

4 participants