Esempio n. 1
0
 def test_list(self):
     os.environ["TEST_DATA"] = "foo,bar,baz"
     self.assertEqual(get_env_list("TEST_DATA"), ["foo", "bar", "baz"])
     os.environ["TEST_DATA"] = "foo"
     self.assertEqual(get_env_list("TEST_DATA"), ["foo"])
     del os.environ["TEST_DATA"]
     self.assertEqual(get_env_list("TEST_DATA"), [])
     self.assertEqual(get_env_list("TEST_DATA", ["x"]), ["x"])
Esempio n. 2
0
 def test_list(self):
     os.environ['TEST_DATA'] = 'foo,bar,baz'
     self.assertEqual(get_env_list('TEST_DATA'), ['foo', 'bar', 'baz'])
     os.environ['TEST_DATA'] = 'foo'
     self.assertEqual(get_env_list('TEST_DATA'), ['foo'])
     del os.environ['TEST_DATA']
     self.assertEqual(get_env_list('TEST_DATA'), [])
     self.assertEqual(get_env_list('TEST_DATA', ['x']), ['x'])
Esempio n. 3
0
 def test_list(self):
     os.environ['TEST_DATA'] = 'foo,bar,baz'
     self.assertEqual(get_env_list('TEST_DATA'), ['foo', 'bar', 'baz'])
     os.environ['TEST_DATA'] = 'foo'
     self.assertEqual(get_env_list('TEST_DATA'), ['foo'])
     del os.environ['TEST_DATA']
     self.assertEqual(get_env_list('TEST_DATA'), [])
     self.assertEqual(get_env_list('TEST_DATA', ['x']), ['x'])
Esempio n. 4
0
SOCIAL_AUTH_FACEBOOK_KEY = os.environ.get("WEBLATE_SOCIAL_AUTH_FACEBOOK_KEY", "")
SOCIAL_AUTH_FACEBOOK_SECRET = os.environ.get("WEBLATE_SOCIAL_AUTH_FACEBOOK_SECRET", "")
SOCIAL_AUTH_FACEBOOK_SCOPE = ["email", "public_profile"]
SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = {"fields": "id,name,email"}

if "WEBLATE_SOCIAL_AUTH_GOOGLE_OAUTH2_KEY" in os.environ:
    AUTHENTICATION_BACKENDS += ("social_core.backends.google.GoogleOAuth2",)

SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = os.environ.get(
    "WEBLATE_SOCIAL_AUTH_GOOGLE_OAUTH2_KEY", ""
)
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = os.environ.get(
    "WEBLATE_SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET", ""
)
SOCIAL_AUTH_GOOGLE_OAUTH2_WHITELISTED_DOMAINS = get_env_list(
    "WEBLATE_SOCIAL_AUTH_GOOGLE_OAUTH2_WHITELISTED_DOMAINS"
)
SOCIAL_AUTH_GOOGLE_OAUTH2_WHITELISTED_EMAILS = get_env_list(
    "WEBLATE_SOCIAL_AUTH_GOOGLE_OAUTH2_WHITELISTED_EMAILS"
)

if "WEBLATE_SOCIAL_AUTH_GITLAB_KEY" in os.environ:
    AUTHENTICATION_BACKENDS += ("social_core.backends.gitlab.GitLabOAuth2",)

if "WEBLATE_SOCIAL_AUTH_GITLAB_API_URL" in os.environ:
    SOCIAL_AUTH_GITLAB_API_URL = os.environ.get("WEBLATE_SOCIAL_AUTH_GITLAB_API_URL")

SOCIAL_AUTH_GITLAB_KEY = os.environ.get("WEBLATE_SOCIAL_AUTH_GITLAB_KEY", "")
SOCIAL_AUTH_GITLAB_SECRET = os.environ.get("WEBLATE_SOCIAL_AUTH_GITLAB_SECRET", "")
SOCIAL_AUTH_GITLAB_SCOPE = ["read_user"]
Esempio n. 5
0
if "WEBLATE_AUTH_LDAP_SERVER_URI" in os.environ:
    import ldap
    from django_auth_ldap.config import LDAPSearch

    AUTH_LDAP_SERVER_URI = os.environ.get("WEBLATE_AUTH_LDAP_SERVER_URI")
    AUTH_LDAP_USER_DN_TEMPLATE = (
        os.environ.get("WEBLATE_AUTH_LDAP_USER_DN_TEMPLATE") or None
    )
    AUTHENTICATION_BACKENDS += ("django_auth_ldap.backend.LDAPBackend",)
    AUTH_LDAP_USER_ATTR_MAP = get_env_map(
        "WEBLATE_AUTH_LDAP_USER_ATTR_MAP", {"full_name": "name", "email": "mail"}
    )
    AUTH_LDAP_BIND_DN = os.environ.get("WEBLATE_AUTH_LDAP_BIND_DN", "")
    AUTH_LDAP_BIND_PASSWORD = os.environ.get("WEBLATE_AUTH_LDAP_BIND_PASSWORD", "")

    _AUTH_LDAP_USER_SEARCH = get_env_list("")
    if "WEBLATE_AUTH_LDAP_USER_SEARCH" in os.environ:
        AUTH_LDAP_USER_SEARCH = LDAPSearch(
            os.environ["WEBLATE_AUTH_LDAP_USER_SEARCH"],
            ldap.SCOPE_SUBTREE,
            os.environ.get("WEBLATE_AUTH_LDAP_USER_SEARCH_FILTER", "(uid=%(user)s)"),
        )

