diff --git a/cmd/dbaas_show_mysql.go b/cmd/dbaas_show_mysql.go index f6cbf96c..85e34f09 100644 --- a/cmd/dbaas_show_mysql.go +++ b/cmd/dbaas_show_mysql.go @@ -17,6 +17,7 @@ import ( "github.com/exoscale/cli/utils" exoapi "github.com/exoscale/egoscale/v2/api" "github.com/exoscale/egoscale/v2/oapi" + v3 "github.com/exoscale/egoscale/v3" ) type dbServiceMysqlComponentShowOutput struct { @@ -147,7 +148,39 @@ func (c *dbaasServiceShowCmd) showDatabaseServiceMysql(ctx context.Context) (out return nil, nil case c.ShowURI: - fmt.Println(utils.DefaultString(databaseService.Uri, "")) + // Read password from dedicated endpoint + client, err := switchClientZoneV3( + ctx, + globalstate.EgoscaleV3Client, + v3.ZoneName(c.Zone), + ) + if err != nil { + return nil, err + } + + uriParams := *databaseService.UriParams + + creds, err := client.RevealDBAASMysqlUserPassword( + ctx, + string(databaseService.Name), + uriParams["user"].(string), + ) + if err != nil { + return nil, err + } + + // Build URI + uri := fmt.Sprintf( + "mysql://%s:%s@%s:%s/%s?ssl-mode=%s", + uriParams["user"], + creds.Password, + uriParams["host"], + uriParams["port"], + uriParams["dbname"], + uriParams["ssl-mode"], + ) + + fmt.Println(uri) return nil, nil } diff --git a/cmd/dbaas_show_opensearch.go b/cmd/dbaas_show_opensearch.go index 2642bc45..87eb15b0 100644 --- a/cmd/dbaas_show_opensearch.go +++ b/cmd/dbaas_show_opensearch.go @@ -19,6 +19,7 @@ import ( "github.com/exoscale/cli/utils" exoapi "github.com/exoscale/egoscale/v2/api" "github.com/exoscale/egoscale/v2/oapi" + v3 "github.com/exoscale/egoscale/v3" ) type dbServiceOpensearchComponentsShowOutput struct { @@ -147,7 +148,37 @@ func (c *dbaasServiceShowCmd) showDatabaseServiceOpensearch(ctx context.Context) case c.ShowSettings != "": return nil, opensearchShowSettings(c.ShowSettings, res.JSON200) case c.ShowURI: - fmt.Println(utils.DefaultString(res.JSON200.Uri, "")) + // Read password from dedicated endpoint + client, err := switchClientZoneV3( + ctx, + globalstate.EgoscaleV3Client, + v3.ZoneName(c.Zone), + ) + if err != nil { + return nil, err + } + + uriParams := *res.JSON200.UriParams + + creds, err := client.RevealDBAASOpensearchUserPassword( + ctx, + string(res.JSON200.Name), + uriParams["user"].(string), + ) + if err != nil { + return nil, err + } + + // Build URI + uri := fmt.Sprintf( + "https://%s:%s@%s:%s", + uriParams["user"], + creds.Password, + uriParams["host"], + uriParams["port"], + ) + + fmt.Println(uri) return nil, nil default: return opensearchShowDatabase(res.JSON200, c.Zone) diff --git a/cmd/dbaas_show_pg.go b/cmd/dbaas_show_pg.go index 5c06eaa7..b3d4a47e 100644 --- a/cmd/dbaas_show_pg.go +++ b/cmd/dbaas_show_pg.go @@ -17,6 +17,7 @@ import ( "github.com/exoscale/cli/utils" exoapi "github.com/exoscale/egoscale/v2/api" "github.com/exoscale/egoscale/v2/oapi" + v3 "github.com/exoscale/egoscale/v3" ) type dbServicePGConnectionPool struct { @@ -181,7 +182,39 @@ func (c *dbaasServiceShowCmd) showDatabaseServicePG(ctx context.Context) (output return nil, nil case c.ShowURI: - fmt.Println(utils.DefaultString(databaseService.Uri, "")) + // Read password from dedicated endpoint + client, err := switchClientZoneV3( + ctx, + globalstate.EgoscaleV3Client, + v3.ZoneName(c.Zone), + ) + if err != nil { + return nil, err + } + + uriParams := *databaseService.UriParams + + creds, err := client.RevealDBAASPostgresUserPassword( + ctx, + string(databaseService.Name), + uriParams["user"].(string), + ) + if err != nil { + return nil, err + } + + // Build URI + uri := fmt.Sprintf( + "postgres://%s:%s@%s:%s/%s?sslmode=%s", + uriParams["user"], + creds.Password, + uriParams["host"], + uriParams["port"], + uriParams["dbname"], + uriParams["sslmode"], + ) + + fmt.Println(uri) return nil, nil } diff --git a/cmd/dbaas_show_redis.go b/cmd/dbaas_show_redis.go index 8d0ffeb8..c5374610 100644 --- a/cmd/dbaas_show_redis.go +++ b/cmd/dbaas_show_redis.go @@ -17,6 +17,7 @@ import ( "github.com/exoscale/cli/utils" exoapi "github.com/exoscale/egoscale/v2/api" "github.com/exoscale/egoscale/v2/oapi" + v3 "github.com/exoscale/egoscale/v3" ) type dbServiceRedisComponentShowOutput struct { @@ -143,7 +144,37 @@ func (c *dbaasServiceShowCmd) showDatabaseServiceRedis(ctx context.Context) (out return nil, nil case c.ShowURI: - fmt.Println(utils.DefaultString(databaseService.Uri, "")) + // Read password from dedicated endpoint + client, err := switchClientZoneV3( + ctx, + globalstate.EgoscaleV3Client, + v3.ZoneName(c.Zone), + ) + if err != nil { + return nil, err + } + + uriParams := *databaseService.UriParams + + creds, err := client.RevealDBAASRedisUserPassword( + ctx, + string(databaseService.Name), + uriParams["user"].(string), + ) + if err != nil { + return nil, err + } + + // Build URI + uri := fmt.Sprintf( + "rediss://%s:%s@%s:%s", + uriParams["user"], + creds.Password, + uriParams["host"], + uriParams["port"], + ) + + fmt.Println(uri) return nil, nil }