@@ -25,30 +25,36 @@ type OnboardingDatabaseRequest struct {
2525
2626// ConfigResponse represents the configuration response
2727type ConfigResponse struct {
28- ID string `json:"id"`
29- ConnectionString string `json:"connection_string"`
30- PostgresVersion string `json:"postgres_version"`
31- SchemaOnly bool `json:"schema_only"`
32- RefreshSchedule string `json:"refresh_schedule"`
33- BranchPostgresqlConf string `json:"branch_postgresql_conf"`
34- DatabaseName string `json:"database_name"`
35- Domain string `json:"domain"`
36- LetsEncryptEmail string `json:"lets_encrypt_email"`
37- MaxRestores int `json:"max_restores"`
38- LastRefreshedAt * time.Time `json:"last_refreshed_at"`
39- NextRefreshAt * time.Time `json:"next_refresh_at"`
40- CreatedAt time.Time `json:"created_at"`
28+ ID string `json:"id"`
29+ ConnectionString string `json:"connection_string"`
30+ PostgresVersion string `json:"postgres_version"`
31+ SchemaOnly bool `json:"schema_only"`
32+ RefreshSchedule string `json:"refresh_schedule"`
33+ BranchPostgresqlConf string `json:"branch_postgresql_conf"`
34+ DatabaseName string `json:"database_name"`
35+ Domain string `json:"domain"`
36+ LetsEncryptEmail string `json:"lets_encrypt_email"`
37+ MaxRestores int `json:"max_restores"`
38+ LastRefreshedAt * time.Time `json:"last_refreshed_at"`
39+ NextRefreshAt * time.Time `json:"next_refresh_at"`
40+ CreatedAt time.Time `json:"created_at"`
41+ CrunchyBridgeAPIKey string `json:"crunchy_bridge_api_key"`
42+ CrunchyBridgeClusterName string `json:"crunchy_bridge_cluster_name"`
43+ CrunchyBridgeDatabaseName string `json:"crunchy_bridge_database_name"`
4144}
4245
4346// UpdateConfigRequest represents the request to update configuration
4447type UpdateConfigRequest struct {
45- ConnectionString string `json:"connectionString"`
46- PostgresVersion string `json:"postgresVersion"`
47- SchemaOnly * bool `json:"schemaOnly"`
48- RefreshSchedule string `json:"refreshSchedule"`
49- Domain string `json:"domain"`
50- LetsEncryptEmail string `json:"letsEncryptEmail"`
51- MaxRestores * int `json:"maxRestores"`
48+ ConnectionString string `json:"connectionString"`
49+ PostgresVersion string `json:"postgresVersion"`
50+ SchemaOnly * bool `json:"schemaOnly"`
51+ RefreshSchedule string `json:"refreshSchedule"`
52+ Domain string `json:"domain"`
53+ LetsEncryptEmail string `json:"letsEncryptEmail"`
54+ MaxRestores * int `json:"maxRestores"`
55+ CrunchyBridgeAPIKey string `json:"crunchyBridgeApiKey"`
56+ CrunchyBridgeClusterName string `json:"crunchyBridgeClusterName"`
57+ CrunchyBridgeDatabaseName string `json:"crunchyBridgeDatabaseName"`
5258}
5359
5460// @Summary Get configuration
@@ -72,19 +78,22 @@ func (s *Server) getConfig(c *gin.Context) {
7278 }
7379
7480 c .JSON (http .StatusOK , ConfigResponse {
75- ID : config .ID ,
76- ConnectionString : redactConnectionString (config .ConnectionString ),
77- PostgresVersion : config .PostgresVersion ,
78- SchemaOnly : config .SchemaOnly ,
79- RefreshSchedule : config .RefreshSchedule ,
80- BranchPostgresqlConf : config .BranchPostgresqlConf ,
81- DatabaseName : config .DatabaseName ,
82- Domain : config .Domain ,
83- LetsEncryptEmail : config .LetsEncryptEmail ,
84- MaxRestores : config .MaxRestores ,
85- LastRefreshedAt : config .LastRefreshedAt ,
86- NextRefreshAt : config .NextRefreshAt ,
87- CreatedAt : config .CreatedAt ,
81+ ID : config .ID ,
82+ ConnectionString : redactConnectionString (config .ConnectionString ),
83+ PostgresVersion : config .PostgresVersion ,
84+ SchemaOnly : config .SchemaOnly ,
85+ RefreshSchedule : config .RefreshSchedule ,
86+ BranchPostgresqlConf : config .BranchPostgresqlConf ,
87+ DatabaseName : config .DatabaseName ,
88+ Domain : config .Domain ,
89+ LetsEncryptEmail : config .LetsEncryptEmail ,
90+ MaxRestores : config .MaxRestores ,
91+ LastRefreshedAt : config .LastRefreshedAt ,
92+ NextRefreshAt : config .NextRefreshAt ,
93+ CreatedAt : config .CreatedAt ,
94+ CrunchyBridgeAPIKey : redactSecret (config .CrunchyBridgeAPIKey ),
95+ CrunchyBridgeClusterName : config .CrunchyBridgeClusterName ,
96+ CrunchyBridgeDatabaseName : config .CrunchyBridgeDatabaseName ,
8897 })
8998}
9099
@@ -117,6 +126,29 @@ func (s *Server) updateConfig(c *gin.Context) {
117126 return
118127 }
119128
129+ // Update Crunchy Bridge configuration if provided
130+ if req .CrunchyBridgeAPIKey != "" {
131+ config .CrunchyBridgeAPIKey = req .CrunchyBridgeAPIKey
132+ }
133+ if req .CrunchyBridgeClusterName != "" {
134+ config .CrunchyBridgeClusterName = req .CrunchyBridgeClusterName
135+ }
136+ if req .CrunchyBridgeDatabaseName != "" {
137+ config .CrunchyBridgeDatabaseName = req .CrunchyBridgeDatabaseName
138+ }
139+
140+ // Clear connection string if Crunchy Bridge fields are being set
141+ if req .CrunchyBridgeAPIKey != "" && req .ConnectionString == "" {
142+ config .ConnectionString = ""
143+ }
144+
145+ // Clear Crunchy Bridge fields if connection string is being set
146+ if req .ConnectionString != "" && req .CrunchyBridgeAPIKey == "" {
147+ config .CrunchyBridgeAPIKey = ""
148+ config .CrunchyBridgeClusterName = ""
149+ config .CrunchyBridgeDatabaseName = ""
150+ }
151+
120152 // Update connection string if provided
121153 if req .ConnectionString != "" {
122154 // Validate new connection string
@@ -238,22 +270,33 @@ func (s *Server) updateConfig(c *gin.Context) {
238270 s .logger .Info ().Str ("config_id" , config .ID ).Msg ("Configuration updated" )
239271
240272 c .JSON (http .StatusOK , ConfigResponse {
241- ID : config .ID ,
242- ConnectionString : redactConnectionString (config .ConnectionString ),
243- PostgresVersion : config .PostgresVersion ,
244- SchemaOnly : config .SchemaOnly ,
245- RefreshSchedule : config .RefreshSchedule ,
246- BranchPostgresqlConf : config .BranchPostgresqlConf ,
247- DatabaseName : config .DatabaseName ,
248- Domain : config .Domain ,
249- LetsEncryptEmail : config .LetsEncryptEmail ,
250- MaxRestores : config .MaxRestores ,
251- LastRefreshedAt : config .LastRefreshedAt ,
252- NextRefreshAt : config .NextRefreshAt ,
253- CreatedAt : config .CreatedAt ,
273+ ID : config .ID ,
274+ ConnectionString : redactConnectionString (config .ConnectionString ),
275+ PostgresVersion : config .PostgresVersion ,
276+ SchemaOnly : config .SchemaOnly ,
277+ RefreshSchedule : config .RefreshSchedule ,
278+ BranchPostgresqlConf : config .BranchPostgresqlConf ,
279+ DatabaseName : config .DatabaseName ,
280+ Domain : config .Domain ,
281+ LetsEncryptEmail : config .LetsEncryptEmail ,
282+ MaxRestores : config .MaxRestores ,
283+ LastRefreshedAt : config .LastRefreshedAt ,
284+ NextRefreshAt : config .NextRefreshAt ,
285+ CreatedAt : config .CreatedAt ,
286+ CrunchyBridgeAPIKey : redactSecret (config .CrunchyBridgeAPIKey ),
287+ CrunchyBridgeClusterName : config .CrunchyBridgeClusterName ,
288+ CrunchyBridgeDatabaseName : config .CrunchyBridgeDatabaseName ,
254289 })
255290}
256291
292+ // redactSecret replaces a secret value with *** if it's not empty
293+ func redactSecret (secret string ) string {
294+ if secret == "" {
295+ return ""
296+ }
297+ return "***"
298+ }
299+
257300// redactConnectionString replaces the password with *** in a PostgreSQL connection string
258301func redactConnectionString (connStr string ) string {
259302 if connStr == "" {
0 commit comments