usebruno / bruno

Opensource IDE For Exploring and Testing Api's (lightweight alternative to postman/insomnia)
https://www.usebruno.com/
MIT License
25.83k stars 1.18k forks source link

Global Environments #115

Open sanbhattdeep opened 1 year ago

sanbhattdeep commented 1 year ago

Environment object should be a separate entity by itself and not be stored inside a collection. Currently we are not able to share environments across collections due to this

helloanoop commented 1 year ago

Hi @sanbhattdeep

This is actually by design.

In the postman world, Workspaces are the first class citizen, Collections and Environments are under workspaces. This paradigm has been the defacto way of thinking for a decade, and every other alternative (Insomnia, Hoppscotch etc) start with the same paradigm.

With Bruno, we see collections as a first class citizen. Everything related to a collection resides inside the collection including env variables. If you have a payment service, you would save your bruno collections inside a collection folder like below.

payments-api
  |-- src
  |-- collection
       |--environments
           |-- prod.bru
           |-- stg.bru
       |--get payments.bru
       |--create payment.bru

If you are not storing bruno collections inside a repo, but you are using a separate git repo to store collections, that is also fine.

I have two questions

  1. Are you exploring bruno for personal use or are you using bruno in a project with some team members?
  2. Other than urls, what kind of variables are you storing in environments ?
sanbhattdeep commented 1 year ago
  1. Am currently exploring bruno for personal use and may recommend for official use in project later
  2. Am storing mostly urls in environments, since the urls will be same across multiple services say payment, order etc.. for running multiple collections in same environment say test i need to duplicate the environment across each collection
helloanoop commented 1 year ago

Nice!

One way to quickly clone environments is to copy the environments folder of your previous collection to the new collection.

You can copy folder using file explorer or do it via vscode by open collections inside vscode.

At this point, i don't think we may support global environments, as we see collection as the first class citizen, and everything related to collection (envs, vars, tests, scripts) resides inside the collection

helloanoop commented 1 year ago

One of the options I am thinking is to support a flow in the UI for importing environments environments from any other collections.

victor-marino commented 1 year ago

Hi!

Sorry to bump such an old issue, but I just came across Bruno (which I love, by the way) and stumbled upon this issue after importing my second collection.

I get what you say about seeing collections as the first-class entity here. But in the end, that is highly dependent on the specific projects you're working on.

For instance, in my case, things look more like this:

project-root
  |-- dev-env
       |--api-1
           |-- GET
           |-- PUT
           |-- DELETE
       |--api-2
           |-- GET
           |-- PUT
           |-- DELETE
       |--api-3
           |-- GET
           |-- PUT
           |-- DELETE
  |-- staging-env
       |--api-1
           |-- GET
           |-- PUT
           |-- DELETE
       |--api-2
           |-- GET
           |-- PUT
           |-- DELETE
       |--api-3
           |-- GET
           |-- PUT
           |-- DELETE
  |-- production-env
       |--api-1
           |-- GET
           |-- PUT
           |-- DELETE
       |--api-2
           |-- GET
           |-- PUT
           |-- DELETE
       |--api-3
           |-- GET
           |-- PUT
           |-- DELETE

So all APIs share a common ancestor - the current environment. That means they ALL have the same base URL, same OAuth2 endpoint, same client credentials and tokens for OAuth2, etc. etc.

I only listed 3 APIs here, but we actually have dozens of them. So the main benefit I get out of using environments in other clients (Postman, Insomnia, etc.) is for different collections to share the same env variables, and being able to switch between environments with a single click.

If my understanding is correct, the only way to do this in Bruno would be to create a single, huge collection for our whole project, and nest all our APIs inside it by creating a folder for each of them. But then, that would require having folder-level variables as well, so we can reuse variables across different methods (e.g.: same API endpoint).

Ultimately, I think this is the reason why most popular clients have structured things that way. Otherwise you're very limited when it comes to automation, and you have to repeat variables in lots of places.

Just my 2 cents, in case it makes you reconsider the feature! ;-)

helloanoop commented 1 year ago

@victor-marino Definitely considering to support Global Environments at the app level.

I'd like to understand your structure a bit more.

payment-service
  |-- dev-env
       |--payment-config
           |-- GET
           |-- PUT
           |-- DELETE\
  |-- staging-env
       |--payment-config
           |-- GET
           |-- PUT
           |-- DEL

Can you elaborate why your structure duplicates the payment config requests. Is it because the data that is being used while you test each environment is different ?

If my understanding is correct, the only way to do this in Bruno would be to create a single, huge collection for our whole project, and nest all our APIs inside it by creating a folder for each of them.

Can you talk about the project a bit more (if it is possible)? If you are coming from the insomnia/postman world how were you collaborating with teams? - paid plan OR write it to a folder and share via git or google drive (etc)

Also, in your directory structure - you have project-root. Is this a directory where all your collections were saved ?

Hope you don't mind sharing some more details. It'll help me come up with a solution that is comprehensive.

