-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move graph deletion to datapipe (#517)
* chore: move graph deletion logic to datapipe * fix: go generate * fix: broken sql * chore: better logging and datapipe status for purge * chore: fix tests * chore: delete bad comment --------- Co-authored-by: Alyx Holms <[email protected]>
- Loading branch information
1 parent
05c6832
commit e774e08
Showing
11 changed files
with
180 additions
and
93 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
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,35 @@ | ||
package datapipe | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/specterops/bloodhound/dawgs/graph" | ||
"github.com/specterops/bloodhound/dawgs/ops" | ||
) | ||
|
||
func DeleteCollectedGraphData(ctx context.Context, graphDB graph.Database) error { | ||
var nodeIDs []graph.ID | ||
|
||
if err := graphDB.ReadTransaction(ctx, | ||
func(tx graph.Transaction) error { | ||
fetchedNodeIDs, err := ops.FetchNodeIDs(tx.Nodes()) | ||
|
||
nodeIDs = append(nodeIDs, fetchedNodeIDs...) | ||
return err | ||
}, | ||
); err != nil { | ||
return fmt.Errorf("error fetching all nodes: %w", err) | ||
} else if err := graphDB.BatchOperation(ctx, func(batch graph.Batch) error { | ||
for _, nodeId := range nodeIDs { | ||
// deleting a node also deletes all of its edges due to a sql trigger | ||
if err := batch.DeleteNode(nodeId); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
}); err != nil { | ||
return fmt.Errorf("error deleting all nodes: %w", err) | ||
} else { | ||
return nil | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.