Skip to content

Commit ca48d7a

Browse files
author
Matthew Fisher
committed
feat(router): allow customizing controller subdomain
1 parent 6af57b2 commit ca48d7a

4 files changed

Lines changed: 22 additions & 5 deletions

File tree

api/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def validate_app_structure(value):
9292

9393
def validate_reserved_names(value):
9494
"""A value cannot use some reserved names."""
95-
if value in ['deis']:
95+
if value in settings.DEIS_RESERVED_NAMES:
9696
raise ValidationError('{} is a reserved name.'.format(value))
9797

9898

api/tests/test_app.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,6 @@ def test_app_errors(self):
156156
HTTP_AUTHORIZATION='token {}'.format(self.token))
157157
self.assertContains(response, 'App IDs can only contain [a-z0-9-]', status_code=400)
158158
url = '/v1/apps'
159-
body = {'id': 'deis'}
160-
response = self.client.post(url, json.dumps(body), content_type='application/json',
161-
HTTP_AUTHORIZATION='token {}'.format(self.token))
162-
self.assertContains(response, 'deis is a reserved name.', status_code=400)
163159
body = {'id': app_id}
164160
response = self.client.post(url, json.dumps(body), content_type='application/json',
165161
HTTP_AUTHORIZATION='token {}'.format(self.token))
@@ -175,6 +171,20 @@ def test_app_errors(self):
175171
HTTP_AUTHORIZATION='token {}'.format(self.token))
176172
self.assertEquals(response.status_code, 404)
177173

174+
def test_app_reserved_names(self):
175+
"""Nobody should be able to create applications with names which are reserved."""
176+
url = '/v1/apps'
177+
reserved_names = ['foo', 'bar']
178+
with self.settings(DEIS_RESERVED_NAMES=reserved_names):
179+
for name in reserved_names:
180+
body = {'id': name}
181+
response = self.client.post(url, json.dumps(body), content_type='application/json',
182+
HTTP_AUTHORIZATION='token {}'.format(self.token))
183+
self.assertContains(
184+
response,
185+
'{} is a reserved name.'.format(name),
186+
status_code=400)
187+
178188
def test_app_structure_is_valid_json(self):
179189
"""Application structures should be valid JSON objects."""
180190
url = '/v1/apps'

deis/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@
287287
# standard datetime format used for logging, model timestamps, etc.
288288
DEIS_DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%S%Z'
289289

290+
# names which apps cannot reserve for routing
291+
DEIS_RESERVED_NAMES = ['deis']
292+
290293
# default scheduler settings
291294
SCHEDULER_MODULE = 'scheduler.mock'
292295
SCHEDULER_TARGET = '' # path to scheduler endpoint (e.g. /var/run/fleet.sock)

templates/confd_settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
{{ end }}
5050
UNIT_HOSTNAME = '{{ if exists "/deis/controller/unitHostname" }}{{ getv "/deis/controller/unitHostname" }}{{ else }}default{{ end }}'
5151

52+
{{ if exists "/deis/controller/subdomain" }}
53+
DEIS_RESERVED_NAMES = ['{{ getv "/deis/controller/subdomain" }}']
54+
{{ end }}
55+
5256
# AUTH
5357
# LDAP
5458
{{ if exists "/deis/controller/auth/ldap/endpoint" }}

0 commit comments

Comments
 (0)