Пример #1
0
    def patch_attributes(self, attributes):
        # import privileges into class
        self.available_privs = AVAILABLE_PRIVS.copy()
        self.available_db_privs = AVAILABLE_DB_PRIVS.copy()
        self.sql_available_privs = SQL_AVAILABLE_PRIVS.copy()
        self.sql_available_db_privs = SQL_AVAILABLE_DB_PRIVS.copy()

        if self.node.os == 'debian' and self.node.os_version[0] >= 10:
            self.available_privs += [
                'Delete_history_priv',  # MariaDB > 1.5
            ]
            self.sql_available_privs[
                'Delete_history_priv'] = 'DELETE HISTORY'  # MariaDB > 1.5

            self.available_db_privs += [
                'Delete_history_priv',  # MariaDB > 1.5
            ]

            self.sql_available_db_privs[
                'Delete_history_priv'] = 'DELETE HISTORY'  # since MariaDB > 1.5

        if 'password' in attributes and attributes['password'] != '':
            attributes['password_hash'] = mysql_context.encrypt(
                force_text(attributes['password']))
        # sort hosts, since they do not depent in order
        if 'hosts' in attributes:
            attributes['hosts'] = sorted(attributes['hosts'])

        if 'superuser' in attributes and attributes['superuser']:
            attributes['privileges'] = AVAILABLE_PRIVS.copy()

        if attributes.get('db_priv', None) is None:
            attributes['db_priv'] = {}

        if 'db_priv' in attributes:
            for db, rights in attributes['db_priv'].items():
                if rights == 'all':
                    attributes['db_priv'][db] = self.available_db_privs.copy()
                elif type(attributes['db_priv'][db]) is not list:
                    attributes['db_priv'][db] = []

        return attributes
Пример #2
0
def insert_default(target, connection, **kw):
    default_user = User("admin", pwd_context.encrypt("admin"))
    db.session.add(default_user)
    db.session.commit()
Пример #3
0
 def hash_passwd(self, passwd):
     self.passwd = pwd_context.encrypt(passwd)
Пример #4
0
 def hash_password(self, password):
     self.password_hash = pwd_context.encrypt(password)