Exemple #1
0
    def POST(self, consumer_id):
        """
        Create a bind association between the specified
        consumer by id included in the URL path and a repo-distributor
        specified in the POST body: {repo_id:<str>, distributor_id:<str>}.
        Designed to be idempotent so only MissingResource is expected to
        be raised by manager.
        @param consumer_id: The consumer to bind.
        @type consumer_id: str
        @return: A call_report
        @rtype: TaskResult
        """
        # get other options and validate them
        body = self.params()
        repo_id = body.get('repo_id')
        distributor_id = body.get('distributor_id')
        binding_config = body.get('binding_config', {})
        options = body.get('options', {})
        notify_agent = body.get('notify_agent', True)

        if not isinstance(binding_config, dict):
            raise BadRequest()

        call_report = consumer.bind(
            consumer_id, repo_id, distributor_id, notify_agent, binding_config, options)

        if call_report.spawned_tasks:
            raise OperationPostponed(call_report)
        else:
            return self.ok(call_report.serialize())
Exemple #2
0
 def POST(self, consumer_group_id, action):
     """
     Content actions.
     """
     method = getattr(self, action, None)
     if method:
         return method(consumer_group_id)
     else:
         raise BadRequest()
 def POST(self):
     auth = web.ctx.env.get('HTTP_AUTHORIZATION')
     if self.authorized(auth):
         try:
             data = web.input()
             bathroom_name = data.BathroomName
             occupied = data.Occupied
             if occupied.lower() not in ('true', 'false'):
                 return BadRequest()
             bathroom_available = web.config.bathroom_available
             bathroom_available.update(occupied.lower() == 'true',
                                       str(bathroom_name))
             web.header('Content-Type', 'application/json')
             return json.dumps(bathroom_available.status())
         except AttributeError:
             return BadRequest()
     else:
         return Unauthorized()
Exemple #4
0
 def POST(self, action):
     """
     Content source actions.
     :param action: Name of action to perform
     :type action: str
     """
     method = getattr(self, action, None)
     if method:
         return method()
     else:
         raise BadRequest()
Exemple #5
0
 def POST(self, source_id, action):
     """
     Content source actions.
     """
     container = ContentContainer()
     source = container.sources.get(source_id)
     if source:
         method = getattr(self, action, None)
         if method:
             return method(source_id)
         else:
             raise BadRequest()
     else:
         raise MissingResource(source_id=source_id)
Exemple #6
0
    def GET(self, method, ignore_me=None, parameters_raw=None):
        try:
            handler = getattr(self, method)
        except:
            logging.debug("No handler defined for [%s]." % (method))
            return BadRequest()

        parameters = split_parameters(parameters_raw)

        try:
            response = handler(**parameters)
        except Exception as e:
            logging.exception(e)

            if issubclass(e.__class__, RequestError):
                message = str(e)
            elif issubclass(e.__class__, TypeError):
                arg_spec = inspect.getargspec(handler)
                arg_names = arg_spec.args[1:]
                defaults = {}

                if arg_spec.defaults is not None:
                    default_values = arg_spec.defaults
                    num_default_values = len(default_values)
                    i = 0
                    for k in arg_names[-num_default_values:]:
                        defaults[k] = default_values[i]
                        i += 1

                    arg_names = arg_names[:-num_default_values]

                arg_phrase = ', '.join(arg_names)

                if defaults:
                    if arg_phrase:
                        arg_phrase += ", "

                    arg_phrase += ', '.join([(('%s(%s)') % (k, v))
                                             for k, v in defaults.iteritems()])

                message = ("There was an error. Make sure your arguments are "
                           "correct: %s" % (arg_phrase))
            else:
                message = "There was an error."

            return self.json_error(message, e.__class__.__name__) \
                    if self.__returns_json \
                    else message
        else:
            return self.json_response(response)
Exemple #7
0
    def POST(self, *args, **kwargs):
        """Return a 400, unless implemented (per spec)."""

        return BadRequest()