Skip to content

Commit 99ca261

Browse files
committed
[BREAKING] Custom Env options moved from GOPASS_CONFIG_CONFIG_KEY_i to GOPASS_CONFIG_KEY_i
As discussed in #2617, this actually reflects the way GIT_CONFIG works Signed-off-by: Yolan Romailler <[email protected]>
1 parent 020046d commit 99ca261

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

docs/config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ different configuration sources that take precedence over each other, just like
7272
* User-wide (aka. global) configuration allows to set per-user settings. This is the closest equivalent to the old gopass configs. Located in `$HOME/.config/gopass/config`
7373
* Per-store (aka. local) configuration allow to set per-store settings, e.g. read-only. Located in `<STORE_DIR>/config`.
7474
* Per-store unversioned (aka `config.worktree`) configuration allows to override versioned per-store settings, e.g. disabling read-only. Located in `<STORE_DIR>/config.worktree`
75-
* Environment variables (or command line flags) override all other values. Read from `GOPASS_CONFIG_CONFIG_KEY_n` and `GOPASS_CONFIG_CONFIG_VALUE_n` up to `GOPASS_CONFIG_CONFIG_COUNT`. Command line flags take precedence over environment variables.
75+
* Environment variables (or command line flags) override all other values. Read from `GOPASS_CONFIG_KEY_n` and `GOPASS_CONFIG_VALUE_n` up to `GOPASS_CONFIG_COUNT`. Command line flags take precedence over environment variables.
7676

7777
### Configuration options
7878

internal/config/config_test.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ func TestConfig(t *testing.T) {
4444

4545
func TestEnvConfig(t *testing.T) {
4646
envs := map[string]string{
47-
"GOPASS_CONFIG_CONFIG_COUNT": "2",
48-
"GOPASS_CONFIG_CONFIG_KEY_0": "core.autosync",
49-
"GOPASS_CONFIG_CONFIG_VALUE_0": "false",
50-
"GOPASS_CONFIG_CONFIG_KEY_1": "show.safecontent",
51-
"GOPASS_CONFIG_CONFIG_VALUE_1": "true",
47+
"GOPASS_CONFIG_COUNT": "2",
48+
"GOPASS_CONFIG_KEY_0": "core.autosync",
49+
"GOPASS_CONFIG_VALUE_0": "false",
50+
"GOPASS_CONFIG_KEY_1": "show.safecontent",
51+
"GOPASS_CONFIG_VALUE_1": "true",
5252
}
5353
for k, v := range envs {
5454
t.Setenv(k, v)
@@ -73,6 +73,10 @@ func TestInvalidEnvConfig(t *testing.T) {
7373
"GOPASS_CONFIG__CONFIG_COUNT": "1",
7474
"GOPASS_CONFIG__CONFIG_KEY_0": "core.autosync",
7575
"GOPASS_CONFIG__CONFIG_VALUE_0": "false",
76+
// old format
77+
"GOPASS_CONFIG_CONFIG_COUNT": "1",
78+
"GOPASS_CONFIG_CONFIG_KEY_0": "core.autosync",
79+
"GOPASS_CONFIG_CONFIG_VALUE_0": "false",
7680
}
7781
for k, v := range envs {
7882
t.Setenv(k, v)
@@ -171,10 +175,10 @@ func TestOptsMigration(t *testing.T) {
171175

172176
t.Run("env variable are not migrated", func(t *testing.T) {
173177
envs := map[string]string{
174-
"GOPASS_CONFIG_CONFIG_COUNT": "1",
175-
"GOPASS_CONFIG_CONFIG_KEY_0": "core.showsafecontent",
176-
"GOPASS_CONFIG_CONFIG_VALUE_0": "true",
177-
"GOPASS_CONFIG_NO_MIGRATE": "",
178+
"GOPASS_CONFIG_COUNT": "1",
179+
"GOPASS_CONFIG_KEY_0": "core.showsafecontent",
180+
"GOPASS_CONFIG_VALUE_0": "true",
181+
"GOPASS_CONFIG_NO_MIGRATE": "",
178182
}
179183
for k, v := range envs {
180184
t.Setenv(k, v)

pkg/gitconfig/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ func LoadConfig(fn string) (*Config, error) {
368368
}
369369

370370
// ParseConfig will try to parse a gitconfig from the given io.Reader. It never fails.
371-
// Invalid configs will be silently rejceted.
371+
// Invalid configs will be silently rejected.
372372
func ParseConfig(r io.Reader) *Config {
373373
c := &Config{
374374
vars: make(map[string][]string, 42),
@@ -396,7 +396,7 @@ func LoadConfigFromEnv(envPrefix string) *Config {
396396
noWrites: true,
397397
}
398398

399-
count, err := strconv.Atoi(os.Getenv(envPrefix + "_CONFIG_COUNT"))
399+
count, err := strconv.Atoi(os.Getenv(envPrefix + "_COUNT"))
400400
if err != nil || count < 1 {
401401
return &Config{
402402
noWrites: true,
@@ -406,10 +406,10 @@ func LoadConfigFromEnv(envPrefix string) *Config {
406406
c.vars = make(map[string][]string, count)
407407

408408
for i := 0; i < count; i++ {
409-
keyVar := fmt.Sprintf("%s%d", envPrefix+"_CONFIG_KEY_", i)
409+
keyVar := fmt.Sprintf("%s%d", envPrefix+"_KEY_", i)
410410
key := os.Getenv(keyVar)
411411

412-
valVar := fmt.Sprintf("%s%d", envPrefix+"_CONFIG_VALUE_", i)
412+
valVar := fmt.Sprintf("%s%d", envPrefix+"_VALUE_", i)
413413
value, found := os.LookupEnv(valVar)
414414

415415
if key == "" || !found {

pkg/gitconfig/config_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,11 @@ func TestLoadFromEnv(t *testing.T) {
279279

280280
i := 0
281281
for k, v := range tc {
282-
t.Setenv(fmt.Sprintf("%s_CONFIG_KEY_%d", prefix, i), k)
283-
t.Setenv(fmt.Sprintf("%s_CONFIG_VALUE_%d", prefix, i), v)
282+
t.Setenv(fmt.Sprintf("%s_KEY_%d", prefix, i), k)
283+
t.Setenv(fmt.Sprintf("%s_VALUE_%d", prefix, i), v)
284284
i++
285285
}
286-
t.Setenv(fmt.Sprintf("%s_CONFIG_COUNT", prefix), strconv.Itoa(i))
286+
t.Setenv(fmt.Sprintf("%s_COUNT", prefix), strconv.Itoa(i))
287287

288288
cfg := LoadConfigFromEnv(prefix)
289289
for k, v := range tc {

0 commit comments

Comments
 (0)