Skip to content

Commit cb8223a

Browse files
committed
fix(rds-refresh): use correct DBLab config API format
DBLab expects a flat JSON structure matching ConfigProjection fields, not a nested structure. The API automatically reloads the config after update (calls reloadFn internally), so no SIGHUP is needed. Changed from nested: {"retrieval": {"dbSource": {"host": "..."}}} To flat projection format: {"host": "...", "port": 5432, "dbname": "...", ...}
1 parent 869eba1 commit cb8223a

File tree

1 file changed

+14
-34
lines changed

1 file changed

+14
-34
lines changed

rds-refresh/dblab.go

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,13 @@ type APIError struct {
7373
}
7474

7575
// ConfigUpdateRequest represents a request to update DBLab config.
76+
// Uses flat structure matching DBLab's ConfigProjection fields.
7677
type ConfigUpdateRequest struct {
77-
Retrieval *RetrievalConfigUpdate `json:"retrieval,omitempty"`
78-
}
79-
80-
// RetrievalConfigUpdate represents retrieval config fields to update.
81-
type RetrievalConfigUpdate struct {
82-
DBSource *DBSourceConfig `json:"dbSource,omitempty"`
83-
}
84-
85-
// DBSourceConfig represents the source database connection config.
86-
type DBSourceConfig struct {
87-
Host string `json:"host,omitempty"`
88-
Port int `json:"port,omitempty"`
89-
DBName string `json:"dbname,omitempty"`
90-
Username string `json:"username,omitempty"`
91-
Password string `json:"password,omitempty"`
78+
Host *string `json:"host,omitempty"`
79+
Port *int64 `json:"port,omitempty"`
80+
DBName *string `json:"dbname,omitempty"`
81+
Username *string `json:"username,omitempty"`
82+
Password *string `json:"password,omitempty"`
9283
}
9384

9485
// DBLabClient provides methods to interact with the DBLab Engine API.
@@ -227,39 +218,28 @@ func (c *DBLabClient) Health(ctx context.Context) error {
227218
}
228219

229220
// UpdateSourceConfig updates the source database connection in DBLab config.
221+
// DBLab automatically reloads the configuration after the update.
230222
func (c *DBLabClient) UpdateSourceConfig(ctx context.Context, host string, port int, dbname, username, password string) error {
223+
port64 := int64(port)
231224
updateReq := ConfigUpdateRequest{
232-
Retrieval: &RetrievalConfigUpdate{
233-
DBSource: &DBSourceConfig{
234-
Host: host,
235-
Port: port,
236-
DBName: dbname,
237-
Username: username,
238-
Password: password,
239-
},
240-
},
225+
Host: &host,
226+
Port: &port64,
227+
DBName: &dbname,
228+
Username: &username,
229+
Password: &password,
241230
}
242231

243232
bodyBytes, err := json.Marshal(updateReq)
244233
if err != nil {
245234
return fmt.Errorf("failed to marshal config update: %w", err)
246235
}
247236

248-
resp, err := c.doRequest(ctx, http.MethodPatch, "/admin/config", bytes.NewReader(bodyBytes))
237+
resp, err := c.doRequest(ctx, http.MethodPut, "/admin/config", bytes.NewReader(bodyBytes))
249238
if err != nil {
250239
return fmt.Errorf("failed to update DBLab config: %w", err)
251240
}
252241
defer resp.Body.Close()
253242

254-
var result APIResponse
255-
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
256-
return fmt.Errorf("failed to decode config update response: %w", err)
257-
}
258-
259-
if result.Status != "OK" {
260-
return fmt.Errorf("config update failed: %s", result.Message)
261-
}
262-
263243
return nil
264244
}
265245

0 commit comments

Comments
 (0)