Skip to content

Commit

Permalink
Added a reformat button for the artifact editor (Velocidex#3087)
Browse files Browse the repository at this point in the history
Also refactor column filters/sorters in paged table.
  • Loading branch information
scudette authored Nov 10, 2023
1 parent c1903af commit d22c46e
Show file tree
Hide file tree
Showing 15 changed files with 646 additions and 239 deletions.
286 changes: 148 additions & 138 deletions api/proto/notebooks.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/proto/notebooks.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ option go_package = "www.velocidex.com/golang/velociraptor/api/proto";

message ReformatVQLMessage {
string vql = 1;
string artifact = 2;
}


message Env {
string key = 1;
string value = 2;
Expand Down
11 changes: 11 additions & 0 deletions api/reformat.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ func (self *ApiServer) ReformatVQL(
"User is not allowed to read notebooks.")
}

if in.Artifact != "" {
manager, err := services.GetRepositoryManager(org_config_obj)
if err != nil {
return nil, Status(self.verbose, err)
}

reformated_vql, err := manager.ReformatVQL(ctx, in.Artifact)
return &api_proto.ReformatVQLMessage{
Artifact: reformated_vql,
}, Status(self.verbose, err)
}
notebook_manager, err := services.GetNotebookManager(org_config_obj)
if err != nil {
return nil, Status(self.verbose, err)
Expand Down
5 changes: 5 additions & 0 deletions api/tables/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package tables

import (
"io"
"regexp"
"time"

Expand Down Expand Up @@ -137,6 +138,10 @@ func getTable(

// Seek to the row we need.
err = rs_reader.SeekToRow(int64(in.StartRow))
if err == io.EOF {
return result, nil
}

if err != nil {
return nil, err
}
Expand Down
16 changes: 16 additions & 0 deletions gui/velociraptor/src/components/artifacts/new-artifact.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ export default class NewArtifactDialog extends React.Component {
});
}

reformatArtifact = ()=>{
this.setState({loading: true});
api.post("v1/ReformatVQL",
{artifact: this.state.text}, this.source.token).then(
response=>{
if (response.data.artifact) {
this.setState({text: response.data.artifact});
};
this.setState({loading: false});
});
}

aceConfig = (ace) => {
// Attach a completer to ACE.
let completer = new Completer();
Expand Down Expand Up @@ -113,6 +125,10 @@ export default class NewArtifactDialog extends React.Component {
<Navbar className="w-100 justify-content-between">
<ButtonGroup className="float-left">
<SettingsButton ace={this.state.ace}/>
<Button variant="default"
onClick={this.reformatArtifact}>
<FontAwesomeIcon icon="indent"/>
</Button>
</ButtonGroup>

<ButtonGroup className="float-right">
Expand Down
5 changes: 3 additions & 2 deletions gui/velociraptor/src/components/core/api-service.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ function retryDelay(retryNumber = 0) {
}

function isRetryableError(error) {
return error.code !== 'ECONNABORTED' && (!error.response || (
error.response.status >= 500 && error.response.status <= 599));
return error.code !== 'ECONNABORTED' && (!error.response || (
error.response.status >= 500 && error.response.status <= 599));
}

function isNetworkError(error) {
Expand Down Expand Up @@ -82,6 +82,7 @@ function isNetworkOrIdempotentRequestError(error) {
function simpleNetworkErrorCheck(error) {
if ((error && error.message) === 'Network Error') {
return true;

} else {
return isNetworkOrIdempotentRequestError(error);
}
Expand Down
10 changes: 9 additions & 1 deletion gui/velociraptor/src/components/core/paged-table.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,18 @@ table.paged-table-header:hover .sort-element {
display: block;
}

table.paged-table-header .sort-element.visible {
table.paged-table-header .sort-element {
display: block;
}

tr.paged-table-header th {
padding: 0;
}

table.paged-table-header .hidden-edit {
visibility: hidden;
}

table.paged-table-header:hover .hidden-edit {
visibility: visible;
}
Loading

0 comments on commit d22c46e

Please sign in to comment.