Example #1
0
    def dump_models(self, expected):

        expected_dict = { 'itip' : InternalTip,
                          'wtip' : WhistleblowerTip,
                          'rtip' : ReceiverTip,
                          'receivers' : Receiver,
                          'comment' : Comment,
                          'profiles' : PluginProfiles,
                          'rcfg' : ReceiverConfs,
                          'file' : File,
                          'submission' : Submission,
                          'contexts' : Context }

        outputDict = {}
        self.returnCode(200)

        store = self.getStore()

        if expected in ['count', 'all']:

            for key, object in expected_dict.iteritems():
                info_list = object(store).get_all()

                if expected == 'all':
                    outputDict.update({key : info_list})

                outputDict.update({("%s_elements" % key) : len(info_list) })

            self.returnData(outputDict)
            return self.prepareRetVals()

        # XXX plugins is not dumped with all or count!
        if expected == 'plugins':

            info_list = PluginManager.get_all()
            outputDict.update({expected : info_list, ("%s_elements" % expected) : len(info_list) })

            self.returnData(outputDict)
            return self.prepareRetVals()

        if expected_dict.has_key(expected):

            info_list = expected_dict[expected](store).get_all()
            outputDict.update({expected : info_list, ("%s_elements" % expected) : len(info_list) })

            self.returnData(outputDict)
            return self.prepareRetVals()

        raise InvalidInputFormat("Not acceptable '%s'" % expected)
Example #2
0
    def get(self, *uriargs):
        """
        Parameters: None
        Response: adminPluginList
        Errors: None

        This handler is one of the few that do not operate versus the database model, but in
        the filesystem. Checks the plugin presents in the appropriate directory and return
        a list with name and properties.
        """

        plugin_descriptive_list = yield PluginManager.get_all()
        # TODO output validation - adminPluginList

        self.set_status(200)
        self.write(json.dumps(plugin_descriptive_list))
        self.finish()
Example #3
0
    def get(self, what, *uriargs):
        """
        Parameters: None
        Response: Unknown
        Errors: None

        /dump/overview GET should return up to all the tables of GLBackend
        """

        expected = [ 'itip', 'wtip', 'rtip', 'receivers', 'comment',
                     'profiles', 'rcfg', 'file', 'submission', 'contexts', 'plugins', 'all', 'count' ]

        outputDict = {}

        if what == 'receivers' or what == 'all' or what == 'count':
            receiver_iface = Receiver()
            receiver_list = yield receiver_iface.get_all()

            if what != 'count':
                outputDict.update({ 'receivers_elements' : len(receiver_list), 'receivers' : receiver_list})
            else:
                outputDict.update({ 'receivers_elements' : len(receiver_list)})

        if what == 'itip' or what == 'all' or what == 'count':
            itip_iface = InternalTip()
            itip_list = yield itip_iface.get_all()

            if what != 'count':
                outputDict.update({ 'internaltips_elements' : len(itip_list), 'internaltips' : itip_list })
            else:
                outputDict.update({ 'internaltips_elements' : len(itip_list)})

        if what == 'rtip' or what == 'all' or what == 'count':
            rtip_iface = ReceiverTip()
            rtip_list = yield rtip_iface.get_all()

            if what != 'count':
                outputDict.update({ 'rtip_elements' : len(rtip_list), 'receivers_tips' : rtip_list })
            else:
                outputDict.update({ 'rtip_elements' : len(rtip_list)})

        if what == 'wtip' or what == 'all' or what == 'count':
            wtip_iface = WhistleblowerTip()
            wtip_list = yield wtip_iface.get_all()

            if what != 'count':
                outputDict.update({ 'wtip_elements' : len(wtip_list), 'whistleblower_tips' : wtip_list })
            else:
                outputDict.update({ 'wtip_elements' : len(wtip_list)})

        if what == 'comment' or what == 'all' or what == 'count':
            comment_iface = Comment()
            comment_list = yield comment_iface.get_all()

            if what != 'count':
                outputDict.update({ 'comment_elements' : len(comment_list), 'comments' : comment_list })
            else:
                outputDict.update({ 'comment_elements' : len(comment_list)})

        if what == 'profiles' or what == 'all' or what == 'count':
            profile_iface = PluginProfiles()
            profile_list = yield profile_iface.get_all()

            if what != 'count':
                outputDict.update({ 'profiles_elements' : len(profile_list), 'profiles' : profile_list })
            else:
                outputDict.update({ 'profiles_elements' : len(profile_list)})

        if what == 'plugins' or what == 'all' or what == 'count':
            plugin_list = yield PluginManager.get_all()

            if what != 'count':
                outputDict.update({ 'plugins_elements' : len(plugin_list), 'plugins' : plugin_list })
            else:
                outputDict.update({ 'plugins_elements' : len(plugin_list) })

        if what == 'rcfg' or what == 'all' or what == 'count':
            rconf_iface = ReceiverConfs()
            rconf_list = yield rconf_iface.get_all()

            if what != 'count':
                outputDict.update({ 'rcfg_elements' : len(rconf_list), 'settings' : rconf_list })
            else:
                outputDict.update({ 'rcfg_elements' : len(rconf_list)})

        if what == 'submission' or what == 'all' or what == 'count':
            submission_iface = Submission()
            submission_list = yield submission_iface.get_all()

            if what != 'count':
                outputDict.update({ 'submission_elements' : len(submission_list), 'submissions' : submission_list })
            else:
                outputDict.update({ 'submission_elements' : len(submission_list)})

        if what == 'file' or what == 'all' or what == 'count':
            file_iface = File()
            file_list = yield file_iface.get_all()

            if what != 'count':
                outputDict.update({ 'file_elements' : len(file_list), 'files' : file_list })
            else:
                outputDict.update({ 'file_elements' : len(file_list)})

        if what == 'contexts' or what == 'all' or what == 'count':
            context_iface = Context()
            context_list = yield context_iface.get_all()

            if what != 'count':
                outputDict.update({ 'contexts_elements' : len(context_list), 'contexts' : context_list })
            else:
                outputDict.update({ 'contexts_elements' : len(context_list)})


        if not what in expected:
            self.set_status(405)
        else:
            self.set_status(200)
            self.write(outputDict)

        self.finish()