Exemplo n.º 1
0
 def _check_caldav_config_validity(self) -> None:
     """
     Check if config is correctly setted for caldav features
     """
     if self.CALDAV__ENABLED:
         self.check_mandatory_param(
             "CALDAV__RADICALE_PROXY__BASE_URL",
             self.CALDAV__RADICALE_PROXY__BASE_URL,
             when_str="when caldav feature is enabled",
         )
         # TODO - G.M - 2019-05-06 - convert "caldav.radicale.storage.filesystem_folder"
         # as tracim global parameter
         self.check_mandatory_param(
             "CALDAV__RADICALE__STORAGE__FILESYSTEM_FOLDER",
             self.CALDAV__RADICALE__STORAGE__FILESYSTEM_FOLDER,
             when_str="if caldav feature is enabled",
         )
         self.check_directory_path_param(
             "CALDAV__RADICALE__STORAGE__FILESYSTEM_FOLDER",
             self.CALDAV__RADICALE__STORAGE__FILESYSTEM_FOLDER,
             writable=True,
         )
         radicale_storage_type = self.settings.get(
             "caldav.radicale.storage.type")
         if radicale_storage_type != "multifilesystem":
             raise ConfigurationError('"{}" should be set to "{}"'
                                      " (currently only valid value)"
                                      ' when "{}" is true'.format(
                                          "caldav.radicale.storage.type",
                                          "multifilesystem",
                                          "caldav.enabled"))
Exemplo n.º 2
0
 def check_config(self, app_config: CFG) -> None:
     """
     Check if config is correctly setted for caldav features
     """
     app_config.check_mandatory_param(
         "CALDAV__RADICALE_PROXY__BASE_URL",
         app_config.CALDAV__RADICALE_PROXY__BASE_URL,
         when_str="when caldav feature is enabled",
     )
     # TODO - G.M - 2019-05-06 - convert "caldav.radicale.storage.filesystem_folder"
     # as tracim global parameter
     app_config.check_mandatory_param(
         "CALDAV__RADICALE__STORAGE__FILESYSTEM_FOLDER",
         app_config.CALDAV__RADICALE__STORAGE__FILESYSTEM_FOLDER,
         when_str="if caldav feature is enabled",
     )
     app_config.check_directory_path_param(
         "CALDAV__RADICALE__STORAGE__FILESYSTEM_FOLDER",
         app_config.CALDAV__RADICALE__STORAGE__FILESYSTEM_FOLDER,
         writable=True,
     )
     radicale_storage_type = app_config.settings.get("caldav.radicale.storage.type")
     if radicale_storage_type != "multifilesystem":
         raise ConfigurationError(
             '"{}" should be set to "{}"'
             " (currently only valid value)"
             " when {} app is active".format(
                 "caldav.radicale.storage.type", "multifilesystem", "agenda"
             )
         )
Exemplo n.º 3
0
 def _check_caldav_config_validity(self) -> None:
     """
     Check if config is correctly setted for caldav features
     """
     if self.CALDAV__ENABLED and not self.CALDAV__RADICALE_PROXY__BASE_URL:
         raise ConfigurationError(
             "ERROR: Caldav radicale proxy cannot be activated if no radicale"
             'base url is configured. set "caldav.radicale_proxy.base_url" properly'
         )