# Always include Weblate backend
AUTHENTICATION_BACKENDS += ("weblate.accounts.auth.WeblateUserBackend",)

# Social auth settings
SOCIAL_AUTH_PIPELINE = (
    "social_core.pipeline.social_auth.social_details",
    "social_core.pipeline.social_auth.social_uid",
    "social_core.pipeline.social_auth.auth_allowed",
Esempio n. 6
0
#     'weblate.addons.flags.TargetEditAddon',
#     'weblate.addons.generate.GenerateFileAddon',
#     'weblate.addons.json.JSONCustomizeAddon',
#     'weblate.addons.properties.PropertiesSortAddon',
#     'weblate.addons.git.GitSquashAddon',
# )

# E-mail address that error messages come from.
SERVER_EMAIL = os.environ['WEBLATE_SERVER_EMAIL']

# Default email address to use for various automated correspondence from
# the site managers. Used for registration emails.
DEFAULT_FROM_EMAIL = os.environ['WEBLATE_DEFAULT_FROM_EMAIL']

# List of URLs your site is supposed to serve
ALLOWED_HOSTS = get_env_list('WEBLATE_ALLOWED_HOSTS', ['*'])

# Example configuration for caching
CACHES = {
    'avatar': {
        'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
        'LOCATION': os.path.join(DATA_DIR, 'avatar-cache'),
        'TIMEOUT': 604800,
        'OPTIONS': {
            'MAX_ENTRIES': 1000,
        },
    }
}

# Extract redis password
REDIS_PASSWORD = os.environ.get('REDIS_PASSWORD', None)
Esempio n. 7
0
ALLOWED_HOSTS = [os.environ['OPENSHIFT_APP_DNS']]

TTF_PATH = os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'weblate', 'ttf')

if os.environ.get('WEBLATE_REQUIRE_LOGIN', '0') == '1':
    # Example for restricting access to logged in users
    LOGIN_REQUIRED_URLS = (r'/(.*)$', )

    # In such case you will want to include some of the exceptions
    LOGIN_REQUIRED_URLS_EXCEPTIONS = get_env_list(
        'WEBLATE_LOGIN_REQUIRED_URLS_EXCEPTIONS',
        (
            r'/accounts/(.*)$',  # Required for login
            r'/admin/login/(.*)$',  # Required for admin login
            r'/widgets/(.*)$',  # Allowing public access to widgets
            r'/data/(.*)$',  # Allowing public access to data exports
            r'/hooks/(.*)$',  # Allowing public access to notification hooks
            r'/healthz/$',  # Allowing public access to health check
            r'/api/(.*)$',  # Allowing access to API
            r'/js/i18n/$',  # Javascript localization
        ),
    )

# Authentication configuration
AUTHENTICATION_BACKENDS = ()

if 'WEBLATE_NO_EMAIL_AUTH' not in os.environ:
    AUTHENTICATION_BACKENDS += ('social_core.backends.email.EmailAuth', )

# Enable possibility of using other auth providers via configuration
Esempio n. 8
0
TTF_PATH = os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'weblate', 'ttf')

if os.environ.get('WEBLATE_REQUIRE_LOGIN', '0') == '1':
    # Example for restricting access to logged in users
    LOGIN_REQUIRED_URLS = (
        r'/(.*)$',
    )

    # In such case you will want to include some of the exceptions
    LOGIN_REQUIRED_URLS_EXCEPTIONS = get_env_list(
        'WEBLATE_LOGIN_REQUIRED_URLS_EXCEPTIONS',
        (
           r'/accounts/(.*)$',      # Required for login
           r'/admin/login/(.*)$',   # Required for admin login
           r'/widgets/(.*)$',       # Allowing public access to widgets
           r'/data/(.*)$',          # Allowing public access to data exports
           r'/hooks/(.*)$',         # Allowing public access to notification hooks
           r'/healthz/$',           # Allowing public access to health check
           r'/api/(.*)$',           # Allowing access to API
           r'/js/i18n/$',           # JavaScript localization
        ),
    )

# Authentication configuration
AUTHENTICATION_BACKENDS = ()

if 'WEBLATE_NO_EMAIL_AUTH' not in os.environ:
    AUTHENTICATION_BACKENDS += ('social_core.backends.email.EmailAuth',)

# Enable possibility of using other auth providers via configuration