Skip to content

Commit

Permalink
Merge pull request #891 from gwu-libraries/t361-https2
Browse files Browse the repository at this point in the history
refs #361. Moves creating url into utility function. Adds HTTPS confi…
  • Loading branch information
justinlittman authored Aug 25, 2017
2 parents d46e029 + 7dc0900 commit c05d3d9
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 14 deletions.
16 changes: 16 additions & 0 deletions docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,22 @@ the change only applies to a single container, then you can stop the container w
the change applies to multiple containers (or you're not sure), you can stop all containers with ``docker-compose stop``.
Containers can then be brought back up with ``docker-compose up -d`` and the configuration change will take effect.

-------
HTTPS
-------
To run SFM with HTTPS:

1. Create or acquire a valid certificate and private key.
2. In ``docker-compose.yml`` uncomment the nginx-proxy container and set the paths under ``volumes`` to point to your certificate and key.
3. In ``.env`` change ``USE_HTTPS`` to True and ``SFM_PORT`` to 8080. Make sure that ``SFM_HOSTNAME`` matches your certificate.
4. Start up SFM.

Note:

* HTTPS will run on 443. Port 80 will redirect to 443.
* For more information on nginx-proxy, including advanced configuration see https://github.com/jwilder/nginx-proxy.
* If you receive a 502 (bad gateway), wait until SFM UI has completely started. If the 502 continues, troubleshoot SFM UI.

----------
Stopping
----------
Expand Down
9 changes: 3 additions & 6 deletions sfm/message_consumer/sfm_ui_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
from sfmutils.harvester import CODE_UNKNOWN_ERROR
from ui.models import User, Harvest, Collection, Seed, Warc, Export, HarvestStat
from ui.jobs import collection_stop
from ui.utils import get_email_addresses_for_collection_set
from ui.utils import get_email_addresses_for_collection_set, get_site_url
from ui.export import create_readme_for_export

import json
from django.core.mail import send_mail
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.contrib.sites.models import Site
import iso8601
import time
from smtplib import SMTPException
Expand Down Expand Up @@ -148,8 +147,7 @@ def _on_harvest_status_message(self):
break

if receiver_emails:
harvest_url = 'http://{}{}'.format(Site.objects.get_current().domain,
reverse('harvest_detail', args=(harvest.id,)))
harvest_url = get_site_url() + reverse('harvest_detail', args=(harvest.id,))

# Send Status mail
if settings.PERFORM_EMAILS:
Expand Down Expand Up @@ -253,8 +251,7 @@ def _on_export_status_message(self):
# Get receiver's email address
receiver_email = export.user.email
if receiver_email:
export_url = 'http://{}{}'.format(Site.objects.get_current().domain,
reverse('export_detail', args=(export.id,)))
export_url = get_site_url() + reverse('export_detail', args=(export.id,))

# Send Status mail
if settings.PERFORM_EMAILS:
Expand Down
6 changes: 5 additions & 1 deletion sfm/sfm/settings/docker_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@
'1': {
'name': 'SFM',
'domain': env.get('SFM_HOST', 'localhost')
},
'2': {
'name': 'SFM-80',
'domain': env.get('SFM_HOSTNAME', 'localhost')
}
}
SITE_ID = 1
SITE_ID = 2 if env.get('SFM_USE_HTTPS', 'False').lower() == 'true' else 1

if 'SFM_SITE_ADMIN_EMAIL' in env:
ADMINS = ((env.get('SFM_SITE_ADMIN_NAME', 'sfmadmin'), env.get('SFM_SITE_ADMIN_EMAIL')),)
Expand Down
7 changes: 3 additions & 4 deletions sfm/ui/management/commands/addsocialapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ def handle(self, *args, **options):
client_id=options['client_id'],
secret=options['secret'],
name=options['provider'])
site = Site.objects.all()[0]
assert site
social_app.sites.add(site)
site.save()
for site in Site.objects.all():
social_app.sites.add(site)
site.save()
self.stdout.write('Created {} social app.'.format(options['provider']))
else:
self.stdout.write(
Expand Down
5 changes: 2 additions & 3 deletions sfm/ui/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
from django.core.mail import EmailMultiAlternatives
from django.db.models import Sum, Q
from django.conf import settings
from django.contrib.sites.models import Site
from django.core.urlresolvers import reverse

from .models import User, CollectionSet, Collection, HarvestStat, Harvest
from .sched import next_run_time
from .utils import get_admin_email_addresses
from .utils import get_admin_email_addresses, get_site_url
import ui.monitoring

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -387,4 +386,4 @@ def _was_harvest_in_range(range_start, range_end, collection):


def _create_url(path):
return 'http://{}{}'.format(Site.objects.get_current().domain, path)
return get_site_url() + path
7 changes: 7 additions & 0 deletions sfm/ui/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from django.contrib.sites.models import Site

import os
from os import environ as env
from itertools import islice, chain
import logging

Expand Down Expand Up @@ -211,3 +213,8 @@ def get_admin_email_addresses():
for _, email_address in settings.ADMINS:
email_addresses.append(email_address)
return email_addresses


def get_site_url():
return '{}://{}'.format("https" if env.get('SFM_USE_HTTPS', 'False').lower() == 'true' else "http",
Site.objects.get_current().domain)

0 comments on commit c05d3d9

Please sign in to comment.