2017-11-09 16:31:57 +01:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
import os
|
2018-03-08 09:37:09 +01:00
|
|
|
import re
|
2017-11-09 16:31:57 +01:00
|
|
|
import sys
|
2018-03-08 09:37:09 +01:00
|
|
|
from six.moves.urllib.parse import urlparse
|
|
|
|
from typing import Any, Text, Tuple, Optional
|
2017-11-09 16:31:57 +01:00
|
|
|
|
|
|
|
if False:
|
|
|
|
from thumbor.context import Context
|
|
|
|
|
|
|
|
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath('__file__'))))
|
|
|
|
sys.path.append(ZULIP_PATH)
|
|
|
|
|
|
|
|
# Piece of code below relating to secrets conf has been duplicated with that of
|
|
|
|
# django settings in zproject/settings.py
|
|
|
|
import six.moves.configparser
|
|
|
|
|
|
|
|
DEPLOY_ROOT = os.path.join(os.path.realpath(os.path.dirname(__file__)), '..', '..')
|
|
|
|
|
|
|
|
config_file = six.moves.configparser.RawConfigParser()
|
|
|
|
config_file.read("/etc/zulip/zulip.conf")
|
|
|
|
|
|
|
|
# Whether this instance of Zulip is running in a production environment.
|
|
|
|
PRODUCTION = config_file.has_option('machine', 'deploy_type')
|
|
|
|
DEVELOPMENT = not PRODUCTION
|
|
|
|
|
|
|
|
secrets_file = six.moves.configparser.RawConfigParser()
|
|
|
|
if PRODUCTION:
|
|
|
|
secrets_file.read("/etc/zulip/zulip-secrets.conf")
|
|
|
|
else:
|
|
|
|
secrets_file.read(os.path.join(DEPLOY_ROOT, "zproject/dev-secrets.conf"))
|
|
|
|
|
|
|
|
def get_secret(key):
|
2018-03-12 03:27:29 +01:00
|
|
|
# type: (str) -> Optional[Text]
|
2017-11-09 16:31:57 +01:00
|
|
|
if secrets_file.has_option('secrets', key):
|
|
|
|
return secrets_file.get('secrets', key)
|
|
|
|
return None
|
|
|
|
|
|
|
|
THUMBOR_EXTERNAL_TYPE = 'external'
|
|
|
|
THUMBOR_S3_TYPE = 's3'
|
|
|
|
THUMBOR_LOCAL_FILE_TYPE = 'local_file'
|
|
|
|
|
2018-03-08 09:37:09 +01:00
|
|
|
def separate_url_and_source_type(url):
|
|
|
|
# type: (Text) -> Tuple[Text, Text]
|
|
|
|
THUMBNAIL_URL_PATT = re.compile('^(?P<actual_url>.+)/source_type/(?P<source_type>.+)')
|
|
|
|
matches = THUMBNAIL_URL_PATT.match(url)
|
|
|
|
return (matches.group('source_type'), matches.group('actual_url'))
|