Skip to content

Commit 225b628

Browse files
author
Matthew Fisher
committed
Merge pull request #1582 from bacongobbler/903-apps-open
fix(controller): expose app URL
2 parents 76f0a43 + 8c335e1 commit 225b628

4 files changed

Lines changed: 10 additions & 8 deletions

File tree

client/deis.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -572,15 +572,10 @@ def apps_open(self, args):
572572
# TODO: replace with a single API call to apps endpoint
573573
response = self._dispatch('get', "/api/apps/{}".format(app))
574574
if response.status_code == requests.codes.ok: # @UndefinedVariable
575-
cluster = response.json()['cluster']
576-
else:
577-
raise ResponseError(response)
578-
response = self._dispatch('get', "/api/clusters/{}".format(cluster))
579-
if response.status_code == requests.codes.ok: # @UndefinedVariable
580-
domain = response.json()['domain']
575+
url = response.json()['url']
581576
# use the OS's default handler to open this URL
582-
webbrowser.open('http://{}.{}/'.format(app, domain))
583-
return domain
577+
webbrowser.open('http://{}.{}/'.format(app, url))
578+
return url
584579
else:
585580
raise ResponseError(response)
586581

controller/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)

controller/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`."""

controller/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)