@@ -77,28 +77,28 @@ func generateURL(ctx context.Context, argsI any) (any, error) {
7777 return nil , fmt .Errorf ("unknown engine %q" , instance .Engine )
7878 }
7979
80- // Then we add the username
81- if args .User != "" {
82- // If a user is provided, use it directly to be resilient across API behaviors and test environments
83- u .User = url .User (args .User )
84- } else {
85- users , err := api .ListUsers (& rdb.ListUsersRequest {
86- Region : args .Region ,
87- InstanceID : args .InstanceID ,
88- Name : & args .User ,
89- }, scw .WithContext (ctx ), scw .WithAllPages ())
90- if err != nil {
91- return nil , fmt .Errorf ("failed to list users for instance %q" , args .InstanceID )
92- }
93- if users .TotalCount != 1 {
94- return nil , fmt .Errorf (
95- "expected 1 user with the name %q, got %d" ,
96- args .User ,
97- users .TotalCount ,
98- )
99- }
100- u .User = url .User (users .Users [0 ].Name )
101- }
80+ // Then we add the username
81+ if args .User != "" {
82+ // If a user is provided, use it directly to be resilient across API behaviors and test environments
83+ u .User = url .User (args .User )
84+ } else {
85+ users , err := api .ListUsers (& rdb.ListUsersRequest {
86+ Region : args .Region ,
87+ InstanceID : args .InstanceID ,
88+ Name : & args .User ,
89+ }, scw .WithContext (ctx ), scw .WithAllPages ())
90+ if err != nil {
91+ return nil , fmt .Errorf ("failed to list users for instance %q" , args .InstanceID )
92+ }
93+ if users .TotalCount != 1 {
94+ return nil , fmt .Errorf (
95+ "expected 1 user with the name %q, got %d" ,
96+ args .User ,
97+ users .TotalCount ,
98+ )
99+ }
100+ u .User = url .User (users .Users [0 ].Name )
101+ }
102102
103103 // Then we have to determine the endpoint
104104 var privateEndpoint * rdb.Endpoint
@@ -119,27 +119,9 @@ func generateURL(ctx context.Context, argsI any) (any, error) {
119119 }
120120 u .Host = fmt .Sprintf ("%s:%d" , endpoint .IP .String (), endpoint .Port )
121121
122- // Finally we add the database if it was given
122+ // Finally we add the database if it was given; otherwise keep instance base URL
123123 if args .Db != "" {
124- // Use provided database name directly; keep legacy lookup only when not provided
125124 u = u .JoinPath (args .Db )
126- } else {
127- databases , err := api .ListDatabases (& rdb.ListDatabasesRequest {
128- Region : args .Region ,
129- InstanceID : args .InstanceID ,
130- Name : & args .Db ,
131- }, scw .WithContext (ctx ), scw .WithAllPages ())
132- if err != nil {
133- return nil , fmt .Errorf ("failed to list databases for instance %q" , args .InstanceID )
134- }
135- if databases .TotalCount != 1 {
136- return nil , fmt .Errorf (
137- "expected 1 database with the name %q, got %d" ,
138- args .Db ,
139- databases .TotalCount ,
140- )
141- }
142- u = u .JoinPath (databases .Databases [0 ].Name )
143125 }
144126
145127 return u .String (), nil
0 commit comments