@@ -18,6 +18,17 @@ class Meta:
1818 def __str__ (self ):
1919 return "{}-{}" .format (self .app .id , str (self .uuid )[:7 ])
2020
21+ def _load_service_config (self , app , component ):
22+ config = super ()._load_service_config (app , component )
23+
24+ # See if the ssl.enforce annotation is available
25+ if 'ssl' not in config :
26+ config ['ssl' ] = {}
27+ if 'enforce' not in config ['ssl' ]:
28+ config ['ssl' ]['enforce' ] = 'false'
29+
30+ return config
31+
2132 def _check_previous_tls_settings (self ):
2233 try :
2334 previous_tls_settings = self .app .tls_set .latest ()
@@ -40,16 +51,24 @@ def save(self, *args, **kwargs):
4051 # get config for the service
4152 config = self ._load_service_config (app , 'router' )
4253
43- # See if the ssl.enforce annotation is available
44- if 'ssl' not in config :
45- config ['ssl' ] = {}
46- if 'enforce' not in config ['ssl' ]:
47- config ['ssl' ]['enforce' ] = 'false'
48-
4954 # convert from bool to string
5055 config ['ssl' ]['enforce' ] = str (https_enforced )
5156
5257 self ._save_service_config (app , 'router' , config )
5358
5459 # Save to DB
5560 return super (TLS , self ).save (* args , ** kwargs )
61+
62+ def sync (self ):
63+ try :
64+ app = str (self .app )
65+
66+ config = self ._load_service_config (app , 'router' )
67+ if (
68+ config ['ssl' ]['enforce' ] != str (self .https_enforced ) and
69+ self .https_enforced is not None
70+ ):
71+ config ['ssl' ]['enforce' ] = str (self .https_enforced )
72+ self ._save_service_config (app , 'router' , config )
73+ except TLS .DoesNotExist :
74+ pass
0 commit comments