Skip to content

Commit

Permalink
Only return a summary of hunts in the hunt table (Velocidex#1240)
Browse files Browse the repository at this point in the history
Otherwise this might overflow the RPC limit if the user has many large
hunts (with large requests)
  • Loading branch information
scudette authored Sep 6, 2021
1 parent 66dfb7c commit 663d6c4
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 73 deletions.
19 changes: 19 additions & 0 deletions api/hunts.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,25 @@ func (self *ApiServer) ListHunts(
return nil, err
}

// Provide only a summary for list hunts GUI
if in.Summary {
summary := &api_proto.ListHuntsResponse{}
for _, item := range result.Items {
summary.Items = append(summary.Items, &api_proto.Hunt{
HuntId: item.HuntId,
HuntDescription: item.HuntDescription,
State: item.State,
Creator: item.Creator,
CreateTime: item.CreateTime,
StartTime: item.StartTime,
Stats: item.Stats,
Expires: item.Expires,
})
}

return summary, nil
}

return result, nil
}

Expand Down
28 changes: 14 additions & 14 deletions api/proto/api.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 57 additions & 46 deletions api/proto/hunts.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions api/proto/hunts.proto
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ message Hunt {
message ListHuntsRequest {
uint64 offset = 1;
uint64 count = 2;

// If specified we return a partial structure.
bool summary = 4;
bool include_archived = 3;
}

Expand Down
38 changes: 26 additions & 12 deletions gui/velociraptor/src/components/flows/new-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,25 +129,33 @@ class NewCollectionSelectArtifacts extends React.Component {
componentDidMount = () => {
this.source = axios.CancelToken.source();
this.doSearch("...");
const el = document.getElementById("text-filter-column-name-search-for-artifact-input");
if (el) {
setTimeout(()=>el.focus(), 1000);
};
}

componentWillUnmount() {
this.source.cancel();
}

onSelect = (row, isSelect) => {
let new_artifacts = [];
if (isSelect) {
new_artifacts = add_artifact(this.props.artifacts, row);
} else {
new_artifacts = remove_artifact(this.props.artifacts, row.name);
}
this.props.setArtifacts(new_artifacts);
this.setState({selectedDescriptor: row});
// The row contains only the name so we need to make another
// request to fetch the full definition.
let name = row["name"];
api.post("v1/GetArtifacts", {
names: [name],
}, this.source.token).then(response=>{
let items = response.data.items || [];
if (_.isEmpty(items)) {
return;
}
let definition = items[0];;
let new_artifacts = [];
if (isSelect) {
new_artifacts = add_artifact(this.props.artifacts, definition);
} else {
new_artifacts = remove_artifact(this.props.artifacts, row.name);
}
this.props.setArtifacts(new_artifacts);
this.setState({selectedDescriptor: definition});
});
}

onSelectAll = (isSelect, rows) => {
Expand Down Expand Up @@ -737,6 +745,12 @@ class NewCollectionWizard extends React.Component {
componentDidMount = () => {
this.source = axios.CancelToken.source();
this.initializeFromBaseFlow();

// A bit hacky but whatevs...
const el = document.getElementById("text-filter-column-name-search-for-artifact-input");
if (el) {
setTimeout(()=>el.focus(), 100);
};
}

componentWillUnmount() {
Expand Down
1 change: 0 additions & 1 deletion gui/velociraptor/src/components/hunts/hunt-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ export function getHuntColumns() {
{dataField: "expires",
text: "Expires", sort: true,
type: "timestamp"},
{dataField: "client_limit", text: "Limit"},
{dataField: "stats.total_clients_scheduled", text: "Scheduled"},
{dataField: "creator", text: "Creator"},
]);
Expand Down
1 change: 1 addition & 0 deletions gui/velociraptor/src/components/hunts/hunts.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class VeloHunts extends React.Component {
api.get("v1/ListHunts", {
count: 2000,
offset: 0,
summary: true,
}, this.list_hunts_source.token).then((response) => {
if (response.cancel) return;

Expand Down
Loading

0 comments on commit 663d6c4

Please sign in to comment.