def put(self, id): # pylint: disable=redefined-builtin """Updates an Observable. If tags are provided in the request, they will individually be applied to the observable in question. Fields not part of the observable schema will be ignored. Args: id: The Observable's primary ID. Returns: A JSON representation of the Observable, a 404 HTTP status code if the Observable cannot be found, or a 400 HTTP status code if the request could not be parsed. """ try: obj = get_object_or_404(self.resource_object, id) dumped = obj.dump() request_json = request.get_json() tags = [] for tag in request_json.pop('tags', []): tags.append(tag['name'] if isinstance(tag, dict) else tag) dumped.update(request_json) saved_object = self.resource_object.load(dumped).save() saved_object.tag(tags, strict=True) return saved_object except GenericYetiError as err: import traceback traceback.print_exc() return err, 400
def tag(self, id): # pylint: disable=redefined-builtin """Updates a given object. Args: id: The object's primary ID. Returns: A JSON representation of the requested object, or a 404 HTTP status code if the object cannot be found. """ args = parser.parse(self.tagargs, request) obj = get_object_or_404(self.resource_object, id) obj.tag(args['tags']) return obj
def put(self, id): # pylint: disable=redefined-builtin """Updates an Observable. If tags are provided in the request, they will individually be applied to the observable in question. Fields not part of the observable schema will be ignored. Args: id: The Observable's primary ID. Returns: A JSON representation of the Observable, a 404 HTTP status code if the Observable cannot be found, or a 400 HTTP status code if the request could not be parsed. """ try: obj = get_object_or_404(self.resource_object, id) return obj.update(request.json) except GenericYetiError as err: return err, 400