Exemplo n.º 4
0
 def check_directory_path_param(self,
                                param_name: str,
                                path: str,
                                writable: bool = False,
                                readable: bool = True) -> None:
     """
     Check if path exist, if it is a directory and if it is readable/writable.
     if check fail, raise ConfigurationError
     :param param_name: name of parameter to check
     :param path: path (value of parameter) which is check as a directory path
     :param writable: check if directory(according to path) is writable
     :param readable: check if directory(according to path) is writable
     """
     try:
         is_dir_exist(path)
         if writable:
             is_dir_writable(path)
         if readable:
             is_dir_readable(path)
     except NotADirectoryError as exc:
         not_a_directory_msg = (
             'ERROR: "{}" is not a valid directory path, '
             'create it or change "{}" value in config '
             "to a valid directory path.")
         raise ConfigurationError(
             not_a_directory_msg.format(path, param_name)) from exc
     except NotWritableDirectory as exc:
         directory_not_writable_msg = (
             "ERROR: current user as not enough right to write and create file"
             ' into "{}" directory.'
             " Change permission of current user on this directory,"
             " change user running this code or change"
             ' directory path of parameter in config "{}" to solve this.')
         raise ConfigurationError(
             directory_not_writable_msg.format(path, param_name)) from exc
     except NotReadableDirectory as exc:
         directory_not_writable_msg = (
             "ERROR: current user as not enough right to read and/or open"
             ' "{}" directory.'
             " Change permission of current user on this directory,"
             " change user running this code or change"
             ' directory path of parameter in config "{}" to solve this.')
         raise ConfigurationError(
             directory_not_writable_msg.format(path, param_name)) from exc
Exemplo n.º 5
0
 def check_mandatory_param(self,
                           param_name: str,
                           value: typing.Any,
                           when_str: str = "") -> None:
     """
     Check if param value is not falsy value, if falsy, raise ConfigurationError
     :param param_name: name of the parameter
     :param value: value to check for parameter
     :param when_str: condition string to explain when parameter is mandatory
     """
     if not value:
         raise ConfigurationError(
             'ERROR: "{}" configuration is mandatory {when_str}.'
             "Set it before continuing.".format(param_name,
                                                when_str=when_str))
Exemplo n.º 6
0
    def _check_search_config_validity(self):
        search_engine_valid = ["elasticsearch", "simple"]
        if self.SEARCH__ENGINE not in search_engine_valid:

            search_engine_list_str = ", ".join(
                '"{}"'.format(engine) for engine in search_engine_valid)
            raise ConfigurationError(
                "ERROR: SEARCH__ENGINE valid values are {}.".format(
                    search_engine_list_str))
        # FIXME - G.M - 2019-06-07 - hack to force index document alias check validity
        # see https://github.com/tracim/tracim/issues/1835
        if self.SEARCH__ENGINE == "elasticsearch":
            self.check_mandatory_param(
                "SEARCH__ELASTICSEARCH__INDEX_ALIAS",
                self.SEARCH__ELASTICSEARCH__INDEX_ALIAS,
                when_str="if elasticsearch search feature is enabled",
            )
Exemplo n.º 7
0
 def check_config(self, app_config: CFG) -> None:
     # INFO - G.M - 2019-02-01 - check if template are available,
     # do not allow running with email_notification_activated
     # if templates needed are not available
     if app_config.EMAIL__NOTIFICATION__ACTIVATED:
         templates = {
             "upload_permission_to_emitter": app_config.EMAIL__NOTIFICATION__UPLOAD_PERMISSION_TO_EMITTER__TEMPLATE__HTML,
             "upload_permission_to_receiver": app_config.EMAIL__NOTIFICATION__UPLOAD_PERMISSION_TO_RECEIVER__TEMPLATE__HTML,
             "new_upload_event": app_config.EMAIL__NOTIFICATION__NEW_UPLOAD_EVENT__TEMPLATE__HTML,
         }
         for template_description, template_path in templates.items():
             if not template_path or not os.path.isfile(template_path):
                 raise ConfigurationError(
                     "ERROR: email template for {template_description} "
                     'not found at "{template_path}".'.format(
                         template_description=template_description, template_path=template_path
                     )
                 )
