Skip to content

Commit 23ff608

Browse files
Merge pull request #204 from hdresearch/ty/fix-dotenv-credential-shadowing
fix(root): stop loading .env at runtime (silent credential shadow)
2 parents 8010630 + d674fef commit 23ff608

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

cmd/root.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
runrt "github.com/hdresearch/vers-cli/internal/runtime"
1717
"github.com/hdresearch/vers-cli/internal/update"
1818
vers "github.com/hdresearch/vers-sdk-go"
19-
"github.com/joho/godotenv"
2019
"github.com/spf13/cobra"
2120
)
2221

@@ -196,8 +195,15 @@ interaction capabilities, and more.`,
196195
return nil
197196
}
198197

199-
// Load .env for the VERS_URL
200-
godotenv.Load()
198+
// NOTE: previously this called godotenv.Load() to pick up VERS_URL
199+
// from a local .env for dev convenience. That had the side effect of
200+
// silently shadowing the user's ~/.versrc credentials with a stale
201+
// VERS_API_KEY whenever the user happened to be in a directory
202+
// containing a .env file — with no warning about which credential
203+
// source won. We now only honor the real environment and ~/.versrc.
204+
// Devs who want .env-style loading can use direnv or `export $(cat
205+
// .env | xargs)`. Tests load their own .env explicitly via
206+
// test/testutil/helpers.go.
201207

202208
// Initialize the client with API key if available
203209
apiKey, err := auth.GetAPIKey()

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ require (
2424
require (
2525
github.com/hdresearch/vers-sdk-go v0.1.0-alpha.32
2626
github.com/inconshreveable/mousetrap v1.1.0 // indirect
27-
github.com/spf13/pflag v1.0.6 // indirect
27+
github.com/spf13/pflag v1.0.6
2828
github.com/tidwall/gjson v1.18.0 // indirect
2929
github.com/tidwall/match v1.2.0 // indirect
3030
github.com/tidwall/pretty v1.2.1 // indirect

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
77
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
88
github.com/google/jsonschema-go v0.2.3 h1:dkP3B96OtZKKFvdrUSaDkL+YDx8Uw9uC4Y+eukpCnmM=
99
github.com/google/jsonschema-go v0.2.3/go.mod h1:r5quNTdLOYEz95Ru18zA0ydNbBuYoo9tgaYcxEYhJVE=
10-
github.com/hdresearch/vers-sdk-go v0.1.0-alpha.31 h1:JXEU1lXHzfIpi5Aq5LQjtdSnZDGTqqTZK4TcbAJTfcQ=
11-
github.com/hdresearch/vers-sdk-go v0.1.0-alpha.31/go.mod h1:aJoQGYzJHXdbj7uhCekUZaxbMu+XhVMOCtVQEdA0NFI=
1210
github.com/hdresearch/vers-sdk-go v0.1.0-alpha.32 h1:b1+KSJbLQgsC9KEnoQxrbHq/sxtHDM/cB1+XwHMYOBs=
1311
github.com/hdresearch/vers-sdk-go v0.1.0-alpha.32/go.mod h1:aJoQGYzJHXdbj7uhCekUZaxbMu+XhVMOCtVQEdA0NFI=
1412
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=

0 commit comments

Comments
 (0)