@@ -18,7 +18,6 @@ package azure
1818
1919import (
2020 "context"
21- "net/url"
2221
2322 "log/slog"
2423 "strings"
@@ -822,6 +821,13 @@ var containsValidEndKinds = map[graph.Kind]graph.Kinds{
822821 },
823822}
824823
824+ func isDirectDescendent (sourceKind , targetKind graph.Kind ) bool {
825+ if validEndKinds , ok := containsValidEndKinds [sourceKind ]; ok && validEndKinds .ContainsOneOf (targetKind ) {
826+ return true
827+ }
828+ return false
829+ }
830+
825831// nodeAzureTenantID returns the Azure tenant ID for a node. For Tenant nodes the tenant ID is
826832// stored in the common.ObjectID property; for all other Azure nodes it is stored in azure.TenantID.
827833func nodeAzureTenantID (node * graph.Node ) (string , error ) {
@@ -832,22 +838,16 @@ func nodeAzureTenantID(node *graph.Node) (string, error) {
832838 return node .Properties .Get (azure .TenantID .String ()).String ()
833839}
834840
835- // FetchDirectDescendentPaths fetches the direct AZContains relationships from the root node. Both
836- // the valid start/end node kind pairing and the tenant-id match are enforced
841+ // FetchDirectDescendentPaths fetches the direct AZContains relationships from the root node
837842func FetchDirectDescendentPaths (tx graph.Transaction , root * graph.Node , descendentKind ... graph.Kind ) (graph.PathSet , error ) {
838- if tenantID , err := nodeAzureTenantID (root ); err != nil {
839- return nil , err
840- } else {
841- return ops .FetchPathSet (tx .Relationships ().Filter (query .And (
842- query .Equals (query .StartID (), root .ID ),
843- query .Kind (query .Relationship (), azure .Contains ),
844- query .KindIn (query .End (), descendentKind ... ),
845- query .Equals (query .EndProperty (azure .TenantID .String ()), tenantID ),
846- )))
847- }
843+ return ops .FetchPathSet (tx .Relationships ().Filter (query .And (
844+ query .Equals (query .StartID (), root .ID ),
845+ query .Kind (query .Relationship (), azure .Contains ),
846+ query .KindIn (query .End (), descendentKind ... ),
847+ )))
848848}
849849
850- func FetchDirectEntityDescendents (tx graph.Transaction , root * graph.Node , skip , limit int , descendentKind graph.Kind ) (graph.NodeSet , error ) {
850+ func FetchDirectEntityDescendents (tx graph.Transaction , root * graph.Node , descendentKind graph.Kind ) (graph.NodeSet , error ) {
851851 if paths , err := FetchDirectDescendentPaths (tx , root , descendentKind ); err != nil {
852852 return nil , err
853853 } else {
@@ -857,7 +857,7 @@ func FetchDirectEntityDescendents(tx graph.Transaction, root *graph.Node, skip,
857857 }
858858}
859859
860- func FetchDescendentKindByTenantID (tx graph.Transaction , root * graph.Node , skip , limit int , descendentKind ... graph.Kind ) (graph.NodeSet , error ) {
860+ func FetchDescendentKindByTenantID (tx graph.Transaction , root * graph.Node , descendentKind ... graph.Kind ) (graph.NodeSet , error ) {
861861 if tenantID , err := nodeAzureTenantID (root ); err != nil {
862862 return nil , err
863863 } else if nodes , err := ops .FetchNodeSet (tx .Nodes ().Filter (query .And (
@@ -883,7 +883,7 @@ func FetchEntityDescendentPaths(tx graph.Transaction, root *graph.Node, descende
883883 // Pre-populate the visited bitmap with root so that any traversal halts when it reaches it
884884 visitedBitmap .Add (root .ID .Uint64 ())
885885
886- terminalNodes , err := FetchDescendentKindByTenantID (tx , root , 0 , 0 , descendentKind ... )
886+ terminalNodes , err := FetchDescendentKindByTenantID (tx , root , descendentKind ... )
887887 if err != nil {
888888 return nil , err
889889 }
@@ -918,7 +918,7 @@ func FetchEntityDescendentPaths(tx graph.Transaction, root *graph.Node, descende
918918 return pathSet , nil
919919}
920920
921- func FetchEntityDescendents (tx graph.Transaction , root * graph.Node , skip , limit int , descendentKind graph.Kind ) (graph.NodeSet , error ) {
921+ func FetchEntityDescendents (tx graph.Transaction , root * graph.Node , descendentKind graph.Kind ) (graph.NodeSet , error ) {
922922 if paths , err := FetchEntityDescendentPaths (tx , root , descendentKind ); err != nil {
923923 return nil , err
924924 } else {
@@ -928,7 +928,7 @@ func FetchEntityDescendents(tx graph.Transaction, root *graph.Node, skip, limit
928928 }
929929}
930930
931- func FetchDirectDescendentCounts (tx graph.Transaction , root * graph.Node , skip , limit int , descendentKinds ... graph.Kind ) (Descendents , error ) {
931+ func FetchDirectDescendentCounts (tx graph.Transaction , root * graph.Node , descendentKinds ... graph.Kind ) (Descendents , error ) {
932932 if paths , err := FetchDirectDescendentPaths (tx , root , descendentKinds ... ); err != nil {
933933 return Descendents {}, err
934934 } else {
@@ -946,7 +946,7 @@ func FetchDirectDescendentCounts(tx graph.Transaction, root *graph.Node, skip, l
946946 }
947947}
948948
949- func FetchEntityDescendentCounts (tx graph.Transaction , root * graph.Node , skip , limit int , descendentKinds ... graph.Kind ) (Descendents , error ) {
949+ func FetchEntityDescendentCounts (tx graph.Transaction , root * graph.Node , descendentKinds ... graph.Kind ) (Descendents , error ) {
950950 if paths , err := FetchEntityDescendentPaths (tx , root , descendentKinds ... ); err != nil {
951951 return Descendents {}, err
952952 } else {
@@ -980,14 +980,10 @@ func fetchRolesTraversalPlan(root *graph.Node) ops.TraversalPlan {
980980
981981// FetchEntityByObjectID pulls a node by its ObjectID. It requires a kind to perform index lookups against.
982982func FetchEntityByObjectID (tx graph.Transaction , objectID string ) (* graph.Node , error ) {
983- if decodedObjectID , err := url .QueryUnescape (objectID ); err != nil {
984- return nil , err
985- } else {
986- return tx .Nodes ().Filterf (func () graph.Criteria {
987- return query .And (
988- query .Kind (query .Node (), azure .Entity ),
989- query .Equals (query .NodeProperty (common .ObjectID .String ()), decodedObjectID ),
990- )
991- }).First ()
992- }
983+ return tx .Nodes ().Filterf (func () graph.Criteria {
984+ return query .And (
985+ query .Kind (query .Node (), azure .Entity ),
986+ query .Equals (query .NodeProperty (common .ObjectID .String ()), objectID ),
987+ )
988+ }).First ()
993989}
0 commit comments