Exemplo n.º 8
0
    def _check_email_config_validity(self) -> None:
        """
        Check if config is correctly setted for email features
        """
        if not self.EMAIL__NOTIFICATION__ACTIVATED:
            logger.warning(
                self,
                "Notification by email mecanism is disabled ! "
                "Notification and mail invitation mecanisms will not work.",
            )

        if not self.EMAIL__REPLY__LOCKFILE_PATH and self.EMAIL__REPLY__ACTIVATED:
            self.check_mandatory_param(
                "EMAIL__REPLY__LOCKFILE_PATH",
                self.EMAIL__REPLY__LOCKFILE_PATH,
                when_str="when email reply is activated",
            )
        # INFO - G.M - 2019-02-01 - check if template are available,
        # do not allow running with email_notification_activated
        # if templates needed are not available
        if self.EMAIL__NOTIFICATION__ACTIVATED:
            templates = {
                "content_update notification":
                self.EMAIL__NOTIFICATION__CONTENT_UPDATE__TEMPLATE__HTML,
                "created account":
                self.EMAIL__NOTIFICATION__CREATED_ACCOUNT__TEMPLATE__HTML,
                "password reset":
                self.
                EMAIL__NOTIFICATION__RESET_PASSWORD_REQUEST__TEMPLATE__HTML,
            }
            for template_description, template_path in templates.items():
                if not template_path or not os.path.isfile(template_path):
                    raise ConfigurationError(
                        "ERROR: email template for {template_description} "
                        'not found at "{template_path}."'.format(
                            template_description=template_description,
                            template_path=template_path))

        if self.EMAIL__PROCESSING_MODE not in (self.CST.ASYNC, self.CST.SYNC):
            raise Exception("EMAIL__PROCESSING_MODE "
                            "can "
                            'be "{}" or "{}", not "{}"'.format(
                                self.CST.ASYNC, self.CST.SYNC,
                                self.EMAIL__PROCESSING_MODE))
Exemplo n.º 9
0
 def create_dir_tree(self, radicale_config: ConfigParser, app_config: CFG):
     # FIXME - G.M - 2019-03-08 - create dir tree if not exist in order
     # to allow item creation without trouble in radicale
     storage_path = radicale_config.get("storage", "filesystem_folder")
     sub_dir_storage_path = os.path.join(storage_path, "collection-root")
     parent_folder = os.path.dirname(storage_path)
     if not os.path.isdir(parent_folder):
         raise ConfigurationError(
             "{} is not a correct folder, can't set properly storage folder of radicale"
             .format(parent_folder))
     user_dir = os.path.join(
         sub_dir_storage_path,
         app_config.CALDAV__RADICALE__AGENDA_DIR,
         app_config.CALDAV__RADICALE__USER_SUBDIR,
     )
     os.makedirs(user_dir, exist_ok=True)
     workspace_dir = os.path.join(
         sub_dir_storage_path,
         app_config.CALDAV__RADICALE__AGENDA_DIR,
         app_config.CALDAV__RADICALE__WORKSPACE_SUBDIR,
     )
     os.makedirs(workspace_dir, exist_ok=True)
