Skip to content
This repository was archived by the owner on May 6, 2020. It is now read-only.

Commit c81dbf9

Browse files
committed
fix(controller): Persist ssl.enforce header on service creation
1 parent 0397cd1 commit c81dbf9

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

rootfs/api/management/commands/load_db_state_to_k8s.py

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def save_apps(self):
4848
try:
4949
app.save()
5050
app.config_set.latest().save()
51+
app.tls_set.latest().sync()
5152
except DeisException as error:
5253
print('ERROR: Problem saving to model {} for {}'
5354
'due to {}'.format(str(App.__name__), str(app), str(error)))

rootfs/api/models/tls.py

+25-6
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)