victor-marino commented 1 year ago

Sure, happy to elaborate!

Maybe my diagram above was a bit confusing, as I was trying to show the env dependencies, not how I actually structure my collections in Postman.

At my job, we develop multiple APIs that we expose in a common platform for customers to use. As a result, the structure of all our APIs is something like:

Dev env:
https://dev.our-platform.com/api1-path/
https://dev.our-platform.com/api2-path/
...
Staging env:
https://stg.our-platform.com/api1-path/
https://stg.our-platform.com/api2-path/
...
Prod env:
https://our-platform.com/api1-path/
https://our-platform.com/api2-path/

That means all our APIs share the same base path, OAuth2 path, credentials, etc. per environment.

So in Postman I just have one collection per API, like this:

Workspace-1
   |--api-1
       |-- GET
       |-- PUT
       |-- DELETE
   |--api-2
       |-- GET
       |-- PUT
       |-- DEL
   ...

In each collection, the base path, OAuth path, credentials, etc. are all configured as env variables. And because environments are shared across collections, I only have to set them (and maintain them) once, and not once per API.

If you are coming from the insomnia/postman world how were you collaborating with teams? - paid plan OR write it to a folder and share via git or google drive (etc)

No, I've never used any sharing or paid features. We typically test these things individually, which means each of us may have their own workflow. However, I'm aware most devs at my workplace use the same kind of structure that I use when it comes to collections and environments, which makes sense given our platform structure.

When somebody needs a collection for one of our APIs, we'll will typically export it in Postman (json) format and just send it over teams/email/etc.

Also, in your directory structure - you have project-root. Is this a directory where all your collections were saved ?

No sorry, I was just referring to the structure of our platform (with a root base path for the root domain of our APIs). Sorry for the confusion.

In the end, the key point here is that typically:

As a result, we need the ability for multiple collections to share the same environments, which is typically achieved by grouping them in workspaces in other apps. Otherwise we'd need to duplicate all our environments inside each collection, which would defeat their purpose altogether.

Hope that's a bit clearer.

AlanSandovalDev commented 11 months ago

@helloanoop We have the same scenario. We are migrating from Postman but we are facing this limitation: there is no global environments 😔 Here I explain our case: https://github.com/usebruno/bruno/discussions/883

We hope you can consider global environments. It's the only thing Bruno is missing.

helloanoop commented 11 months ago

@AlanSandovalDev Will definitely support this as soon as we can.

David-Lannion commented 10 months ago

This issue seems quite related with #292

edbrannin commented 10 months ago

Hi @victor-marino, I'm just some rando, trying to understand your use-case better...

Can you elaborate why your structure duplicates the payment config requests. Is it because the data that is being used while you test each environment is different ?

I think @helloanoop was asking why your structure was using folders to separate environments, instead of something like this:

- Collection: our-platform.com
  - Folder: api-1
    - Request: GET
    - Request: PUT
    - Request: DELETE
  - Folder: api-2
    - Request: GET
    - Request: PUT
    - Request: DELETE
  - Folder: api-3
    - Request: GET
    - Request: PUT
    - Request: DELETE

...with the differences between Dev, Staging, Prod environments being... environments:

Dev env:
BASE_URL=https://dev.our-platform.com

Staging env:
BASE_URL=https://stg.our-platform.com

Prod env:
BASE_URL=https://our-platform.com

So the api-1/GET request would have a URL like {{BASE_URL}}/api-1/, etc.

thjaeckle commented 9 months ago

Hi there. Thanks a lot for creating bruno - I already love it.

While migrating postman collections and environments to bruno I stumbled across the "shared / global environments" topic.
However, I overcame this by the elegance of bruno, that collections are folders and the environments of a collection is also contained within a folder.

Simply create one directory which holds the environment files and use softlinks for the "environment" directories of the collections, pointing to that shared environment directory.

My folder structure is:

.
├── connectivity-service
│   ├── Test Connection.bru
│   ├── bruno.json
│   └── environments -> ../shared-environments
├── ditto
│   ├── Who am I-.bru
│   ├── bruno.json
│   └── environments -> ../shared-environments
├── exploration
│   ├── Search via POST.bru
│   ├── bruno.json
│   ├── collection.bru
│   └── environments -> ../shared-environments
├── shared-environments
│   ├── dev.bru
│   ├── prod.bru
│   ├── qa.bru
│   └── IDEA.bru
└── wot
    ├── Get Thing.bru
    ├── bruno.json
    └── environments -> ../shared-environments

When I create a new bruno collection, I simply create the softlink to the shared-environments:

cd wot
ln -s ../shared-environments environments

This softlink can even be committed to a Git repository - and at least on UNIX systems works out of the box.

With that, I am able to use "shared environments" across all my collections.

Jzerbib69 commented 7 months ago

Hi, i tried to do the same things than @thjaeckle, but i keep the error : EISDIR: illegal operation on a directory, lstat

