Skip to content

Commit

Permalink
[Cleanup] cleanup settings and exposing some of them as env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
geosolutions committed May 14, 2019
1 parent 0e0acc8 commit 9330b9e
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 129 deletions.
79 changes: 0 additions & 79 deletions geonode/local_settings.py.geoserver.sample
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,6 @@ import os
from urlparse import urlparse, urlunparse
from geonode.settings import *

# Require users to authenticate before using Geonode
LOCKDOWN_GEONODE = strtobool(os.getenv('LOCKDOWN_GEONODE', 'False'))

# Require users to authenticate before using Geonode
if LOCKDOWN_GEONODE:
MIDDLEWARE_CLASSES = MIDDLEWARE_CLASSES + \
('geonode.security.middleware.LoginRequiredMiddleware',)

# Add additional paths (as regular expressions) that don't require
# authentication.
# - authorized exempt urls needed for oauth when GeoNode is set to lockdown
FORCE_SCRIPT_NAME = os.getenv('FORCE_SCRIPT_NAME', '')
AUTH_EXEMPT_URLS = (
r'^%s/?$' % FORCE_SCRIPT_NAME,
'%s/o/*' % FORCE_SCRIPT_NAME,
'%s/gs/*' % FORCE_SCRIPT_NAME,
'%s/account/*' % FORCE_SCRIPT_NAME,
'%s/static/*' % FORCE_SCRIPT_NAME,
'%s/api/o/*' % FORCE_SCRIPT_NAME,
'%s/api/roles' % FORCE_SCRIPT_NAME,
'%s/api/adminRole' % FORCE_SCRIPT_NAME,
'%s/api/users' % FORCE_SCRIPT_NAME,
'%s/api/layers' % FORCE_SCRIPT_NAME,
)

PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))

MEDIA_ROOT = os.getenv('MEDIA_ROOT', os.path.join(PROJECT_ROOT, "uploaded"))
Expand All @@ -62,41 +37,8 @@ STATIC_ROOT = os.getenv('STATIC_ROOT',
os.path.join(PROJECT_ROOT, "static_root")
)

# SECRET_KEY = '************************'
# Make this unique, and don't share it with anybody.
SECRET_KEY = os.getenv('SECRET_KEY', "123456")

# per-deployment settings should go here
SITE_HOST_NAME = os.getenv('SITE_HOST_NAME', 'localhost')
SITE_HOST_PORT = os.getenv('SITE_HOST_PORT', None)
_default_siteurl = "http://%s:%s/" % (SITE_HOST_NAME, SITE_HOST_PORT) if SITE_HOST_PORT else "http://%s/" % SITE_HOST_NAME
SITEURL = os.getenv('SITEURL', _default_siteurl)

# we need hostname for deployed
_surl = urlparse(SITEURL)
HOSTNAME = _surl.hostname

# add trailing slash to site url. geoserver url will be relative to this
if not SITEURL.endswith('/'):
SITEURL = '{}/'.format(SITEURL)

try:
# try to parse python notation, default in dockerized env
ALLOWED_HOSTS = ast.literal_eval(os.getenv('ALLOWED_HOSTS'))
except ValueError:
# fallback to regular list of values separated with misc chars
ALLOWED_HOSTS = [HOSTNAME, 'localhost', 'django', 'geonode'] if os.getenv('ALLOWED_HOSTS') is None \
else re.split(r' *[,|:|;] *', os.getenv('ALLOWED_HOSTS'))

TIME_ZONE = 'UTC'

# Login and logout urls override
LOGIN_URL = os.getenv('LOGIN_URL', '{}account/login/'.format(SITEURL))
LOGOUT_URL = os.getenv('LOGOUT_URL', '{}account/logout/'.format(SITEURL))

ACCOUNT_LOGIN_REDIRECT_URL = os.getenv('LOGIN_REDIRECT_URL', SITEURL)
ACCOUNT_LOGOUT_REDIRECT_URL = os.getenv('LOGOUT_REDIRECT_URL', SITEURL)