Exemplo n.º 10
0
    def _check_global_config_validity(self) -> None:
        """
        Check config for global stuff
        """
        self.check_mandatory_param("SQLALCHEMY__URL", self.SQLALCHEMY__URL)
        self.check_mandatory_param("SESSION__DATA_DIR", self.SESSION__DATA_DIR)
        self.check_directory_path_param("SESSION__DATA_DIR",
                                        self.SESSION__DATA_DIR,
                                        writable=True)

        self.check_mandatory_param("SESSION__LOCK_DIR", self.SESSION__LOCK_DIR)
        self.check_directory_path_param("SESSION__LOCK_DIR",
                                        self.SESSION__LOCK_DIR,
                                        writable=True)
        # INFO - G.M - 2019-04-03 - check color file validity
        self.check_mandatory_param("COLOR__CONFIG_FILE_PATH",
                                   self.COLOR__CONFIG_FILE_PATH)
        if not os.path.exists(self.COLOR__CONFIG_FILE_PATH):
            raise ConfigurationError(
                "ERROR: {} file does not exist. "
                'please create it or set "COLOR__CONFIG_FILE_PATH"'
                "with a correct value".format(self.COLOR__CONFIG_FILE_PATH))

        try:
            with open(self.COLOR__CONFIG_FILE_PATH) as json_file:
                self.APPS_COLORS = json.load(json_file)
        except Exception as e:
            raise ConfigurationError(
                "Error: {} file could not be load as json".format(
                    self.COLOR__CONFIG_FILE_PATH)) from e

        try:
            self.APPS_COLORS["primary"]
        except KeyError as e:
            raise ConfigurationError(
                "Error: primary color is required in {} file".format(
                    self.COLOR__CONFIG_FILE_PATH)) from e

        self.check_mandatory_param("DEPOT_STORAGE_DIR", self.DEPOT_STORAGE_DIR)
        self.check_directory_path_param("DEPOT_STORAGE_DIR",
                                        self.DEPOT_STORAGE_DIR,
                                        writable=True)

        self.check_mandatory_param("DEPOT_STORAGE_NAME",
                                   self.DEPOT_STORAGE_NAME)

        self.check_mandatory_param("PREVIEW_CACHE_DIR", self.PREVIEW_CACHE_DIR)
        self.check_directory_path_param("PREVIEW_CACHE_DIR",
                                        self.PREVIEW_CACHE_DIR,
                                        writable=True)

        if AuthType.REMOTE is self.AUTH_TYPES:
            raise ConfigurationError(
                'ERROR: "remote" auth not allowed in auth_types'
                " list, use remote_user_header instead")

        self.check_mandatory_param("WEBSITE__BASE_URL", self.WEBSITE__BASE_URL)

        self.check_mandatory_param("BACKEND__I18N_FOLDER_PATH",
                                   self.BACKEND__I18N_FOLDER_PATH)
        self.check_directory_path_param("BACKEND__I18N_FOLDER_PATH",
                                        self.BACKEND__I18N_FOLDER_PATH,
                                        readable=True)

        # INFO - G.M - 2018-08-06 - We check dist folder existence
        if self.FRONTEND__SERVE:
            self.check_mandatory_param(
                "FRONTEND__DIST_FOLDER_PATH",
                self.FRONTEND__DIST_FOLDER_PATH,
                when_str="if frontend serving is activated",
            )
            self.check_directory_path_param("FRONTEND__DIST_FOLDER_PATH",
                                            self.FRONTEND__DIST_FOLDER_PATH)
