AnWeber / vscode-httpyac

Quickly and easily send REST, Soap, GraphQL, GRPC, MQTT and WebSocket requests directly within Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=anweber.vscode-httpyac
MIT License
237 stars 20 forks source link

Switching Environments deletes global variables #158

Closed hffmnn closed 1 year ago

hffmnn commented 1 year ago

When switching an environment it looks like the global variables are deleted, which I think makes sense in general. Still, I think there are valid use cases that this shouldn't be the case.

My use case:

When developing an API, that needs a valid authentication token, locally, all the endpoint URLs are set to some localhost URLs. But to get an token, I have to switch the environment to some deployed version of the auth API and then switch back to the localhost environment. After the switch, it looks like the token gets reset.

The only workaround I come up with was to add the needed auth URL as part of the localhost environment, but when having a lot of staging/dev/production environments, this gets annoying.

Does that make sense?

AnWeber commented 1 year ago

@hffmnn When switching environments all variables are deleted. I use environments to separate customers and I wanted to prevent leaked data. Since I can't tell which environment a newly created variable belongs to, I simply delete them all

You should choose a setup where a environment change is not needed. This will allow also the use of httpyac CLI to run automated tests and easier use of vscode-httpyac, because using @ref is possible.. A solution would be to share the Auth URL in a separated Environment. My setup is as follows using dotenv Files

.env

authHost=https://keycloak.{{profile}}.int.de/auth/token

local.env

profile=dev
host=http://localhost:8080

prod.env

profile=prod
host=http://httpyac.github.io

token.http


# @name login
POST {{authUrl}}

username=...&password=...

> request.http
```http
# @import ./token.http
# @ref login
GET /service/data
Authorization: Bearer {{login.access_token}}
hffmnn commented 1 year ago

Thanks for the info.

I will look into updating my local workflow to change the profile variable instead of switching environments then.

AnWeber commented 1 year ago

🙏 thx.