Skip to content

Commit 2ab9ddd

Browse files
mhamza15frouioui
andauthored
Allow the use of db credentials when verifying unmanaged tablets config (vitessio#17984) (#190)
Signed-off-by: Florent Poinsard <[email protected]> Signed-off-by: Mohamed Hamza <[email protected]> Co-authored-by: Florent Poinsard <[email protected]>
1 parent b15fabe commit 2ab9ddd

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

go/vt/dbconfigs/credentials.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ func GetCredentialsServer() CredentialsServer {
133133
return cs
134134
}
135135

136+
// SetDbCredentialsFilePath sets the value of the `--db-credentials-file` flag.
137+
// This should be used only for testing.
138+
func SetDbCredentialsFilePath(path string) {
139+
dbCredentialsFile = path
140+
}
141+
136142
// FileCredentialsServer is a simple implementation of CredentialsServer using
137143
// a json file. Protected by mu.
138144
type FileCredentialsServer struct {

go/vt/vttablet/tabletserver/tabletenv/config.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,12 @@ func (c *TabletConfig) verifyUnmanagedTabletConfig() error {
877877
return errors.New("database app user not specified")
878878
}
879879
if c.DB.App.Password == "" {
880-
return errors.New("database app user password not specified")
880+
_, pass, err := dbconfigs.GetCredentialsServer().GetUserAndPassword(c.DB.App.User)
881+
if err == nil && pass != "" {
882+
c.DB.App.Password = pass
883+
} else {
884+
return errors.New("database app user password not specified")
885+
}
881886
}
882887
// Replication fixes should be disabled for Unmanaged tablets.
883888
mysqlctl.DisableActiveReparents = true

go/vt/vttablet/tabletserver/tabletenv/config_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,4 +484,12 @@ func TestVerifyUnmanagedTabletConfig(t *testing.T) {
484484
config.DB.App.Password = "testPassword"
485485
err = config.verifyUnmanagedTabletConfig()
486486
assert.Nil(t, err)
487+
488+
dbconfigs.SetDbCredentialsFilePath("./data/db_credentials.json")
489+
defer dbconfigs.SetDbCredentialsFilePath("")
490+
config.DB.App.Password = ""
491+
492+
err = config.verifyUnmanagedTabletConfig()
493+
assert.Nil(t, err)
494+
assert.Equal(t, "testPassword", config.DB.App.Password)
487495
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"testUser": ["testPassword"]
3+
}

0 commit comments

Comments
 (0)