bruno icon indicating copy to clipboard operation
bruno copied to clipboard

Missing Insomnia Environment Import

Open cmcconomyfwig opened this issue 11 months ago • 0 comments

The Insomnia environment format is incredibly simple -- just a top level json key/value set.

I wrote this python script in case it helps anyone else:

from pathlib import Path
import json

# expects contents to be,
#  { 'envname': {k:v, k2:v2}} etc.
envs = json.loads(Path('./insomnia_envs.json').read_text())

for env, values in envs.items():
    this_env = {
        "name": env,
        "values": [
            {
                "key": key,
                "value": value,
                "type" : "secret" if "secret" in key or "key" in key else "default",
                "enabled": True
            } for (key, value) in values.items()
        ]
    }
    Path(f'./postman.env.{env}.json').write_text(json.dumps(this_env, indent=2))
    print(f"Wrote ./postman.env.{env}.json")

Constructing the required ./insomnia_envs.json is simple; it should look as follows:

{
"env1": {
  "key1": "env1_val1",
  "key2": "env1_val2"
}, 
"env2": {
  "key1": "env2_val1",
  "key2": "env2_val2"
}
}

etc.

Hope this helps!

What I would suggest is a capability in Bruno to open up a textbox and just paste in a k/v json as an environment.

cmcconomyfwig avatar Mar 12 '24 02:03 cmcconomyfwig