Skip to content

[Feature]: Support for Environment Variables in Request Files #3

@dinocodesx

Description

@dinocodesx

Describe the Feature You Are Requesting

Currently, Termino-Logistic requires users to hardcode API keys, authentication tokens, and other sensitive information directly within YAML/JSON request files. This approach has security risks and reduces flexibility when switching environments (development, staging, production).

💡 Proposed Feature:

  • Allow users to reference environment variables inside request files using ${VARIABLE_NAME} syntax.
  • Automatically replace placeholders with their corresponding values from the system environment.
  • Provide an option to load variables from a .env file for projects that store configurations locally.

📝 Example Usage:
request.yml

url: https://api.example.com/data
method: GET
headers:
  Authorization: "Bearer ${API_KEY}"
params:
  user_id: "${USER_ID}"

Command Execution:

# Run request with environment variables automatically resolved
export API_KEY="my-secret-key"
export USER_ID="12345"
termino -f request.yml

Why Is This Feature Needed?

  • Security Improvement: Prevents accidental exposure of sensitive credentials in version control.
  • Environment Flexibility: Users can switch between different API keys or settings without modifying files.
  • Ease of Use: Developers already use environment variables in other CLI tools (e.g., curl, Postman).

How to Implement

1️⃣ Modify the Request File Parser

  • Update the request file processing logic to scan for placeholders (${VAR_NAME}).
  • Extract corresponding values from system environment variables.
  • If a variable is undefined, handle it gracefully (error message or fallback value).

2️⃣ Support for .env File Loading

  • Check if a .env file exists in the project directory.
  • Automatically load variables from .env into the environment for resolution.
  • Ensure compatibility with common .env file formats used in Python projects.

3️⃣ Handling Missing or Undefined Variables

  • Provide clear warnings when a required environment variable is missing.
  • Optionally allow users to define default values in case an environment variable is not set.

4️⃣ Testing and Validation

  • Write test cases to verify environment variable resolution.
  • Ensure correct behavior when variables contain special characters or spaces.
  • Validate how the tool behaves if .env is missing or incorrectly formatted.

Additional Context

  • This feature aligns with best practices in secure API request handling.
  • Future enhancement: Support nested environment variables (e.g., ${BASE_URL}/users).
  • Works well with containerized environments (Docker, Kubernetes) where secrets are stored in environment variables.

Would love to get community feedback on this! Feel free to contribute. 🚀

Metadata

Metadata

Assignees

No one assigned

    Labels

    apertre2.0Issues and PRs created during Apertre EventenhancementNew feature or requestgood first issueGood for newcomersmediumA difficulty tag

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions