Skip to content

Commit a8bf1ce

Browse files
author
Matthew Fisher
committed
feat(controller): expose app url
While users should not have access to view a cluster's private information like the cluster's auth key or the list of machines, we need the cluster domain in order to expose the app url to the user.
1 parent 82da13c commit a8bf1ce

3 files changed

Lines changed: 7 additions & 0 deletions

File tree

api/models.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ class Meta:
131131
def __str__(self):
132132
return self.id
133133

134+
@property
135+
def url(self):
136+
return self.id + '.' + self.cluster.domain
137+
134138
def create(self, *args, **kwargs):
135139
config = Config.objects.create(owner=self.owner, app=self, values={})
136140
build = Build.objects.create(owner=self.owner, app=self, image=settings.DEFAULT_BUILD)

api/serializers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ class AppSerializer(serializers.ModelSerializer):
172172
owner = serializers.Field(source='owner.username')
173173
id = serializers.SlugField(default=utils.generate_app_name)
174174
cluster = serializers.SlugRelatedField(slug_field='id')
175+
url = serializers.Field(source='url')
175176

176177
class Meta:
177178
"""Metadata options for a :class:`AppSerializer`."""

api/tests/test_app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ def test_app(self):
4242
app_id = response.data['id'] # noqa
4343
self.assertIn('cluster', response.data)
4444
self.assertIn('id', response.data)
45+
self.assertIn('url', response.data)
46+
self.assertEqual(response.data['url'], '{app_id}.autotest.local'.format(**locals()))
4547
response = self.client.get('/api/apps')
4648
self.assertEqual(response.status_code, 200)
4749
self.assertEqual(len(response.data['results']), 1)

0 commit comments

Comments
 (0)