Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions go/vt/dbconfigs/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ func GetCredentialsServer() CredentialsServer {
return cs
}

// SetDbCredentialsFilePath sets the value of the `--db-credentials-file` flag.
// This should be used only for testing.
func SetDbCredentialsFilePath(path string) {
dbCredentialsFile = path
}
Copy link

Copilot AI Aug 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function comment should specify what the dbCredentialsFile variable represents and mention that this modifies global state, which could affect other tests running concurrently.

Copilot uses AI. Check for mistakes.

// FileCredentialsServer is a simple implementation of CredentialsServer using
// a json file. Protected by mu.
type FileCredentialsServer struct {
Expand Down
7 changes: 6 additions & 1 deletion go/vt/vttablet/tabletserver/tabletenv/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,12 @@ func (c *TabletConfig) verifyUnmanagedTabletConfig() error {
return errors.New("database app user not specified")
}
if c.DB.App.Password == "" {
return errors.New("database app user password not specified")
_, pass, err := dbconfigs.GetCredentialsServer().GetUserAndPassword(c.DB.App.User)
if err == nil && pass != "" {
c.DB.App.Password = pass
} else {
return errors.New("database app user password not specified")
}
}
// Replication fixes should be disabled for Unmanaged tablets.
mysqlctl.DisableActiveReparents = true
Expand Down
8 changes: 8 additions & 0 deletions go/vt/vttablet/tabletserver/tabletenv/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,4 +484,12 @@ func TestVerifyUnmanagedTabletConfig(t *testing.T) {
config.DB.App.Password = "testPassword"
err = config.verifyUnmanagedTabletConfig()
assert.Nil(t, err)

dbconfigs.SetDbCredentialsFilePath("./data/db_credentials.json")
defer dbconfigs.SetDbCredentialsFilePath("")
config.DB.App.Password = ""

err = config.verifyUnmanagedTabletConfig()
assert.Nil(t, err)
assert.Equal(t, "testPassword", config.DB.App.Password)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"testUser": ["testPassword"]
}
Loading