Exemplo n.º 11
0
    def _load_email_config(self) -> None:
        """
        Load config for email related stuff
        """
        # TODO - G.M - 27-03-2018 - [Email] Restore email config
        ###
        # EMAIL related stuff (notification, reply)
        ##
        self.EMAIL__NOTIFICATION__ENABLED_ON_INVITATION = asbool(
            self.get_raw_config("email.notification.enabled_on_invitation",
                                "true"))

        # TODO - G.M - 2019-04-05 - keep as parameters
        # or set it as constant,
        # see https://github.com/tracim/tracim/issues/1569
        self.EMAIL__NOTIFICATION__NOTIFIED_EVENTS = [
            ActionDescription.COMMENT,
            ActionDescription.CREATION,
            ActionDescription.EDITION,
            ActionDescription.REVISION,
            ActionDescription.STATUS_UPDATE,
        ]
        # TODO - G.M - 2019-04-04 - need to be better handled:
        # dynamic default value and allow user to set this value.
        # see :https://github.com/tracim/tracim/issues/1555
        self.EMAIL__NOTIFICATION__NOTIFIED_CONTENTS = [
            "html-document",
            "thread",
            "file",
            "comment",
            # 'folder' --folder is skipped
        ]

        self.EMAIL__NOTIFICATION__FROM__EMAIL = self.get_raw_config(
            "email.notification.from.email", "noreply+{user_id}@trac.im")
        self.EMAIL__NOTIFICATION__FROM = self.get_raw_config(
            "email.notification.from")
        if self.get_raw_config("email.notification.from"):
            raise ConfigurationError(
                "email.notification.from configuration is deprecated. "
                "Use instead email.notification.from.email and "
                "email.notification.from.default_label.")

        self.EMAIL__NOTIFICATION__FROM__DEFAULT_LABEL = self.get_raw_config(
            "email.notification.from.default_label", "Tracim Notifications")
        self.EMAIL__NOTIFICATION__REPLY_TO__EMAIL = self.get_raw_config(
            "email.notification.reply_to.email")
        self.EMAIL__NOTIFICATION__REFERENCES__EMAIL = self.get_raw_config(
            "email.notification.references.email")
        # Content update notification

        self.EMAIL__NOTIFICATION__CONTENT_UPDATE__TEMPLATE__HTML = self.get_raw_config(
            "email.notification.content_update.template.html")

        self.EMAIL__NOTIFICATION__CONTENT_UPDATE__SUBJECT = self.get_raw_config(
            "email.notification.content_update.subject",
            _("[{website_title}] [{workspace_label}] {content_label} ({content_status_label})"
              ),
        )
        # Created account notification
        self.EMAIL__NOTIFICATION__CREATED_ACCOUNT__TEMPLATE__HTML = self.get_raw_config(
            "email.notification.created_account.template.html")
        self.EMAIL__NOTIFICATION__CREATED_ACCOUNT__SUBJECT = self.get_raw_config(
            "email.notification.created_account.subject",
            _("[{website_title}] Someone created an account for you"),
        )

        # Reset password notification
        self.EMAIL__NOTIFICATION__RESET_PASSWORD_REQUEST__TEMPLATE__HTML = self.get_raw_config(
            "email.notification.reset_password_request.template.html")
        self.EMAIL__NOTIFICATION__RESET_PASSWORD_REQUEST__SUBJECT = self.get_raw_config(
            "email.notification.reset_password_request.subject",
            _("[{website_title}] A password reset has been requested"),
        )

        # TODO - G.M - 2019-01-22 - add feature to process notification email
        # asynchronously see issue https://github.com/tracim/tracim/issues/1345
        self.EMAIL__NOTIFICATION__PROCESSING_MODE = "sync"
        self.EMAIL__NOTIFICATION__ACTIVATED = asbool(
            self.get_raw_config("email.notification.activated"))

        self.EMAIL__NOTIFICATION__SMTP__SERVER = self.get_raw_config(
            "email.notification.smtp.server")
        self.EMAIL__NOTIFICATION__SMTP__PORT = self.get_raw_config(
            "email.notification.smtp.port")
        self.EMAIL__NOTIFICATION__SMTP__USER = self.get_raw_config(
            "email.notification.smtp.user")
        self.EMAIL__NOTIFICATION__SMTP__PASSWORD = self.get_raw_config(
            "email.notification.smtp.password", secret=True)

        self.EMAIL__REPLY__ACTIVATED = asbool(
            self.get_raw_config("email.reply.activated", "false"))

        self.EMAIL__REPLY__IMAP__SERVER = self.get_raw_config(
            "email.reply.imap.server")
        self.EMAIL__REPLY__IMAP__PORT = self.get_raw_config(
            "email.reply.imap.port")
        self.EMAIL__REPLY__IMAP__USER = self.get_raw_config(
            "email.reply.imap.user")
        self.EMAIL__REPLY__IMAP__PASSWORD = self.get_raw_config(
            "email.reply.imap.password", secret=True)
        self.EMAIL__REPLY__IMAP__FOLDER = self.get_raw_config(
            "email.reply.imap.folder")
        self.EMAIL__REPLY__CHECK__HEARTBEAT = int(
            self.get_raw_config("email.reply.check.heartbeat", "60"))
        self.EMAIL__REPLY__IMAP__USE_SSL = asbool(
            self.get_raw_config("email.reply.imap.use_ssl"))
        self.EMAIL__REPLY__IMAP__USE_IDLE = asbool(
            self.get_raw_config("email.reply.imap.use_idle", "true"))
        self.EMAIL__REPLY__CONNECTION__MAX_LIFETIME = int(
            self.get_raw_config("email.reply.connection.max_lifetime",
                                "600")  # 10 minutes
        )
        self.EMAIL__REPLY__USE_HTML_PARSING = asbool(
            self.get_raw_config("email.reply.use_html_parsing", "true"))
        self.EMAIL__REPLY__USE_TXT_PARSING = asbool(
            self.get_raw_config("email.reply.use_txt_parsing", "true"))
        self.EMAIL__REPLY__LOCKFILE_PATH = self.get_raw_config(
            "email.reply.lockfile_path", "")

        self.EMAIL__PROCESSING_MODE = self.get_raw_config(
            "email.processing_mode", "sync").upper()

        self.EMAIL__ASYNC__REDIS__HOST = self.get_raw_config(
            "email.async.redis.host", "localhost")
        self.EMAIL__ASYNC__REDIS__PORT = int(
            self.get_raw_config("email.async.redis.port", "6379"))
        self.EMAIL__ASYNC__REDIS__DB = int(
            self.get_raw_config("email.async.redis.db", "0"))
        self.NEW_USER__INVITATION__DO_NOTIFY = asbool(
            self.get_raw_config("new_user.invitation.do_notify", "True"))

        self.NEW_USER__INVITATION__MINIMAL_PROFILE = self.get_raw_config(
            "new_user.invitation.minimal_profile", Group.TIM_MANAGER_GROUPNAME)
