terminus icon indicating copy to clipboard operation
terminus copied to clipboard

environment variables aren't properly expanding to override nested configuration options

Open ataylorme opened this issue 4 years ago • 16 comments

In theory, dots and dashes should be equivalent -- $this->session()->getConfig()->get('TERMINUS_BUILD-TOOLS_COMPOSER-AUTH') should be equivalent to $this->session()->getConfig()->get('terminus.build-tools.composer-auth') (with the latter being what you need to do to refer to things in your config.yml.

ataylorme avatar Oct 01 '19 16:10 ataylorme

I'm going to debug this a bit, unless it's already a known issue?

danielbachhuber avatar Oct 01 '19 16:10 danielbachhuber

@danielbachhuber from a chat with @TeslaDethray it seems that the dot notation we are using in https://github.com/pantheon-systems/terminus-build-tools-plugin/issues/275 is incorrect.

We should be using build-tools_composer-auth instead of terminus.build-tools.composer-auth

Hyphens are allowed but not preferred as well.

Let's try updating https://github.com/pantheon-systems/terminus-build-tools-plugin/issues/275 to use build-tools_composer_auth with TERMINUS_BUILD-TOOLS_COMPOSER_AUTH and see if that works.

If not, we can continue to debug here

ataylorme avatar Oct 01 '19 16:10 ataylorme

That doesn't look correct to me. You should be using dots to access config. The underscores might work accidentally with environment variables, but you should be using dot-separated terms for config.

terminus.build-tools.composer-authaddresses:

terminus:
  build-tools:
   composer-auth: xyzzy

greg-1-anderson avatar Oct 01 '19 17:10 greg-1-anderson

I did a bit of testing and here's what I found....

Scenario 1

Given a ~/.terminus/config.yml file with:

build-tools:
  composer-auth: '{ "http-basic": { "privatepackage.com": { "username": "[email protected]", "password": "abc123" } } }'

The configuration value is accessible in Terminus Build Tools with:

$this->session()->getConfig()->get('build-tools.composer-auth');

Scenario 2

Given a TERMINUS_BUILDTOOLS_COMPOSERAUTH environment variable with:

'{ "http-basic": { "privatepackage.com": { "username": "[email protected]", "password": "abc123" } } }'

The configuration value is accessible in Terminus Build Tools with:

$this->session()->getConfig()->get('buildtools_composerauth');

However, it's not possible to set a TERMINUS_BUILD-TOOLS_COMPOSER-AUTH environment variable because shells don't support dashes in environment variables. It also doesn't seem to be possible to set an environment variable equivalent to a nested config value — e.g. TERMINUS_BUILDTOOLS_COMPOSERAUTH is equivalent to:

buildtools_composerauth: '{ "http-basic": { "privatepackage.com": { "username": "[email protected]", "password": "abc123" } } }'

@greg-1-anderson Anything I'm missing?

danielbachhuber avatar Oct 08 '19 15:10 danielbachhuber

@TeslaDethray options is a Terminus core configuration key that has nested values. Users not being able to override the option values with TERMINUS_OPTIONS seems like a bug.

ataylorme avatar Oct 08 '19 15:10 ataylorme

I have not looked up what options Terminus Build tools itself defines, but you should be using that as your exemplar. @danielbachhuber's scenario 1 example is in the right form.

greg-1-anderson avatar Oct 08 '19 15:10 greg-1-anderson

terminus self:config:dump shows:

-
  key: options
  env: TERMINUS_OPTIONS
  value:
    decorated: true
    interactive: true
    progress-delay: 2
    simulate: false
    help: false
    quiet: false
    verbose: false
    version: false
    ansi: false
    no-ansi: false
    no-interaction: false
    'yes': false
  source: Default

It also doesn't seem to be possible to set an environment variable equivalent to a nested config value

This is the main issue. With scenario 1 above (nested config), an environment variable cannot be set to set or override the value.

ataylorme avatar Oct 08 '19 15:10 ataylorme

Nested config has definitely worked in the past. I don't see why it would have stopped working.

greg-1-anderson avatar Oct 08 '19 16:10 greg-1-anderson

Build tools documents some configuration options; it does not document environment variable equivalence. We're also missing documentation on environment variable overrides in the consolidation/config README.

Terminus self:config:dump does not understand consolidation/config configuration.

greg-1-anderson avatar Oct 08 '19 16:10 greg-1-anderson

Nested config has definitely worked in the past. I don't see why it would have stopped working.

Nested config, or nested config with environment variable equivalence?

danielbachhuber avatar Oct 08 '19 16:10 danielbachhuber

Environment variable overrides for config is implemented here.

For Terminus, the prefix is TERMINUS, so if there was config:

terminus:
  foo:
   bar:value

That would map to TERMINUS_FOO_BAR rather than TERMINUS_TERMINUS_FOO_BAR (because of the second line). Dots and hyphens are converted to underscores.

greg-1-anderson avatar Oct 08 '19 17:10 greg-1-anderson

@greg-1-anderson It looks like Terminus's EnvConfig extends TerminusConfig:

https://github.com/pantheon-systems/terminus/blob/7a337955a512d94480b2227cb1b7b7fbc7cc028d/src/Config/EnvConfig.php#L9

TerminusConfig doesn't make any reference to Consolidation\Config\Util\EnvConfig:

https://github.com/pantheon-systems/terminus/blob/b953f0d469ece2b4d4fbd525a3ad01d8ad613021/src/Config/TerminusConfig.php#L9

Maybe that's the issue?

danielbachhuber avatar Oct 08 '19 18:10 danielbachhuber

The problem may in fact be in the memory of the commenter (moi)

greg-1-anderson avatar Oct 08 '19 18:10 greg-1-anderson

@greg-1-anderson Ok, no worries.

@ataylorme In the interest of simplicity for https://github.com/pantheon-systems/terminus-build-tools-plugin/issues/275, how about we support:

build-tools:
  composer-auth: '{ "http-basic": { "privatepackage.com": { "username": "[email protected]", "password": "abc123" } } }'

And:

export TERMINUS_BUILD_TOOLS_COMPOSER_AUTH='{ "http-basic": { "privatepackage.com": { "username": "[email protected]", "password": "abc123" } } }'

danielbachhuber avatar Oct 08 '19 18:10 danielbachhuber

@danielbachhuber that works for me. If there isn't an easy fix here we can continue to check for both the config and environment variables in Build Tools

ataylorme avatar Oct 08 '19 18:10 ataylorme

@ataylorme Should we close this issue as wontfix?

danielbachhuber avatar Oct 08 '19 23:10 danielbachhuber