Skip to content

Commit

Permalink
Merge pull request #32 from Syncano/devel
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
23doors authored Feb 14, 2019
2 parents 3b4aef8 + 499e2e7 commit ea645f9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ENV PYTHON_EGG_CACHE=/home/syncano/.python-eggs \
GEOS_LIBRARY_PATH=/usr/lib/libgeos_c.so.1

RUN set -ex \
&& pip install --upgrade pip \
&& adduser -D -s /bin/bash syncano \
&& apk add --no-cache \
bash \
Expand Down
2 changes: 1 addition & 1 deletion apps/core/mixins/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def initial(self, request, *args, **kwargs):
obj = Cached(model, kwargs=lookup_kwargs).get()
else:
obj = model.objects.get(**lookup_kwargs)
except (ValidationError, ObjectDoesNotExist):
except (ValidationError, ObjectDoesNotExist, ValueError):
# If value is not valid for a field or model not found - raise an error
raise ModelNotFound(model)
else:
Expand Down
2 changes: 1 addition & 1 deletion apps/hosting/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __call__(self, request):
except Instance.DoesNotExist:
raise Http404()
else:
instance = host.split(settings.HOSTING_DOMAIN)[0]
instance = host.split('.')[0]
# Check if we're dealing with: <prefix>--<instance_name>
domain_data = instance.rsplit('--', 1)
if len(domain_data) == 2:
Expand Down
30 changes: 19 additions & 11 deletions apps/hosting/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,31 @@ def validate_domain(self, domain):
answers = resolver.query(domain, 'CNAME')
except DNSException:
# If domain has no CNAME and it's a root domain, check if CNAME flattening is used
try:
r = requests.get('http://{}/2a1b7ceb-2b7c-4bd2-a40f-8b021278f5ea/'.format(domain),
timeout=(1.0, 3.0), allow_redirects=False)
if r.status_code == requests.codes.ok and r.content == b'OK':
return
except requests.RequestException:
pass
if domain.count('.') == 1:
try:
r = requests.get('http://{}/2a1b7ceb-2b7c-4bd2-a40f-8b021278f5ea/'.format(domain),
timeout=(1.0, 3.0), allow_redirects=False)
if r.status_code == requests.codes.ok and r.content.decode() == settings.LOCATION:
return
except requests.RequestException:
pass
raise CNameNotSet()

# Check expected CNAME value
expected_cname = '{}{}.'.format(self.instance.name, settings.HOSTING_DOMAIN)
if len(answers) != 1:
raise WrongCName()

cname = answers[0].target.to_unicode()
if cname != expected_cname and not re.match(r'^[a-z0-9-]+--%s$' % expected_cname, cname):
raise WrongCName()
self.validate_cname(cname)

def validate_cname(self, cname):
# Check expected CNAME value
expected_cnames = ['{}.{}{}.'.format(self.instance.name, settings.LOCATION, settings.HOSTING_DOMAIN)]
if settings.MAIN_LOCATION:
expected_cnames.append('{}{}.'.format(self.instance.name, settings.HOSTING_DOMAIN))
for expected_cname in expected_cnames:
if cname == expected_cname or re.match(r'^[a-z0-9-]+--%s$' % expected_cname, cname):
return
raise WrongCName()

def run(self, hosting_pk, domain, **kwargs):
hosting_qs = Hosting.objects.filter(pk=hosting_pk)
Expand Down
2 changes: 1 addition & 1 deletion deploy/env/eu1.env
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ DB_INSTANCES_NAME=syncano-instances
DJANGO_SETTINGS_MODULE=settings.production
GOOGLE_APPLICATION_CREDENTIALS=/secrets/storage/credentials.json
GUI_ROOT_URL=https://dashboard.syncano.io
HOSTING_DOMAIN=.eu1.syncano.site
HOSTING_DOMAIN=.syncano.site
INVITATION_SITE_URL=https://dashboard.syncano.io
LEGACY_CODEBOX_ENABLED=false
LOCATION=eu1
Expand Down

0 comments on commit ea645f9

Please sign in to comment.