Beispiel #1
0
    def index(self, connection=None, cmd=None):

        user = cherrypy.session.get("user")

        if not user:
            raise cherrypy.HTTPError(403, "No user in session. Probably authentication was not configured.")

        result = None

        connections = list(self.get_connections(user))

        if not connections:
            raise cherrypy.HTTPError(
                403,
                "No Redis database connection is configured for you. Probably you are lacking the right LDAP groups.",
            )

        args = None
        if connection and cmd:
            connection = Connection.from_str(connection)

            cmd, args = self.parse_cmd(cmd)

            if cmd not in READ_COMMANDS | WRITE_COMMANDS:
                raise cherrypy.HTTPError(400, "Unsupported Redis command")

            if not self.has_access(user, connection, cmd):
                raise cherrypy.HTTPError(
                    403,
                    'You are not allowed to execute the command "{}" on Redis database "{}"'.format(cmd, connection),
                )

            con = redis.StrictRedis(connection.host, connection.port, connection.db)
            try:
                if cmd not in READ_COMMANDS:
                    raise ValueError("Invalid command")
                result = con.execute_command(cmd, *args)
                result = json.dumps(result, indent=4)
            except Exception, e:
                result = str(e)
Beispiel #2
0
 def get_connections(self, user):
     for grp in user.groupnames:
         yield Connection.from_group_name(grp)