Skip to content
This repository has been archived by the owner on Aug 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #108 from open-craft/smarnach/cms-hostname
Browse files Browse the repository at this point in the history
Set CMS_HOSTNAME Ansible variable to the Studio domain.
  • Loading branch information
Sven Marnach authored Jun 16, 2016
2 parents a72f3a6 + 76301b9 commit d808bb9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions instance/models/openedx_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"""
Open edX Instance models
"""
import re
import string

from django.conf import settings
Expand Down Expand Up @@ -145,6 +146,21 @@ def studio_domain(self):
else:
return self.internal_studio_domain

@property
def studio_domain_nginx_regex(self):
"""
Regex that matches either the internal or the external Studio URL.
This is exclusively meant for the Ansible variable CMS_HOSTNAME to configure the nginx
server_name regex to match the Studio domains.
"""
if self.external_studio_domain:
domains = [self.external_studio_domain, self.internal_studio_domain]
else:
domains = [self.internal_studio_domain]
choices = '|'.join(map(re.escape, domains)) # pylint: disable=bad-builtin
return '~^({})$'.format(choices)

@property
def url(self):
"""
Expand Down
1 change: 1 addition & 0 deletions instance/templates/instance/ansible/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ EDXAPP_PREVIEW_LMS_BASE: '{{ instance.lms_preview_domain }}'

EDXAPP_CMS_SITE_NAME: '{{ instance.studio_domain }}'
EDXAPP_CMS_BASE: '{{ instance.studio_domain }}'
CMS_HOSTNAME: '{{ instance.studio_domain_nginx_regex }}'

# Enable OpenStack settings to be able to use Swift. These three variables are ignored in versions
# of the configuration repo that don't have the openstack role yet, so it's safe to include them.
Expand Down
5 changes: 5 additions & 0 deletions instance/tests/models/test_openedx_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def test_domain_url(self):
self.assertEqual(instance.domain, internal_lms_domain)
self.assertEqual(instance.lms_preview_domain, internal_lms_preview_domain)
self.assertEqual(instance.studio_domain, internal_studio_domain)
self.assertEqual(instance.studio_domain_nginx_regex, r'~^(studio\-sample\.example\.org)$')
self.assertEqual(instance.url, 'http://{}/'.format(internal_lms_domain))
self.assertEqual(instance.lms_preview_url, 'http://{}/'.format(internal_lms_preview_domain))
self.assertEqual(instance.studio_url, 'http://{}/'.format(internal_studio_domain))
Expand All @@ -176,6 +177,10 @@ def test_domain_url(self):
self.assertEqual(instance.domain, external_lms_domain)
self.assertEqual(instance.lms_preview_domain, external_lms_preview_domain)
self.assertEqual(instance.studio_domain, external_studio_domain)
self.assertEqual(
instance.studio_domain_nginx_regex,
r'~^(external\-studio\.domain\.com|studio\-sample\.example\.org)$'
)
self.assertEqual(instance.url, 'http://{}/'.format(external_lms_domain))
self.assertEqual(instance.lms_preview_url, 'http://{}/'.format(external_lms_preview_domain))
self.assertEqual(instance.studio_url, 'http://{}/'.format(external_studio_domain))
Expand Down

0 comments on commit d808bb9

Please sign in to comment.