示例#1
0
    def create_group(self):
        """
        Create a new user group
        :return: None
        """
        sql = open_sql_file('create_group').format(self.group_name)
        self.redshift.query(sql)
        print('Group {} created.'.format(self.group_name))

        return
示例#2
0
    def _add_user_to_read_only_group(self):
        """
        Add a user to read only group permissions
        :return: None
        """
        sql = open_sql_file('add_user_read_only_group').format(self.username)
        self.redshift.query(sql)
        print('User {} added to group read_only.'.format(self.username))

        return
示例#3
0
    def create_read_only_schema(self, owner_user):
        """
        Create a new schema and add it to read_only group
        :param owner_user: <string> user that will own the schema and have all privileges.
        :return: None
        """
        sql = open_sql_file('create_read_only_schema').format(self.schema_name, owner_user)
        self.redshift.query(sql)
        print('Schema {} created.'.format(self.schema_name))

        return
示例#4
0
    def remove_user(self):
        """
        Removes a user from group and then drops it
        :return: None
        """
        sql = open_sql_file('remove_user').format(self.username)

        self.redshift.query(sql)
        print('User {} dropped.'.format(self.username))

        return
示例#5
0
    def add_user(self):
        """
        Add user to redshift, with random password and send email with connection data.
        :return: None
        """
        password = Password().str

        sql = open_sql_file('create_user').format(self.username, password)
        self.redshift.query(sql)
        print('User {} created with password "{}" (without quotes).'.format(self.username, password))

        if self.sendmail:
            sendgrid = SendGrid(self.email)
            sendgrid.send_usercreated_mail(self.username, password)

        if self.access_level == 'read_only':
            self._add_user_to_read_only_group()

        return
示例#6
0
 def _read_only_group_exists(self):
     sql = open_sql_file('check_read_only_exists')
     return self.redshift.query(sql).fetchone()[0]