Skip to content

Commit ec71939

Browse files
authored
Merge pull request #272 from microsoft/stuartpa/only-set-sqlcmdpassword
Don't use SQLCMDPASSWORD env var if SQLCMDUSER env var not set
2 parents fe1f204 + 2871a81 commit ec71939

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

cmd/modern/main.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,20 @@ func initializeEnvVars() {
6262
if os.Getenv("SQLCMDSERVER") == "" {
6363
os.Setenv("SQLCMDSERVER", server)
6464
}
65-
if os.Getenv("SQLCMDUSER") == "" {
66-
os.Setenv("SQLCMDUSER", username)
67-
}
68-
if os.Getenv("SQLCMDPASSWORD") == "" {
69-
os.Setenv("SQLCMDPASSWORD", password)
65+
66+
// Username and password should come together, either from the environment
67+
// variables set by the user before the sqlcmd process started, or from the sqlconfig
68+
// for the current context, but if just the environment variable SQLCMDPASSWORD
69+
// is set before the process starts we do not use it, if the user and password is set in sqlconfig.
70+
if username != "" && password != "" { // If not trusted auth
71+
if os.Getenv("SQLCMDUSER") == "" {
72+
os.Setenv("SQLCMDUSER", username)
73+
os.Setenv("SQLCMDPASSWORD", password)
74+
}
7075
}
76+
7177
}
78+
7279
}
7380

7481
// isFirstArgModernCliSubCommand is TEMPORARY code, to be removed when

0 commit comments

Comments
 (0)