1
0
mirror of https://github.com/etesync/server synced 2024-12-29 10:48:07 +00:00
etesync-server/django_etebase/app_settings.py

55 lines
1.9 KiB
Python
Raw Normal View History

2020-02-19 18:53:43 +00:00
# Copyright © 2017 Tom Hacohen
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, version 3.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
class AppSettings:
def __init__(self, prefix):
self.prefix = prefix
def import_from_str(self, name):
from importlib import import_module
2020-02-26 12:32:25 +00:00
path, prop = name.rsplit('.', 1)
2020-02-19 18:53:43 +00:00
2020-02-26 12:32:25 +00:00
mod = import_module(path)
return getattr(mod, prop)
2020-02-19 18:53:43 +00:00
def _setting(self, name, dflt):
from django.conf import settings
return getattr(settings, self.prefix + name, dflt)
@property
2020-02-26 12:32:25 +00:00
def API_PERMISSIONS(self): # pylint: disable=invalid-name
2020-02-19 18:53:43 +00:00
perms = self._setting("API_PERMISSIONS", ('rest_framework.permissions.IsAuthenticated', ))
ret = []
for perm in perms:
ret.append(self.import_from_str(perm))
return ret
@property
2020-02-26 12:32:25 +00:00
def API_AUTHENTICATORS(self): # pylint: disable=invalid-name
2020-02-19 18:53:43 +00:00
perms = self._setting("API_AUTHENTICATORS", ('rest_framework.authentication.TokenAuthentication',
'rest_framework.authentication.SessionAuthentication'))
ret = []
for perm in perms:
ret.append(self.import_from_str(perm))
return ret
2020-05-14 10:43:49 +00:00
@property
def CHALLENGE_VALID_SECONDS(self): # pylint: disable=invalid-name
return self._setting("CHALLENGE_VALID_SECONDS", 60)
2020-02-19 18:53:43 +00:00
app_settings = AppSettings('ETEBASE_')