Exemplo n.º 12
0
    def _check_email_config_validity(self) -> None:
        """
        Check if config is correctly setted for email features
        """
        if not self.EMAIL__NOTIFICATION__ACTIVATED:
            logger.warning(
                self,
                "Notification by email mechanism is disabled! "
                "Notification and mail invitation mechanisms will not work.",
            )

        if not self.EMAIL__REPLY__LOCKFILE_PATH and self.EMAIL__REPLY__ACTIVATED:
            self.check_mandatory_param(
                "EMAIL__REPLY__LOCKFILE_PATH",
                self.EMAIL__REPLY__LOCKFILE_PATH,
                when_str="when email reply is activated",
            )

        if self.EMAIL__REPLY__ACTIVATED:
            # INFO - G.M - 2019-12-10 - check imap config provided
            self.check_mandatory_param(
                "EMAIL__REPLY__IMAP__SERVER",
                self.EMAIL__REPLY__IMAP__SERVER,
                when_str="when email notification is activated",
            )
            self.check_mandatory_param(
                "EMAIL__REPLY__IMAP__PORT",
                self.EMAIL__REPLY__IMAP__PORT,
                when_str="when email notification is activated",
            )
            self.check_mandatory_param(
                "EMAIL__REPLY__IMAP__USER",
                self.EMAIL__REPLY__IMAP__USER,
                when_str="when email notification is activated",
            )
            self.check_mandatory_param(
                "EMAIL__REPLY__IMAP__PASSWORD",
                self.EMAIL__REPLY__IMAP__PASSWORD,
                when_str="when email notification is activated",
            )
            self.check_mandatory_param(
                "EMAIL__REPLY__IMAP__FOLDER",
                self.EMAIL__REPLY__IMAP__FOLDER,
                when_str="when email notification is activated",
            )

        if self.EMAIL__NOTIFICATION__ACTIVATED:
            # INFO - G.M - 2019-12-10 - check smtp config provided
            self.check_mandatory_param(
                "EMAIL__NOTIFICATION__SMTP__SERVER",
                self.EMAIL__NOTIFICATION__SMTP__SERVER,
                when_str="when email notification is activated",
            )
            self.check_mandatory_param(
                "EMAIL__NOTIFICATION__SMTP__PORT",
                self.EMAIL__NOTIFICATION__SMTP__PORT,
                when_str="when email notification is activated",
            )
            self.check_mandatory_param(
                "EMAIL__NOTIFICATION__SMTP__USER",
                self.EMAIL__NOTIFICATION__SMTP__USER,
                when_str="when email notification is activated",
            )
            self.check_mandatory_param(
                "EMAIL__NOTIFICATION__SMTP__PASSWORD",
                self.EMAIL__NOTIFICATION__SMTP__PASSWORD,
                when_str="when email notification is activated",
            )
            # INFO - G.M - 2019-12-10 - check value provided for headers
            self.check_mandatory_param(
                "EMAIL__NOTIFICATION__FROM__EMAIL",
                self.EMAIL__NOTIFICATION__FROM__EMAIL,
                when_str="when email notification is activated",
            )
            self.check_mandatory_param(
                "EMAIL__NOTIFICATION__FROM__DEFAULT_LABEL",
                self.EMAIL__NOTIFICATION__FROM__DEFAULT_LABEL,
                when_str="when email notification is activated",
            )
            self.check_mandatory_param(
                "EMAIL__NOTIFICATION__REPLY_TO__EMAIL",
                self.EMAIL__NOTIFICATION__REPLY_TO__EMAIL,
                when_str="when email notification is activated",
            )
            self.check_mandatory_param(
                "EMAIL__NOTIFICATION__REFERENCES__EMAIL",
                self.EMAIL__NOTIFICATION__REFERENCES__EMAIL,
                when_str="when email notification is activated",
            )
            # INFO - G.M - 2019-02-01 - check if template are available,
            # do not allow running with email_notification_activated
            # if templates needed are not available
            templates = {
                "content_update notification":
                self.EMAIL__NOTIFICATION__CONTENT_UPDATE__TEMPLATE__HTML,
                "created account":
                self.EMAIL__NOTIFICATION__CREATED_ACCOUNT__TEMPLATE__HTML,
                "password reset":
                self.
                EMAIL__NOTIFICATION__RESET_PASSWORD_REQUEST__TEMPLATE__HTML,
            }
            for template_description, template_path in templates.items():
                if not template_path or not os.path.isfile(template_path):
                    raise ConfigurationError(
                        "ERROR: email template for {template_description} "
                        'not found at "{template_path}."'.format(
                            template_description=template_description,
                            template_path=template_path,
                        ))
