@@ -100,6 +100,9 @@ func (u *ConfigUpdater) UpdateDbConfig(ctx context.Context, projectRef string, c
100100 if err := u .UpdateDbNetworkRestrictionsConfig (ctx , projectRef , c .NetworkRestrictions , filter ... ); err != nil {
101101 return err
102102 }
103+ if c .SslEnforcement != nil {
104+ return u .UpdateSslEnforcement (ctx , projectRef , * c .SslEnforcement , filter ... )
105+ }
103106 return nil
104107}
105108
@@ -132,6 +135,35 @@ func (u *ConfigUpdater) UpdateDbNetworkRestrictionsConfig(ctx context.Context, p
132135 return nil
133136}
134137
138+ func (u * ConfigUpdater ) UpdateSslEnforcement (ctx context.Context , projectRef string , s sslEnforcement , filter ... func (string ) bool ) error {
139+ sslEnforcementConfig , err := u .client .V1GetSslEnforcementConfigWithResponse (ctx , projectRef )
140+ if err != nil {
141+ return errors .Errorf ("failed to read SSL enforcement config: %w" , err )
142+ } else if sslEnforcementConfig .JSON200 == nil {
143+ return errors .Errorf ("unexpected status %d: %s" , sslEnforcementConfig .StatusCode (), string (sslEnforcementConfig .Body ))
144+ }
145+ sslEnforcementDiff , err := s .DiffWithRemote (* sslEnforcementConfig .JSON200 )
146+ if err != nil {
147+ return err
148+ } else if len (sslEnforcementDiff ) == 0 {
149+ fmt .Fprintln (os .Stderr , "Remote DB SSL enforcement config is up to date." )
150+ return nil
151+ }
152+ fmt .Fprintln (os .Stderr , "Updating SSL enforcement with config:" , string (sslEnforcementDiff ))
153+ for _ , keep := range filter {
154+ if ! keep ("db" ) {
155+ return nil
156+ }
157+ }
158+ updateBody := s .ToUpdateSslEnforcementBody ()
159+ if resp , err := u .client .V1UpdateSslEnforcementConfigWithResponse (ctx , projectRef , updateBody ); err != nil {
160+ return errors .Errorf ("failed to update SSL enforcement config: %w" , err )
161+ } else if resp .JSON200 == nil {
162+ return errors .Errorf ("unexpected status %d: %s" , resp .StatusCode (), string (resp .Body ))
163+ }
164+ return nil
165+ }
166+
135167func (u * ConfigUpdater ) UpdateAuthConfig (ctx context.Context , projectRef string , c auth , filter ... func (string ) bool ) error {
136168 if ! c .Enabled {
137169 return nil
0 commit comments