Skip to content

Add JSON configuration support with environment variable interpolation#13

Merged
Yukaii merged 4 commits intomainfrom
copilot/fix-12
Jun 5, 2025
Merged

Add JSON configuration support with environment variable interpolation#13
Yukaii merged 4 commits intomainfrom
copilot/fix-12

Conversation

Copy link
Contributor

Copilot AI commented Jun 5, 2025

This PR adds support for JSON-based configuration files in addition to the existing environment variable approach, addressing the need for more flexible configuration management.

Features Added

JSON Configuration Files

  • Supports configuration files in multiple locations:
    • ./tailportal.json (current directory)
    • ./.tailportal.json (current directory, hidden)
    • ~/.tailportal.json (home directory)

Environment Variable Interpolation

  • JSON configuration supports $ENV_VAR_NAME syntax for environment variable interpolation
  • Example configuration:
{
  "tsAuthKey": "$TS_AUTH_KEY",
  "pulumiPassphrase": "$PULUMI_CONFIG_PASSPHRASE",
  "vultrApiKey": "$VULTR_API_KEY",
  "googleProject": "my-project",
  "googleCredentials": "$GOOGLE_CREDENTIALS"
}

Backward Compatibility

  • Maintains full backward compatibility with existing environment variable approach
  • JSON configuration takes precedence over environment variables when both are present
  • Invalid JSON files gracefully fall back to environment variables with warning messages

Implementation Details

  • Added src/config.ts module with centralized configuration loading logic
  • Refactored index.ts to eliminate code duplication across all command actions
  • Reduced lines of code while adding functionality (54 lines removed, 6 lines added in main file)
  • All existing tests continue to pass without modification

Usage Examples

Environment Variables (existing approach):

export TS_AUTH_KEY=your_key
export PULUMI_CONFIG_PASSPHRASE=your_passphrase
tailportal create vultr ewr

JSON Configuration:

echo '{"tsAuthKey": "your_key", "pulumiPassphrase": "your_passphrase"}' > tailportal.json
tailportal create vultr ewr

Mixed approach with interpolation:

export VULTR_API_KEY=secret_key
echo '{"tsAuthKey": "direct_value", "vultrApiKey": "$VULTR_API_KEY"}' > tailportal.json
tailportal create vultr ewr

Fixes #12.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: Yukaii <4230968+Yukaii@users.noreply.github.com>
Copilot AI changed the title [WIP] Support json config Add JSON configuration support with environment variable interpolation Jun 5, 2025
Copilot AI requested a review from Yukaii June 5, 2025 14:14
Copilot finished work on behalf of Yukaii June 5, 2025 14:14
@Yukaii
Copy link
Owner

Yukaii commented Jun 5, 2025

@copilot Update the config under XDG_CONFIG_HOME/tailportal/config.json or ~/.config/tailportal/config.json then ~/.tailportal.json

Co-authored-by: Yukaii <4230968+Yukaii@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jun 5, 2025

@copilot Update the config under XDG_CONFIG_HOME/tailportal/config.json or ~/.config/tailportal/config.json then ~/.tailportal.json

Updated configuration paths to follow XDG Base Directory standards. The config now searches in order:

  1. $XDG_CONFIG_HOME/tailportal/config.json (if set)
  2. ~/.config/tailportal/config.json (fallback)
  3. ~/.tailportal.json (backward compatibility)

Documentation has been updated accordingly. Changes in commit 1f047ed.

Copilot finished work on behalf of Yukaii June 5, 2025 14:29
@Yukaii
Copy link
Owner

Yukaii commented Jun 5, 2025

@copilot COuld you also add some tests for it

Co-authored-by: Yukaii <4230968+Yukaii@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jun 5, 2025

@copilot COuld you also add some tests for it

Added comprehensive unit tests for the configuration functionality. The test suite includes 14 test cases covering:

  • Environment variable configuration loading and validation
  • JSON configuration files from all supported paths (XDG, ~/.config, ~/.tailportal.json)
  • Environment variable interpolation in JSON configs
  • Configuration precedence and merging
  • Error handling for invalid JSON files

All tests pass successfully. Commit 78c506e.

Copilot finished work on behalf of Yukaii June 5, 2025 16:10
@Yukaii Yukaii marked this pull request as ready for review June 5, 2025 16:23
@Yukaii Yukaii merged commit 6249b8d into main Jun 5, 2025
1 check passed
@Yukaii Yukaii deleted the copilot/fix-12 branch June 5, 2025 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support json config

2 participants