Skip to content

Feat: Environment variables in templating #849

@Meldiron

Description

@Meldiron

I find Mockoon CLI useful for testing purposes in CI/CD environments. In my use case, I am spinning up multiple Mockoon instances running in a Docker container. Even tho I want them to source from the same config file, I would prefer having the option to identify instances.

As a solution to this, I would like to add a new set of helpers that would allow you to read environment variables. Implementation might look something like this:

{ "server": "{{env 'Variable-Name' 'default value'}}" }

To keep the solution secure, this would only allow reading variables that are prefixed with MOCKOON_. There should be an option (CLI parameter?) to change this prefix. Setting prefix to empty string and allowing reading any variable should NOT be allowed.

Source of security concerns and solutions is Vite.

TODO:

  • Discuss implementation with maintainers
  • Add System Helpers
  • Implement environment variable system helper
  • Write tests (if applicable)
  • Update docs

If possible, I would like to contribute to this issue.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

Done (merged, ready for next release)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions