Skip to content

feat: support SWITCH_CONFIG_PATH env var for config file location#200

Open
posquit0 wants to merge 1 commit into
danielfoehrKn:masterfrom
posquit0:feat/support-switch-config-path-env
Open

feat: support SWITCH_CONFIG_PATH env var for config file location#200
posquit0 wants to merge 1 commit into
danielfoehrKn:masterfrom
posquit0:feat/support-switch-config-path-env

Conversation

@posquit0

Copy link
Copy Markdown
Contributor

What

Adds support for a SWITCH_CONFIG_PATH environment variable to specify the
location of the switch configuration file, as an alternative to the
--config-path flag.

A new getDefaultConfigPath() helper resolves the config path from
SWITCH_CONFIG_PATH (with $HOME/env expansion), falling back to the existing
default $HOME/.kube/switch-config.yaml when the variable is unset. It is wired
in as the default value of the --config-path flag across the root, context,
gardener controlplane, and hooks commands. The explicit --config-path flag
still takes precedence when provided, so behavior is fully backwards compatible.

Why

Closes #191.

This enables directory-based environment managers such as
direnv to select a per-directory kubeswitch
configuration without shell aliases or wrapper scripts — e.g. adding
export SWITCH_CONFIG_PATH=$PWD/switch-config.yaml to a directory's .envrc.

Testing

Built locally and verified the resolved --config-path default:

  • unset env → ~/.kube/switch-config.yaml (unchanged default)
  • SWITCH_CONFIG_PATH=/custom/path/my-switch.yaml → used as the default
  • SWITCH_CONFIG_PATH='$HOME/projectA/switch.yaml'$HOME expanded correctly

Docs updated in docs/kubeconfig_stores.md.

Security self-check

No new attack surface: the change only reads an environment variable the user
already controls and passes it through the existing os.ExpandEnv path used for
other paths. No command execution, SQL, or templating is involved. No
SQL-injection / XSS vectors apply to this CLI path-resolution change.

Add a getDefaultConfigPath() helper that resolves the switch config path
from the SWITCH_CONFIG_PATH environment variable, falling back to the
existing default of $HOME/.kube/switch-config.yaml when unset. Wire it in
as the default value of the --config-path flag across the root, context,
gardener and hooks commands.

This enables directory-based environment managers such as direnv to select
a per-directory kubeswitch configuration without shell aliases or wrapper
scripts. The --config-path flag still takes precedence when provided.

Closes danielfoehrKn#191
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 for  SWITCH_CONFIG_PATH  environment variable to specify config file location in kubeswitch

1 participant