# Backend
DATABASES = {
'default': {
Expand Down Expand Up @@ -514,27 +456,6 @@ CORS_ORIGIN_ALLOW_ALL = True

GEOIP_PATH = "/usr/local/share/GeoIP"

# add following lines to your local settings to enable monitoring
MONITORING_ENABLED = True

if MONITORING_ENABLED:
if 'geonode.contrib.monitoring' not in INSTALLED_APPS:
INSTALLED_APPS += ('geonode.contrib.monitoring',)
if 'geonode.contrib.monitoring.middleware.MonitoringMiddleware' not in MIDDLEWARE_CLASSES:
MIDDLEWARE_CLASSES += \
('geonode.contrib.monitoring.middleware.MonitoringMiddleware',)
MONITORING_CONFIG = None
MONITORING_HOST_NAME = os.getenv("MONITORING_HOST_NAME", HOSTNAME)
MONITORING_SERVICE_NAME = os.getenv("MONITORING_SERVICE_NAME", 'local-geonode')


# Documents Thumbnails
UNOCONV_ENABLE = True

if UNOCONV_ENABLE:
UNOCONV_EXECUTABLE = os.getenv('UNOCONV_EXECUTABLE', '/usr/bin/unoconv')
UNOCONV_TIMEOUT = os.getenv('UNOCONV_TIMEOUT', 30) # seconds

# Advanced Security Workflow Settings
DELAYED_SECURITY_SIGNALS = False
ACCOUNT_OPEN_SIGNUP = True
Expand Down
116 changes: 66 additions & 50 deletions geonode/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,20 @@
# otherwise it will raise errors for the missing non-minified dependencies
DEBUG_STATIC = strtobool(os.getenv('DEBUG_STATIC', 'False'))

FORCE_SCRIPT_NAME = os.getenv('FORCE_SCRIPT_NAME', '')

# Define email service on GeoNode
EMAIL_ENABLE = strtobool(os.getenv('EMAIL_ENABLE', 'False'))

if EMAIL_ENABLE:
EMAIL_BACKEND = os.getenv('DJANGO_EMAIL_BACKEND',
default='django.core.mail.backends.smtp.EmailBackend')
EMAIL_HOST = 'localhost'
EMAIL_PORT = 25
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_USE_TLS = False
DEFAULT_FROM_EMAIL = 'GeoNode <no-reply@geonode.org>'
EMAIL_HOST = os.getenv('DJANGO_EMAIL_HOST', 'localhost')
EMAIL_PORT = os.getenv('DJANGO_EMAIL_PORT', 25)
EMAIL_HOST_USER = os.getenv('DJANGO_EMAIL_HOST_USER', '')
EMAIL_HOST_PASSWORD = os.getenv('DJANGO_EMAIL_HOST_PASSWORD', '')
EMAIL_USE_TLS = strtobool(os.getenv('DJANGO_EMAIL_USE_TLS', 'False'))
DEFAULT_FROM_EMAIL = os.getenv('DEFAULT_FROM_EMAIL', 'GeoNode <no-reply@geonode.org>')
else:
EMAIL_BACKEND = os.getenv('DJANGO_EMAIL_BACKEND',
default='django.core.mail.backends.console.EmailBackend')
Expand All @@ -78,25 +80,6 @@
else:
DJANGO_LIVE_TEST_SERVER_ADDRESS = 'localhost:8000'

try:
# try to parse python notation, default in dockerized env
ALLOWED_HOSTS = ast.literal_eval(os.getenv('ALLOWED_HOSTS'))
except ValueError:
# fallback to regular list of values separated with misc chars
ALLOWED_HOSTS = ['localhost', 'django', 'geonode'] if os.getenv('ALLOWED_HOSTS') is None \
else re.split(r' *[,|:|;] *', os.getenv('ALLOWED_HOSTS'))

# AUTH_IP_WHITELIST property limits access to users/groups REST endpoints
# to only whitelisted IP addresses.
#
# Empty list means 'allow all'
#
# If you need to limit 'api' REST calls to only some specific IPs
# fill the list like below:
#
# AUTH_IP_WHITELIST = ['192.168.1.158', '192.168.1.159']
AUTH_IP_WHITELIST = []

# Make this unique, and don't share it with anybody.
_DEFAULT_SECRET_KEY = 'myv-y4#7j-d*p-__@j#*3z@!y24fz8%^z2v6atuy4bo9vqr1_a'
SECRET_KEY = os.getenv('SECRET_KEY', _DEFAULT_SECRET_KEY)
Expand Down Expand Up @@ -237,8 +220,8 @@
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = os.getenv('MEDIA_URL', "/uploaded/")
LOCAL_MEDIA_URL = os.getenv('LOCAL_MEDIA_URL', "/uploaded/")
MEDIA_URL = os.getenv('MEDIA_URL', '%s/uploaded/' % FORCE_SCRIPT_NAME)
LOCAL_MEDIA_URL = os.getenv('LOCAL_MEDIA_URL', '%s/uploaded/' % FORCE_SCRIPT_NAME)

# Absolute path to the directory that holds static files like app media.
# Example: "/home/media/media.lawrence.com/apps/"
Expand All @@ -248,7 +231,7 @@

# URL that handles the static files like app media.
# Example: "http://media.lawrence.com"
STATIC_URL = os.getenv('STATIC_URL', "/static/")
STATIC_URL = os.getenv('STATIC_URL', '%s/static/' % FORCE_SCRIPT_NAME)

# Additional directories which hold static files
_DEFAULT_STATICFILES_DIRS = [
Expand Down Expand Up @@ -635,15 +618,18 @@
# authentication.
# - authorized exempt urls needed for oauth when GeoNode is set to lockdown
AUTH_EXEMPT_URLS = (
r'^/?$',
'/gs/*',
'/static/*',
'/o/*',
'/api/o/*',
'/api/roles',
'/api/adminRole',
'/api/users',
'/api/layers',
r'^%s/?$' % FORCE_SCRIPT_NAME,
'%s/o/*' % FORCE_SCRIPT_NAME,
'%s/gs/*' % FORCE_SCRIPT_NAME,
'%s/account/*' % FORCE_SCRIPT_NAME,
'%s/static/*' % FORCE_SCRIPT_NAME,
'%s/api/o/*' % FORCE_SCRIPT_NAME,
'%s/api/roles' % FORCE_SCRIPT_NAME,
'%s/api/adminRole' % FORCE_SCRIPT_NAME,
'%s/api/users' % FORCE_SCRIPT_NAME,
'%s/api/layers' % FORCE_SCRIPT_NAME,
'%s/mps_index' % FORCE_SCRIPT_NAME,
'%s/mps-hub' % FORCE_SCRIPT_NAME,
)

ANONYMOUS_USER_ID = os.getenv('ANONYMOUS_USER_ID', '-1')
Expand Down Expand Up @@ -1053,8 +1039,34 @@

SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'

try:
# try to parse python notation, default in dockerized env
ALLOWED_HOSTS = ast.literal_eval(os.getenv('ALLOWED_HOSTS'))
except ValueError:
# fallback to regular list of values separated with misc chars
ALLOWED_HOSTS = [HOSTNAME, 'localhost', 'django', 'geonode'] if os.getenv('ALLOWED_HOSTS') is None \
else re.split(r' *[,|:|;] *', os.getenv('ALLOWED_HOSTS'))

# AUTH_IP_WHITELIST property limits access to users/groups REST endpoints
# to only whitelisted IP addresses.
#
# Empty list means 'allow all'
#
# If you need to limit 'api' REST calls to only some specific IPs
# fill the list like below:
#
# AUTH_IP_WHITELIST = ['192.168.1.158', '192.168.1.159']
AUTH_IP_WHITELIST = [] if os.getenv('AUTH_IP_WHITELIST') is None \
else re.split(r' *[,|:|;] *', os.getenv('AUTH_IP_WHITELIST'))

# A tuple of hosts the proxy can send requests to.
PROXY_ALLOWED_HOSTS = ()
try:
# try to parse python notation, default in dockerized env
PROXY_ALLOWED_HOSTS = ast.literal_eval(os.getenv('PROXY_ALLOWED_HOSTS'))
except ValueError:
# fallback to regular list of values separated with misc chars
PROXY_ALLOWED_HOSTS = [HOSTNAME, 'localhost', 'django', 'geonode', 'nominatim.openstreetmap.org'] if os.getenv('PROXY_ALLOWED_HOSTS') is None \
else re.split(r' *[,|:|;] *', os.getenv('PROXY_ALLOWED_HOSTS'))

# The proxy to use when making cross origin requests.
PROXY_URL = '/proxy/?url=' if DEBUG else None
Expand Down Expand Up @@ -1270,10 +1282,10 @@

# Make Free-Text Kaywords writable from users or read-only
# - if True only admins can edit free-text kwds from admin dashboard
FREETEXT_KEYWORDS_READONLY = False
FREETEXT_KEYWORDS_READONLY = ast.literal_eval(os.environ.get('FREETEXT_KEYWORDS_READONLY', 'True'))

# notification settings
NOTIFICATION_ENABLED = True or TEST
NOTIFICATION_ENABLED = ast.literal_eval(os.environ.get('NOTIFICATION_ENABLED', 'True')) or TEST
#PINAX_NOTIFICATIONS_LANGUAGE_MODEL = "people.Profile"

# notifications backends
Expand All @@ -1284,8 +1296,8 @@
PINAX_NOTIFICATIONS_HOOKSET = "pinax.notifications.hooks.DefaultHookSet"

# Queue non-blocking notifications.
PINAX_NOTIFICATIONS_QUEUE_ALL = False
PINAX_NOTIFICATIONS_LOCK_WAIT_TIMEOUT = -1
PINAX_NOTIFICATIONS_QUEUE_ALL = ast.literal_eval(os.environ.get('NOTIFICATIONS_QUEUE_ALL', 'False'))
PINAX_NOTIFICATIONS_LOCK_WAIT_TIMEOUT = os.environ.get('NOTIFICATIONS_LOCK_WAIT_TIMEOUT', -1)

# explicitly define NOTIFICATION_LOCK_LOCATION
# NOTIFICATION_LOCK_LOCATION = <path>
Expand All @@ -1295,7 +1307,8 @@
NOTIFICATIONS_MODULE = 'pinax.notifications'

# set to true to have multiple recipients in /message/create/
USER_MESSAGES_ALLOW_MULTIPLE_RECIPIENTS = False
USER_MESSAGES_ALLOW_MULTIPLE_RECIPIENTS = ast.literal_eval(
os.environ.get('USER_MESSAGES_ALLOW_MULTIPLE_RECIPIENTS', 'True'))

if NOTIFICATION_ENABLED:
if NOTIFICATIONS_MODULE not in INSTALLED_APPS:
Expand Down Expand Up @@ -1533,9 +1546,10 @@
'ARGS': []}}

# Each uploaded Layer must be approved by an Admin before becoming visible
ADMIN_MODERATE_UPLOADS = False
ADMIN_MODERATE_UPLOADS = ast.literal_eval(os.environ.get('ADMIN_MODERATE_UPLOADS', 'True'))

# add following lines to your local settings to enable monitoring
MONITORING_CONFIG = None
MONITORING_ENABLED = ast.literal_eval(os.environ.get('MONITORING_ENABLED', 'False'))
MONITORING_HOST_NAME = os.getenv("MONITORING_HOST_NAME", HOSTNAME)
MONITORING_SERVICE_NAME = os.getenv("MONITORING_SERVICE_NAME", 'local-geonode')
Expand All @@ -1545,7 +1559,8 @@

# this will disable csrf check for notification config views,
# use with caution - for dev purpose only
MONITORING_DISABLE_CSRF = False
CORS_ORIGIN_ALLOW_ALL = ast.literal_eval(os.environ.get('CORS_ORIGIN_ALLOW_ALL', 'True'))
MONITORING_DISABLE_CSRF = ast.literal_eval(os.environ.get('MONITORING_DISABLE_CSRF', 'False'))

if MONITORING_ENABLED:
if 'geonode.contrib.monitoring' not in INSTALLED_APPS:
Expand All @@ -1554,25 +1569,26 @@
MIDDLEWARE_CLASSES += \
('geonode.contrib.monitoring.middleware.MonitoringMiddleware',)

GEOIP_PATH = os.path.join(PROJECT_ROOT, 'GeoIPCities.dat')
GEOIP_PATH = os.getenv('GEOIP_PATH', os.path.join(PROJECT_ROOT, 'GeoIPCities.dat'))

# If this option is enabled, Resources belonging to a Group won't be
# visible by others
GROUP_PRIVATE_RESOURCES = False
GROUP_PRIVATE_RESOURCES = ast.literal_eval(os.environ.get('GROUP_PRIVATE_RESOURCES', 'False'))

# If this option is enabled, Groups will become strictly Mandatory on
# Metadata Wizard
GROUP_MANDATORY_RESOURCES = False
GROUP_MANDATORY_RESOURCES = ast.literal_eval(os.environ.get('GROUP_MANDATORY_RESOURCES', 'False'))

# A boolean which specifies wether to display the email in user's profile
SHOW_PROFILE_EMAIL = False
SHOW_PROFILE_EMAIL = ast.literal_eval(os.environ.get('SHOW_PROFILE_EMAIL', 'False'))

# Enables cross origin requests for geonode-client
MAP_CLIENT_USE_CROSS_ORIGIN_CREDENTIALS = strtobool(os.getenv(
'MAP_CLIENT_USE_CROSS_ORIGIN_CREDENTIALS',
'False'
))

ACCOUNT_OPEN_SIGNUP = True
ACCOUNT_OPEN_SIGNUP = ast.literal_eval(os.environ.get('ACCOUNT_OPEN_SIGNUP', 'True'))
ACCOUNT_APPROVAL_REQUIRED = strtobool(
os.getenv('ACCOUNT_APPROVAL_REQUIRED', 'False')
)
Expand Down

0 comments on commit 9330b9e

Please sign in to comment.