def get(self, sketch_id, group_id): """Handles GET request to the resource. Args: sketch_id: Integer primary key for a sketch database model. group_id: Integer primary key for an aggregation group database """ sketch = Sketch.query.get_with_acl(sketch_id) group = AggregationGroup.query.get(group_id) if not group: abort( HTTP_STATUS_CODE_NOT_FOUND, 'No Group found with this ID.') if not sketch: abort( HTTP_STATUS_CODE_NOT_FOUND, 'No sketch found with this ID.') if not sketch.has_permission(user=current_user, permission='read'): abort( HTTP_STATUS_CODE_FORBIDDEN, 'The user does not have read permission on the sketch.') # Check that this group belongs to the sketch if group.sketch_id != sketch.id: msg = ( 'The sketch ID ({0:d}) does not match with the aggregation ' 'group sketch ID ({1:d})'.format(sketch.id, group.sketch_id)) abort(HTTP_STATUS_CODE_FORBIDDEN, msg) _, objects, meta = run_aggregator_group(group, sketch_id=sketch.id) schema = {'meta': meta, 'objects': objects} return jsonify(schema)
def export_aggregation_group(group, sketch, zip_file): """Export an aggregation group from a sketch and write it to a ZIP file. Args: group (timesketch.models.sketch.AggregationGroup): an aggregation group object. sketch (timesketch.models.sketch.Sketch): a sketch object. zip_file (ZipFile): a zip file handle that can be used to write content to. """ name = "{0:04d}_{1:s}".format(group.id, group.name) chart, _, meta = utils.run_aggregator_group(group, sketch_id=sketch.id) zip_file.writestr("aggregation_groups/{0:s}.meta".format(name), json.dumps(meta)) zip_file.writestr("aggregation_groups/{0:s}.html".format(name), chart.to_html())
def get(self, sketch_id, group_id): """Handles GET request to the resource. Args: sketch_id: Integer primary key for a sketch database model. group_id: Integer primary key for an aggregation group database """ sketch = Sketch.query.get_with_acl(sketch_id) group = AggregationGroup.query.get(group_id) if not group: abort( HTTP_STATUS_CODE_NOT_FOUND, 'No Group found with this ID.') if not sketch: abort( HTTP_STATUS_CODE_NOT_FOUND, 'No sketch found with this ID.') if not sketch.has_permission(user=current_user, permission='read'): abort( HTTP_STATUS_CODE_FORBIDDEN, 'The user does not have read permission on the sketch.') # Check that this group belongs to the sketch if group.sketch_id != sketch.id: msg = ( 'The sketch ID ({0:d}) does not match with the aggregation ' 'group sketch ID ({1:d})'.format(sketch.id, group.sketch_id)) abort(HTTP_STATUS_CODE_FORBIDDEN, msg) _, objects, meta = utils.run_aggregator_group( group, sketch_id=sketch.id) group_fields = self.fields_registry[group.__tablename__] group_dict = marshal(group, group_fields) group_dict['agg_ids'] = [a.id for a in group.aggregations] objects[0].update(group_dict) schema = { 'meta': meta, 'objects': objects } # Update the last activity of a sketch. utils.update_sketch_last_activity(sketch) return jsonify(schema)