From 3999b1798b4d2299cbe50074d9c973c02e6134c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Cie=C5=9Blak?= Date: Tue, 29 Mar 2022 18:07:45 +0200 Subject: [PATCH] Use db name for URI in Teleterm rather than db server host ID The previous version of the code used GetHostId return value for the URI. That caused problems as a single host can run multiple database servers. This in turn resulted in stuff like Teleterm not listing all databases. There's `Database.GetURI` function which I decided not to use, because it's an URI on its own which might include stuff like port numbers and what not. I wanted to avoid a situation in which the database URI creates some potential conflicts with the Teleterm URIs. I noticed that the Web UI code runs `DeduplicateDatabases` already and it uses `Database.GetName` underneath, so I deemed it a good candidate to be a part of a database URI in Teleterm. Fixes gravitational/webapps.e#127 --- lib/teleterm/clusters/cluster_databases.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/teleterm/clusters/cluster_databases.go b/lib/teleterm/clusters/cluster_databases.go index a7d52d64ae21e..e02d3c6095830 100644 --- a/lib/teleterm/clusters/cluster_databases.go +++ b/lib/teleterm/clusters/cluster_databases.go @@ -69,15 +69,22 @@ func (c *Cluster) GetDatabases(ctx context.Context) ([]Database, error) { return nil, trace.Wrap(err) } - dbs := []Database{} - for _, srv := range dbservers { - dbs = append(dbs, Database{ - URI: c.URI.AppendDB(srv.GetHostID()), - Database: srv.GetDatabase(), + var dbs []types.Database + for _, server := range dbservers { + dbs = append(dbs, server.GetDatabase()) + } + + dbs = types.DeduplicateDatabases(dbs) + + var responseDbs []Database + for _, db := range dbs { + responseDbs = append(responseDbs, Database{ + URI: c.URI.AppendDB(db.GetName()), + Database: db, }) } - return dbs, nil + return responseDbs, nil } // ReissueDBCerts issues new certificates for specific DB access