-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update flow index when importing a flow (#3240)
Fixes: #3192
- Loading branch information
Showing
15 changed files
with
139 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 40 additions & 10 deletions
50
artifacts/testdata/server/testcases/import_collection.out.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,63 @@ | ||
LET Sanitize(X) = regex_replace(re="[CF]\\.[0-9a-z]+", replace="C.ID", source=X)[]LET X <= SELECT * FROM Artifact.Server.Utils.ImportCollection( Hostname="FooBarHost", Path=srcDir+"/vql/tools/collector/fixtures/import.zip")[]LET Y <= SELECT * FROM Artifact.Server.Utils.ImportCollection( Hostname="FooBarHost", Path=srcDir+"/vql/tools/collector/fixtures/import.zip")[]SELECT X[0].ClientId = Y[0].ClientId AS ClientIdEqual FROM scope()[ | ||
LET Sanitize(X) = regex_replace(re="[C]\\.[0-9a-z]+", replace="C.ID", source=X)[]LET X <= SELECT * FROM Artifact.Server.Utils.ImportCollection( Hostname="FooBarHost", Path=srcDir+"/vql/tools/collector/fixtures/import.zip")[]LET Y <= SELECT * FROM Artifact.Server.Utils.ImportCollection( Hostname="FooBarHost", Path=srcDir+"/vql/tools/collector/fixtures/import.zip")[]SELECT X[0].ClientId = Y[0].ClientId AS ClientIdEqual FROM scope()[ | ||
{ | ||
"ClientIdEqual": true | ||
} | ||
]SELECT Sanitize(X=vfs_path) AS vfs_path FROM Artifact.Server.Utils.DeleteClient( ClientIdList=[X[0].ClientId, Y[0].ClientId], ReallyDoIt=TRUE) WHERE NOT vfs_path =~ "monitoring" Order by vfs_path[ | ||
{ | ||
"vfs_path": "/clients/C.ID/artifacts/Linux.Search.FileFinder/C.ID.json" | ||
"vfs_path": "/clients/C.ID/artifacts/Linux.Search.FileFinder/F.1.json" | ||
}, | ||
{ | ||
"vfs_path": "/clients/C.ID/artifacts/Linux.Search.FileFinder/C.ID.json.index" | ||
"vfs_path": "/clients/C.ID/artifacts/Linux.Search.FileFinder/F.1.json.index" | ||
}, | ||
{ | ||
"vfs_path": "/clients/C.ID/collections/C.ID.json.db" | ||
"vfs_path": "/clients/C.ID/artifacts/Linux.Search.FileFinder/F.CD62UJJO259A4.json" | ||
}, | ||
{ | ||
"vfs_path": "/clients/C.ID/collections/C.ID/logs.json" | ||
"vfs_path": "/clients/C.ID/artifacts/Linux.Search.FileFinder/F.CD62UJJO259A4.json.index" | ||
}, | ||
{ | ||
"vfs_path": "/clients/C.ID/collections/C.ID/logs.json.index" | ||
"vfs_path": "/clients/C.ID/collections/F.1.json.db" | ||
}, | ||
{ | ||
"vfs_path": "/clients/C.ID/collections/C.ID/task.db" | ||
"vfs_path": "/clients/C.ID/collections/F.1/logs.json" | ||
}, | ||
{ | ||
"vfs_path": "/clients/C.ID/collections/C.ID/uploads.json" | ||
"vfs_path": "/clients/C.ID/collections/F.1/logs.json.index" | ||
}, | ||
{ | ||
"vfs_path": "/clients/C.ID/collections/C.ID/uploads.json.index" | ||
"vfs_path": "/clients/C.ID/collections/F.1/uploads.json" | ||
}, | ||
{ | ||
"vfs_path": "/clients/C.ID/collections/C.ID/uploads/file/tmp/\"ls\\with\\back:slash\"" | ||
"vfs_path": "/clients/C.ID/collections/F.1/uploads.json.index" | ||
}, | ||
{ | ||
"vfs_path": "/clients/C.ID/collections/F.1/uploads/file/tmp/\"ls\\with\\back:slash\"" | ||
}, | ||
{ | ||
"vfs_path": "/clients/C.ID/collections/F.CD62UJJO259A4.json.db" | ||
}, | ||
{ | ||
"vfs_path": "/clients/C.ID/collections/F.CD62UJJO259A4/logs.json" | ||
}, | ||
{ | ||
"vfs_path": "/clients/C.ID/collections/F.CD62UJJO259A4/logs.json.index" | ||
}, | ||
{ | ||
"vfs_path": "/clients/C.ID/collections/F.CD62UJJO259A4/task.db" | ||
}, | ||
{ | ||
"vfs_path": "/clients/C.ID/collections/F.CD62UJJO259A4/uploads.json" | ||
}, | ||
{ | ||
"vfs_path": "/clients/C.ID/collections/F.CD62UJJO259A4/uploads.json.index" | ||
}, | ||
{ | ||
"vfs_path": "/clients/C.ID/collections/F.CD62UJJO259A4/uploads/file/tmp/\"ls\\with\\back:slash\"" | ||
}, | ||
{ | ||
"vfs_path": "/clients/C.ID/flow_index.json" | ||
}, | ||
{ | ||
"vfs_path": "/clients/C.ID/flow_index.json.index" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package utils | ||
|
||
import ( | ||
"crypto/rand" | ||
"encoding/base32" | ||
"encoding/binary" | ||
"fmt" | ||
"time" | ||
|
||
"www.velocidex.com/golang/velociraptor/constants" | ||
) | ||
|
||
var ( | ||
generator FlowIdGenerator = RandomFlowIdGenerator{} | ||
) | ||
|
||
type FlowIdGenerator interface { | ||
Next(client_id string) string | ||
} | ||
|
||
type RandomFlowIdGenerator struct{} | ||
|
||
func (self RandomFlowIdGenerator) Next(client_id string) string { | ||
buf := make([]byte, 8) | ||
_, _ = rand.Read(buf) | ||
|
||
binary.BigEndian.PutUint32(buf, uint32(time.Now().Unix())) | ||
result := base32.HexEncoding.EncodeToString(buf)[:13] | ||
|
||
return constants.FLOW_PREFIX + result | ||
|
||
} | ||
|
||
type ConstantFlowIdGenerator string | ||
|
||
func (self ConstantFlowIdGenerator) Next(client_id string) string { | ||
return string(self) | ||
} | ||
|
||
type IncrementalFlowIdGenerator int | ||
|
||
func (self *IncrementalFlowIdGenerator) Next(client_id string) string { | ||
*self = *self + 1 | ||
return fmt.Sprintf("F.%d", *self) | ||
} | ||
|
||
func NewFlowId(client_id string) string { | ||
return generator.Next(client_id) | ||
} | ||
|
||
func SetFlowIdGenerator(gen FlowIdGenerator) { | ||
generator = gen | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters