Fully autonomous AI Agents system capable of performing complex penetration testing tasks
Go ai-agentsai-security-toolanthropicautonomous-agentsgolanggptgraphqlmulti-agent-systemoffensive-securityopen-sourceopenaipenetration-testingpenetration-testing-toolsreactsecurity-automationsecurity-testingsecurity-toolsself-hosted
fix: bug with retrieving resources recursive via graphql
Dmitry Ng629c018a68f3
diff --git a/backend/pkg/database/querier.go b/backend/pkg/database/querier.goindex 8317ff7a..11c8ee98 100644--- a/backend/pkg/database/querier.go+++ b/backend/pkg/database/querier.go@@ -55,6 +55,7 @@ type Querier interface {// Get toolcalls stats for all flowsGetAllFlowsToolcallsStats(ctx context.Context) ([]GetAllFlowsToolcallsStatsRow, error)GetAllFlowsUsageStats(ctx context.Context) ([]GetAllFlowsUsageStatsRow, error)+ GetAllResourcesAll(ctx context.Context) ([]UserResource, error)GetAllResourcesInDir(ctx context.Context, arg GetAllResourcesInDirParams) ([]UserResource, error)GetAllResourcesRecursive(ctx context.Context, arg GetAllResourcesRecursiveParams) ([]UserResource, error)GetAllResourcesRoot(ctx context.Context) ([]UserResource, error)@@ -210,6 +211,7 @@ type Querier interface {GetUserProviders(ctx context.Context, userID int64) ([]Provider, error)GetUserProvidersByType(ctx context.Context, arg GetUserProvidersByTypeParams) ([]Provider, error)GetUserResourceByID(ctx context.Context, id int64) (UserResource, error)+ GetUserResourcesAll(ctx context.Context, userID int64) ([]UserResource, error)GetUserResourcesByIDs(ctx context.Context, ids []int64) ([]UserResource, error)GetUserResourcesInDir(ctx context.Context, arg GetUserResourcesInDirParams) ([]UserResource, error)GetUserResourcesRecursive(ctx context.Context, arg GetUserResourcesRecursiveParams) ([]UserResource, error)diff --git a/backend/pkg/database/resources.sql.go b/backend/pkg/database/resources.sql.goindex c3f1c623..c9af0d74 100644--- a/backend/pkg/database/resources.sql.go+++ b/backend/pkg/database/resources.sql.go@@ -11,6 +11,45 @@ import ("github.com/lib/pq")+const getAllResourcesAll = `-- name: GetAllResourcesAll :many+SELECT id, user_id, hash, name, path, size, is_dir, created_at, updated_at+FROM user_resources+ORDER BY updated_at DESC, name ASC+`++func (q *Queries) GetAllResourcesAll(ctx context.Context) ([]UserResource, error) {+ rows, err := q.db.QueryContext(ctx, getAllResourcesAll)+ if err != nil {+ return nil, err+ }+ defer rows.Close()+ var items []UserResource+ for rows.Next() {+ var i UserResource+ if err := rows.Scan(+ &i.ID,+ &i.UserID,+ &i.Hash,+ &i.Name,+ &i.Path,+ &i.Size,+ &i.IsDir,+ &i.CreatedAt,+ &i.UpdatedAt,+ ); err != nil {+ return nil, err+ }+ items = append(items, i)+ }+ if err := rows.Close(); err != nil {+ return nil, err+ }+ if err := rows.Err(); err != nil {+ return nil, err+ }+ return items, nil+}+const getAllResourcesInDir = `-- name: GetAllResourcesInDir :manySELECT id, user_id, hash, name, path, size, is_dir, created_at, updated_atFROM user_resources@@ -166,6 +205,46 @@ func (q *Queries) GetUserResourceByID(ctx context.Context, id int64) (UserResourreturn i, err}+const getUserResourcesAll = `-- name: GetUserResourcesAll :many+SELECT id, user_id, hash, name, path, size, is_dir, created_at, updated_at+FROM user_resources+WHERE user_id = $1+ORDER BY updated_at DESC, name ASC+`++func (q *Queries) GetUserResourcesAll(ctx context.Context, userID int64) ([]UserResource, error) {+ rows, err := q.db.QueryContext(ctx, getUserResourcesAll, userID)+ if err != nil {+ return nil, err+ }+ defer rows.Close()+ var items []UserResource+ for rows.Next() {+ var i UserResource+ if err := rows.Scan(+ &i.ID,+ &i.UserID,+ &i.Hash,+ &i.Name,+ &i.Path,+ &i.Size,+ &i.IsDir,+ &i.CreatedAt,+ &i.UpdatedAt,+ ); err != nil {+ return nil, err+ }+ items = append(items, i)+ }+ if err := rows.Close(); err != nil {+ return nil, err+ }+ if err := rows.Err(); err != nil {+ return nil, err+ }+ return items, nil+}+const getUserResourcesByIDs = `-- name: GetUserResourcesByIDs :manySELECT id, user_id, hash, name, path, size, is_dir, created_at, updated_atFROM user_resourcesdiff --git a/backend/pkg/graph/schema.resolvers.go b/backend/pkg/graph/schema.resolvers.goindex a4321ba5..2d766d08 100644--- a/backend/pkg/graph/schema.resolvers.go+++ b/backend/pkg/graph/schema.resolvers.go@@ -2261,16 +2261,19 @@ func (r *queryResolver) Resources(ctx context.Context, path *string, recursive *var recs []database.UserResourceif !admin {- if reqPath == "" {+ switch {+ case reqPath == "" && isRecursive:+ recs, err = r.DB.GetUserResourcesAll(ctx, uid)+ case reqPath == "":recs, err = r.DB.GetUserResourcesRoot(ctx, uid)- } else if isRecursive {+ case isRecursive:escaped := resources.EscapeLike(reqPath)recs, err = r.DB.GetUserResourcesRecursive(ctx, database.GetUserResourcesRecursiveParams{UserID: uid,DirPath: reqPath,ChildPrefix: escaped + "/%",})- } else {+ default:escaped := resources.EscapeLike(reqPath)recs, err = r.DB.GetUserResourcesInDir(ctx, database.GetUserResourcesInDirParams{UserID: uid,@@ -2280,15 +2283,18 @@ func (r *queryResolver) Resources(ctx context.Context, path *string, recursive *})}} else {- if reqPath == "" {+ switch {+ case reqPath == "" && isRecursive:+ recs, err = r.DB.GetAllResourcesAll(ctx)+ case reqPath == "":recs, err = r.DB.GetAllResourcesRoot(ctx)- } else if isRecursive {+ case isRecursive:escaped := resources.EscapeLike(reqPath)recs, err = r.DB.GetAllResourcesRecursive(ctx, database.GetAllResourcesRecursiveParams{DirPath: reqPath,ChildPrefix: escaped + "/%",})- } else {+ default:escaped := resources.EscapeLike(reqPath)recs, err = r.DB.GetAllResourcesInDir(ctx, database.GetAllResourcesInDirParams{DirPath: reqPath,diff --git a/backend/sqlc/models/resources.sql b/backend/sqlc/models/resources.sqlindex 0137381e..c5acf31b 100644--- a/backend/sqlc/models/resources.sql+++ b/backend/sqlc/models/resources.sql@@ -19,6 +19,12 @@ WHERE user_id = sqlc.arg(user_id)AND (path = sqlc.arg(dir_path) OR path LIKE sqlc.arg(child_prefix))ORDER BY updated_at DESC, name ASC;+-- name: GetUserResourcesAll :many+SELECT id, user_id, hash, name, path, size, is_dir, created_at, updated_at+FROM user_resources+WHERE user_id = sqlc.arg(user_id)+ORDER BY updated_at DESC, name ASC;+-- name: GetAllResourcesRoot :manySELECT id, user_id, hash, name, path, size, is_dir, created_at, updated_atFROM user_resources@@ -38,6 +44,11 @@ FROM user_resourcesWHERE path = sqlc.arg(dir_path) OR path LIKE sqlc.arg(child_prefix)ORDER BY updated_at DESC, name ASC;+-- name: GetAllResourcesAll :many+SELECT id, user_id, hash, name, path, size, is_dir, created_at, updated_at+FROM user_resources+ORDER BY updated_at DESC, name ASC;+-- name: GetUserResourceByID :oneSELECT id, user_id, hash, name, path, size, is_dir, created_at, updated_atFROM user_resources