image image

Have you an idea, i execute the command : ln -s ../global-environnements environments in the directory Evenement

ldng commented 7 months ago

I having the same problem. To stay true to your manifesto this need can be framed differently. More than a global Environment, the issue is more not to be able to have a Shared Environment.

When you have a micro-service architecture, I want to have collection for each of my services, but I also want be able to run authentication collection once, set my TOKEN in a Shared Environment, and just have those other collections reuse that TOKEN.

I hope it give more insights or another light to the problem. Great work on Bruno BTW.

dj-fiorex commented 6 months ago

Hi there. Thanks a lot for creating bruno - I already love it.

While migrating postman collections and environments to bruno I stumbled across the "shared / global environments" topic. However, I overcame this by the elegance of bruno, that collections are folders and the environments of a collection is also contained within a folder.

Simply create one directory which holds the environment files and use softlinks for the "environment" directories of the collections, pointing to that shared environment directory.

My folder structure is:

.
├── connectivity-service
│   ├── Test Connection.bru
│   ├── bruno.json
│   └── environments -> ../shared-environments
├── ditto
│   ├── Who am I-.bru
│   ├── bruno.json
│   └── environments -> ../shared-environments
├── exploration
│   ├── Search via POST.bru
│   ├── bruno.json
│   ├── collection.bru
│   └── environments -> ../shared-environments
├── shared-environments
│   ├── dev.bru
│   ├── prod.bru
│   ├── qa.bru
│   └── IDEA.bru
└── wot
    ├── Get Thing.bru
    ├── bruno.json
    └── environments -> ../shared-environments

When I create a new bruno collection, I simply create the softlink to the shared-environments:

cd wot
ln -s ../shared-environments environments

This softlink can even be committed to a Git repository - and at least on UNIX systems works out of the box.

With that, I am able to use "shared environments" across all my collections.

Does this method still work? does it also work on mac? Because i just tried, and Bruno didn't see anything in the enviroments. This is the command and the output

Tests % mkdir environments
Tests % ln -s ../SharedEnv environments
Tests % ls environments 
SharedEnv
Tests % ls -l environments 
total 0
lrwxr-xr-x  1 carmelofiorello  staff  12 Apr  3 19:48 SharedEnv -> ../SharedEnv

Thanks!

EDIT tried also via UI image but nothing, and i can't create an environment through the UI with an error

SakshiSharmaz commented 5 months ago

its a little hacky but, we can also just add all our collections into one directory ( as sub directories ), the one that has the environments. and then all the api's in sub directory will be able to use the environment in parent directory which is the main collection

image

end3rbyte commented 5 months ago

This is a long running story... I agree with the big amount of users that we are missing global environments, and it is a big limitation compared to postman for example. In our case we have plenty of microservices hosted in the same host, and we need to duplicate the environment variables and secrets for this host into each microservice test collection. Or there is the hacky trick with the symlink but that is not nice.

acuenca-facephi commented 5 months ago

I agree too, Bruno is awesome but I think it must have global and collection editable variables such us environment variables.

In my case, to use collection vars I have to setup pre-request vars, also these variables can not be secrets, so I have to use .env files or delete/ignore them to commit the collection to a repository.

iucn-applications commented 4 months ago

+1

phen0menon commented 3 months ago

Only one thing stopping me from migrating to Bruno - global variables absence :(

jfraullodra commented 3 months ago

I agree, I generally use one collection per api, but I can have several api on the same environment. In my case one oauth2 server and api servers. it's a pain to have to copy every environment.

jkblume commented 1 month ago

Same for me, this is a really important feature to completely migrate to bruno :) What es even more important is, that there is a possibility to do something like setGlobalEnv(...) for getting auth tokens in one collection and use this token in other collections that belong to own microservices (and therefore own repositories). What i will try to avoid is sharing this temp auth variables over an environment, what e.g. results maybe in changes on file system and therefore in git changes.

jkblume commented 1 month ago

The more i think about it, i come to the point that global variables and global environments are two separate things. This ticket https://github.com/usebruno/bruno/issues/1509 was closed as duplicate, but maybe it is just another feature and maybe global variables are easier to solve, because they life not on file system but more a like in memory of the bruno runtime :)

sguerreroRGA commented 1 month ago

We are trying to migrate from Postman to Bruno. Are global variables still not supported?

kapvas commented 3 weeks ago

Global variables are very crucial for our workflow. Like we take Auth Token which are common for many collections BUT i unnecessarily have to create duplicates which creates redundancy and not practical to manage 50+ collection in my case.

Can we please have global variables.

As bruno consider collection as first class citizen, multiple tabs are not not working when we switch between collection.

MisterJD commented 3 weeks ago

We are currently considering migrating from Postman to Bruno in the company. Even though we find the approach of having enviornments at collection level very elegant in some cases, it would sometimes be better if there were also global ones. It would be good if, for example, you could simply select between global and local enviornments in the dropdown.