Skip to content

Commit

Permalink
CySQL Support and fixes (#1020)
Browse files Browse the repository at this point in the history
* feat: BED-5159 - support coalesce function

* fix: BED-5173 - use correct pgsql regex operator

* chore: BED-5168 - enable schema manager to act independently to allow inline kind lookups and asserts in select parts of dawgs

* chore: BED-5168 - update schema manager calls to support looking up the latest information in the database if there is a kind lookup failure

* chore: BED-5168 - prepare for review
  • Loading branch information
zinic authored Dec 18, 2024
1 parent 51b29a4 commit 5d6f959
Show file tree
Hide file tree
Showing 44 changed files with 648 additions and 406 deletions.
6 changes: 2 additions & 4 deletions cmd/api/src/api/tools/pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@ func migrateTypes(ctx context.Context, neoDB, pgDB graph.Database) error {
return err
}

return pgDB.WriteTransaction(ctx, func(tx graph.Transaction) error {
_, err := pgDB.(*pg.Driver).KindMapper().AssertKinds(tx, append(neoNodeKinds, neoEdgeKinds...))
return err
})
_, err := pgDB.(*pg.Driver).KindMapper().AssertKinds(ctx, append(neoNodeKinds, neoEdgeKinds...))
return err
}

func convertNeo4jProperties(properties *graph.Properties) error {
Expand Down
6 changes: 4 additions & 2 deletions cmd/api/src/api/v2/integration/ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"strings"
"time"

"github.com/specterops/bloodhound/graphschema"

"github.com/specterops/bloodhound/dawgs/graph"
"github.com/specterops/bloodhound/src/model"
"github.com/specterops/bloodhound/src/model/appcfg"
Expand Down Expand Up @@ -198,7 +200,7 @@ func (s *Context) WaitForDatapipeAnalysis(timeout time.Duration, originalWrapper
type IngestAssertion func(testCtrl test.Controller, tx graph.Transaction)

func (s *Context) AssertIngest(assertion IngestAssertion) {
graphDB := integration.OpenGraphDB(s.TestCtrl)
graphDB := integration.OpenGraphDB(s.TestCtrl, graphschema.DefaultGraphSchema())
defer graphDB.Close(s.ctx)

require.Nil(s.TestCtrl, graphDB.ReadTransaction(s.ctx, func(tx graph.Transaction) error {
Expand All @@ -208,7 +210,7 @@ func (s *Context) AssertIngest(assertion IngestAssertion) {
}

func (s *Context) AssertIngestProperties(assertion IngestAssertion) {
graphDB := integration.OpenGraphDB(s.TestCtrl)
graphDB := integration.OpenGraphDB(s.TestCtrl, graphschema.DefaultGraphSchema())
defer graphDB.Close(s.ctx)

require.Nil(s.TestCtrl, graphDB.ReadTransaction(s.ctx, func(tx graph.Transaction) error {
Expand Down
3 changes: 2 additions & 1 deletion cmd/api/src/api/v2/integration/reconciliation.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package integration

import (
"github.com/specterops/bloodhound/dawgs/graph"
"github.com/specterops/bloodhound/graphschema"
"github.com/specterops/bloodhound/src/test"
"github.com/specterops/bloodhound/src/test/integration"
"github.com/stretchr/testify/require"
Expand All @@ -26,7 +27,7 @@ import (
type ReconciliationAssertion func(testCtrl test.Controller, tx graph.Transaction)

func (s *Context) AssertReconciliation(assertion ReconciliationAssertion) {
graphDB := integration.OpenGraphDB(s.TestCtrl)
graphDB := integration.OpenGraphDB(s.TestCtrl, graphschema.DefaultGraphSchema())
defer graphDB.Close(s.ctx)

require.Nil(s.TestCtrl, graphDB.ReadTransaction(s.ctx, func(tx graph.Transaction) error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/api/src/test/integration/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (s *GraphContext) End(t test.Context) {
func NewGraphContext(ctx test.Context, schema graph.Schema) *GraphContext {
graphContext := &GraphContext{
schema: schema,
Database: OpenGraphDB(ctx),
Database: OpenGraphDB(ctx, schema),
}

// Initialize the graph context
Expand Down
5 changes: 2 additions & 3 deletions cmd/api/src/test/integration/dawgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/specterops/bloodhound/dawgs/drivers/neo4j"
"github.com/specterops/bloodhound/dawgs/drivers/pg"
"github.com/specterops/bloodhound/dawgs/graph"
schema "github.com/specterops/bloodhound/graphschema"
"github.com/specterops/bloodhound/src/config"
"github.com/specterops/bloodhound/src/test"
"github.com/specterops/bloodhound/src/test/integration/utils"
Expand All @@ -39,7 +38,7 @@ func LoadConfiguration(testCtrl test.Controller) config.Configuration {
return cfg
}

func OpenGraphDB(testCtrl test.Controller) graph.Database {
func OpenGraphDB(testCtrl test.Controller, schema graph.Schema) graph.Database {
var (
cfg = LoadConfiguration(testCtrl)
graphDatabase graph.Database
Expand All @@ -62,7 +61,7 @@ func OpenGraphDB(testCtrl test.Controller) graph.Database {
}

test.RequireNilErrf(testCtrl, err, "Failed connecting to graph database: %v", err)
test.RequireNilErr(testCtrl, graphDatabase.AssertSchema(context.Background(), schema.DefaultGraphSchema()))
test.RequireNilErr(testCtrl, graphDatabase.AssertSchema(context.Background(), schema))

return graphDatabase
}
4 changes: 2 additions & 2 deletions cmd/api/src/test/integration/harnesses/enrollonbehalfof-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions cmd/api/src/test/integration/harnesses/enrollonbehalfof-2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions cmd/api/src/test/integration/harnesses/enrollonbehalfof-3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/go/cypher/models/cypher/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
ToStringFunction = "tostring"
ToIntegerFunction = "toint"
ListSizeFunction = "size"
CoalesceFunction = "coalesce"

// ITTC - Instant Type; Temporal Component (https://neo4j.com/docs/cypher-manual/current/functions/temporal/)
ITTCYear = "year"
Expand Down
2 changes: 1 addition & 1 deletion packages/go/cypher/models/pgsql/format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func formatNode(builder *OutputBuilder, rootExpr pgsql.SyntaxNode) error {
exprStack = append(exprStack, *typedNextExpr)

case pgsql.FunctionCall:
if typedNextExpr.CastType != pgsql.UnsetDataType {
if typedNextExpr.CastType.IsKnown() {
exprStack = append(exprStack, typedNextExpr.CastType, pgsql.FormattingLiteral("::"))
}

Expand Down
Loading

0 comments on commit 5d6f959

Please sign in to comment.