Exemplo n.º 13
0
    def _check_global_config_validity(self) -> None:
        """
        Check config for global stuff
        """
        self.check_mandatory_param("SQLALCHEMY__URL", self.SQLALCHEMY__URL)
        self.check_mandatory_param("SESSION__TYPE", self.SESSION__TYPE)
        if self.SESSION__TYPE == "file":
            self.check_mandatory_param(
                "SESSION__DATA_DIR",
                self.SESSION__DATA_DIR,
                when_str="if session type is file",
            )
            self.check_directory_path_param("SESSION__DATA_DIR",
                                            self.SESSION__DATA_DIR,
                                            writable=True)
        elif self.SESSION__TYPE in [
                "ext:database",
                "ext:mongodb",
                "ext:redis",
                "ext:memcached",
        ]:
            self.check_mandatory_param(
                "SESSION__URL",
                self.SESSION__URL,
                when_str="if session type is {}".format(self.SESSION__TYPE),
            )
        self.check_mandatory_param("SESSION__LOCK_DIR", self.SESSION__LOCK_DIR)
        self.check_directory_path_param("SESSION__LOCK_DIR",
                                        self.SESSION__LOCK_DIR,
                                        writable=True)
        # INFO - G.M - 2019-04-03 - check color file validity
        self.check_mandatory_param("COLOR__CONFIG_FILE_PATH",
                                   self.COLOR__CONFIG_FILE_PATH)
        if not os.path.exists(self.COLOR__CONFIG_FILE_PATH):
            raise ConfigurationError(
                "ERROR: {} file does not exist. "
                'please create it or set "COLOR__CONFIG_FILE_PATH"'
                "with a correct value".format(self.COLOR__CONFIG_FILE_PATH))

        try:
            with open(self.COLOR__CONFIG_FILE_PATH) as json_file:
                self.APPS_COLORS = json.load(json_file)
        except Exception as e:
            raise ConfigurationError(
                "Error: {} file could not be load as json".format(
                    self.COLOR__CONFIG_FILE_PATH)) from e

        try:
            self.APPS_COLORS["primary"]
        except KeyError as e:
            raise ConfigurationError(
                "Error: primary color is required in {} file".format(
                    self.COLOR__CONFIG_FILE_PATH)) from e

        self.check_mandatory_param("DEPOT_STORAGE_DIR", self.DEPOT_STORAGE_DIR)
        self.check_directory_path_param("DEPOT_STORAGE_DIR",
                                        self.DEPOT_STORAGE_DIR,
                                        writable=True)

        self.check_mandatory_param("DEPOT_STORAGE_NAME",
                                   self.DEPOT_STORAGE_NAME)

        self.check_mandatory_param("PREVIEW_CACHE_DIR", self.PREVIEW_CACHE_DIR)
        self.check_directory_path_param("PREVIEW_CACHE_DIR",
                                        self.PREVIEW_CACHE_DIR,
                                        writable=True)

        if AuthType.REMOTE is self.AUTH_TYPES:
            raise ConfigurationError(
                'ERROR: "remote" auth not allowed in auth_types'
                " list, use remote_user_header instead")

        self.check_mandatory_param("WEBSITE__BASE_URL", self.WEBSITE__BASE_URL)

        self.check_mandatory_param("BACKEND__I18N_FOLDER_PATH",
                                   self.BACKEND__I18N_FOLDER_PATH)
        self.check_directory_path_param("BACKEND__I18N_FOLDER_PATH",
                                        self.BACKEND__I18N_FOLDER_PATH,
                                        readable=True)

        # INFO - G.M - 2018-08-06 - We check dist folder existence
        if self.FRONTEND__SERVE:
            self.check_mandatory_param(
                "FRONTEND__DIST_FOLDER_PATH",
                self.FRONTEND__DIST_FOLDER_PATH,
                when_str="if frontend serving is activated",
            )
            self.check_directory_path_param("FRONTEND__DIST_FOLDER_PATH",
                                            self.FRONTEND__DIST_FOLDER_PATH)

        if self.USER__DEFAULT_PROFILE not in Profile.get_all_valid_slugs():
            profile_str_list = ", ".join([
                '"{}"'.format(profile_name)
                for profile_name in Profile.get_all_valid_slugs()
            ])
            raise ConfigurationError(
                'ERROR user.default_profile given "{}" is invalid,'
                "valids values are {}.".format(self.USER__DEFAULT_PROFILE,
                                               profile_str_list))
Exemplo n.º 14
0
Arquivo: env.py Projeto: inkhey/tracim
from tracim_backend.exceptions import ConfigurationError
from tracim_backend.models.meta import metadata
from tracim_backend.models.setup_models import *  # noqa: F403,F401

# from logging.config import fileConfig

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
# INFO - G.M - 2019-05-02 - hack to get env url instead of current config file
# url for migration script
env_sqlalchemy_url = os.environ.get("TRACIM_SQLALCHEMY__URL")
if env_sqlalchemy_url:
    config.set_main_option("sqlalchemy.url", env_sqlalchemy_url)
if not config.get_main_option("sqlalchemy.url"):
    raise ConfigurationError("SQLALCHEMY__URL is mandatory")
# Interpret the config file for Python logging.
# This line sets up loggers basically.
# fileConfig(config.config_file_name)

# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata

target_metadata = metadata

# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.