mirror of
https://github.com/elicpeter/nyx.git
synced 2026-06-12 19:55:14 +02:00
cargo fmt
This commit is contained in:
parent
bec7bbf96c
commit
3a35cd6c8f
294 changed files with 6809 additions and 3911 deletions
|
|
@ -28,86 +28,314 @@ struct DriverRule {
|
|||
|
||||
const DRIVER_RULES: &[DriverRule] = &[
|
||||
// Python — relational
|
||||
DriverRule { leaf: "psycopg2.connect", kind: DataStoreKind::Sql, label: "PostgreSQL (psycopg2)" },
|
||||
DriverRule { leaf: "psycopg.connect", kind: DataStoreKind::Sql, label: "PostgreSQL (psycopg3)" },
|
||||
DriverRule { leaf: "mysql.connector.connect", kind: DataStoreKind::Sql, label: "MySQL (mysql.connector)" },
|
||||
DriverRule { leaf: "MySQLdb.connect", kind: DataStoreKind::Sql, label: "MySQL (MySQLdb)" },
|
||||
DriverRule { leaf: "pymysql.connect", kind: DataStoreKind::Sql, label: "MySQL (PyMySQL)" },
|
||||
DriverRule { leaf: "sqlite3.connect", kind: DataStoreKind::Sql, label: "SQLite (sqlite3)" },
|
||||
DriverRule { leaf: "sqlalchemy.create_engine", kind: DataStoreKind::Sql, label: "SQLAlchemy" },
|
||||
DriverRule { leaf: "django.db.connection", kind: DataStoreKind::Sql, label: "Django ORM" },
|
||||
DriverRule {
|
||||
leaf: "psycopg2.connect",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "PostgreSQL (psycopg2)",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "psycopg.connect",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "PostgreSQL (psycopg3)",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "mysql.connector.connect",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "MySQL (mysql.connector)",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "MySQLdb.connect",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "MySQL (MySQLdb)",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "pymysql.connect",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "MySQL (PyMySQL)",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "sqlite3.connect",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "SQLite (sqlite3)",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "sqlalchemy.create_engine",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "SQLAlchemy",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "django.db.connection",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "Django ORM",
|
||||
},
|
||||
// Python — kv / doc
|
||||
DriverRule { leaf: "redis.Redis", kind: DataStoreKind::KeyValue, label: "Redis" },
|
||||
DriverRule { leaf: "redis.from_url", kind: DataStoreKind::KeyValue, label: "Redis" },
|
||||
DriverRule { leaf: "pymongo.MongoClient", kind: DataStoreKind::Document, label: "MongoDB" },
|
||||
DriverRule { leaf: "boto3.client", kind: DataStoreKind::BlobStore, label: "AWS (boto3)" },
|
||||
DriverRule { leaf: "boto3.resource", kind: DataStoreKind::BlobStore, label: "AWS (boto3)" },
|
||||
|
||||
DriverRule {
|
||||
leaf: "redis.Redis",
|
||||
kind: DataStoreKind::KeyValue,
|
||||
label: "Redis",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "redis.from_url",
|
||||
kind: DataStoreKind::KeyValue,
|
||||
label: "Redis",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "pymongo.MongoClient",
|
||||
kind: DataStoreKind::Document,
|
||||
label: "MongoDB",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "boto3.client",
|
||||
kind: DataStoreKind::BlobStore,
|
||||
label: "AWS (boto3)",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "boto3.resource",
|
||||
kind: DataStoreKind::BlobStore,
|
||||
label: "AWS (boto3)",
|
||||
},
|
||||
// JavaScript / TypeScript — relational
|
||||
DriverRule { leaf: "knex", kind: DataStoreKind::Sql, label: "Knex.js" },
|
||||
DriverRule { leaf: "createConnection", kind: DataStoreKind::Sql, label: "MySQL/Postgres (mysql/pg)" },
|
||||
DriverRule { leaf: "Sequelize", kind: DataStoreKind::Sql, label: "Sequelize" },
|
||||
DriverRule { leaf: "TypeORM.createConnection", kind: DataStoreKind::Sql, label: "TypeORM" },
|
||||
DriverRule { leaf: "PrismaClient", kind: DataStoreKind::Sql, label: "Prisma" },
|
||||
DriverRule { leaf: "pool.query", kind: DataStoreKind::Sql, label: "pg/mysql pool" },
|
||||
DriverRule { leaf: "client.query", kind: DataStoreKind::Sql, label: "pg client" },
|
||||
DriverRule { leaf: "db.query", kind: DataStoreKind::Sql, label: "Generic SQL driver" },
|
||||
DriverRule {
|
||||
leaf: "knex",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "Knex.js",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "createConnection",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "MySQL/Postgres (mysql/pg)",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "Sequelize",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "Sequelize",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "TypeORM.createConnection",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "TypeORM",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "PrismaClient",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "Prisma",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "pool.query",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "pg/mysql pool",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "client.query",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "pg client",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "db.query",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "Generic SQL driver",
|
||||
},
|
||||
// JS — kv / doc
|
||||
DriverRule { leaf: "redis.createClient", kind: DataStoreKind::KeyValue, label: "Redis (node-redis)" },
|
||||
DriverRule { leaf: "ioredis", kind: DataStoreKind::KeyValue, label: "ioredis" },
|
||||
DriverRule { leaf: "MongoClient.connect", kind: DataStoreKind::Document, label: "MongoDB (node)" },
|
||||
DriverRule { leaf: "AWS.S3", kind: DataStoreKind::BlobStore, label: "AWS S3" },
|
||||
|
||||
DriverRule {
|
||||
leaf: "redis.createClient",
|
||||
kind: DataStoreKind::KeyValue,
|
||||
label: "Redis (node-redis)",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "ioredis",
|
||||
kind: DataStoreKind::KeyValue,
|
||||
label: "ioredis",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "MongoClient.connect",
|
||||
kind: DataStoreKind::Document,
|
||||
label: "MongoDB (node)",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "AWS.S3",
|
||||
kind: DataStoreKind::BlobStore,
|
||||
label: "AWS S3",
|
||||
},
|
||||
// Java — JDBC / Hibernate
|
||||
DriverRule { leaf: "DriverManager.getConnection", kind: DataStoreKind::Sql, label: "JDBC" },
|
||||
DriverRule { leaf: "JdbcTemplate", kind: DataStoreKind::Sql, label: "Spring JdbcTemplate" },
|
||||
DriverRule { leaf: "EntityManager", kind: DataStoreKind::Sql, label: "JPA EntityManager" },
|
||||
DriverRule { leaf: "SessionFactory.openSession", kind: DataStoreKind::Sql, label: "Hibernate" },
|
||||
DriverRule { leaf: "Jedis", kind: DataStoreKind::KeyValue, label: "Jedis (Redis)" },
|
||||
DriverRule { leaf: "MongoClients.create", kind: DataStoreKind::Document, label: "MongoDB (java-driver)" },
|
||||
|
||||
DriverRule {
|
||||
leaf: "DriverManager.getConnection",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "JDBC",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "JdbcTemplate",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "Spring JdbcTemplate",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "EntityManager",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "JPA EntityManager",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "SessionFactory.openSession",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "Hibernate",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "Jedis",
|
||||
kind: DataStoreKind::KeyValue,
|
||||
label: "Jedis (Redis)",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "MongoClients.create",
|
||||
kind: DataStoreKind::Document,
|
||||
label: "MongoDB (java-driver)",
|
||||
},
|
||||
// Go — sql + ORM
|
||||
DriverRule { leaf: "sql.Open", kind: DataStoreKind::Sql, label: "database/sql" },
|
||||
DriverRule { leaf: "gorm.Open", kind: DataStoreKind::Sql, label: "GORM" },
|
||||
DriverRule { leaf: "sqlx.Connect", kind: DataStoreKind::Sql, label: "sqlx" },
|
||||
DriverRule { leaf: "sqlx.Open", kind: DataStoreKind::Sql, label: "sqlx" },
|
||||
DriverRule { leaf: "redis.NewClient", kind: DataStoreKind::KeyValue, label: "go-redis" },
|
||||
DriverRule { leaf: "mongo.Connect", kind: DataStoreKind::Document, label: "MongoDB (go-driver)" },
|
||||
|
||||
DriverRule {
|
||||
leaf: "sql.Open",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "database/sql",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "gorm.Open",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "GORM",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "sqlx.Connect",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "sqlx",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "sqlx.Open",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "sqlx",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "redis.NewClient",
|
||||
kind: DataStoreKind::KeyValue,
|
||||
label: "go-redis",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "mongo.Connect",
|
||||
kind: DataStoreKind::Document,
|
||||
label: "MongoDB (go-driver)",
|
||||
},
|
||||
// PHP — Eloquent / PDO
|
||||
DriverRule { leaf: "PDO", kind: DataStoreKind::Sql, label: "PDO" },
|
||||
DriverRule { leaf: "Eloquent::find", kind: DataStoreKind::Sql, label: "Laravel Eloquent" },
|
||||
DriverRule { leaf: "Eloquent::where", kind: DataStoreKind::Sql, label: "Laravel Eloquent" },
|
||||
DriverRule { leaf: "DB::connection", kind: DataStoreKind::Sql, label: "Laravel DB" },
|
||||
DriverRule { leaf: "Doctrine", kind: DataStoreKind::Sql, label: "Doctrine ORM" },
|
||||
|
||||
DriverRule {
|
||||
leaf: "PDO",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "PDO",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "Eloquent::find",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "Laravel Eloquent",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "Eloquent::where",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "Laravel Eloquent",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "DB::connection",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "Laravel DB",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "Doctrine",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "Doctrine ORM",
|
||||
},
|
||||
// Ruby — ActiveRecord
|
||||
DriverRule { leaf: "ActiveRecord::Base.connection", kind: DataStoreKind::Sql, label: "ActiveRecord" },
|
||||
DriverRule { leaf: "ActiveRecord::Base.find", kind: DataStoreKind::Sql, label: "ActiveRecord" },
|
||||
DriverRule { leaf: ".find_by_sql", kind: DataStoreKind::Sql, label: "ActiveRecord raw SQL" },
|
||||
|
||||
DriverRule {
|
||||
leaf: "ActiveRecord::Base.connection",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "ActiveRecord",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "ActiveRecord::Base.find",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "ActiveRecord",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: ".find_by_sql",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "ActiveRecord raw SQL",
|
||||
},
|
||||
// Rust — sqlx / diesel
|
||||
DriverRule { leaf: "sqlx::query", kind: DataStoreKind::Sql, label: "sqlx" },
|
||||
DriverRule { leaf: "sqlx::query_as", kind: DataStoreKind::Sql, label: "sqlx" },
|
||||
DriverRule { leaf: "diesel::sql_query", kind: DataStoreKind::Sql, label: "Diesel" },
|
||||
DriverRule { leaf: "PgConnection::establish", kind: DataStoreKind::Sql, label: "Diesel" },
|
||||
|
||||
DriverRule {
|
||||
leaf: "sqlx::query",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "sqlx",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "sqlx::query_as",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "sqlx",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "diesel::sql_query",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "Diesel",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "PgConnection::establish",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "Diesel",
|
||||
},
|
||||
// Type-qualified — fires when the SSA type-fact engine resolves a
|
||||
// receiver to `TypeKind::DatabaseConnection` regardless of the bare
|
||||
// callee name (e.g. `conn = psycopg2.connect(); conn.cursor()` →
|
||||
// typed_call_receivers maps the `.cursor` ordinal to "DatabaseConnection").
|
||||
DriverRule { leaf: "DatabaseConnection.cursor", kind: DataStoreKind::Sql, label: "Database connection" },
|
||||
DriverRule { leaf: "DatabaseConnection.execute", kind: DataStoreKind::Sql, label: "Database connection" },
|
||||
DriverRule { leaf: "DatabaseConnection.query", kind: DataStoreKind::Sql, label: "Database connection" },
|
||||
DriverRule { leaf: "DatabaseConnection.exec", kind: DataStoreKind::Sql, label: "Database connection" },
|
||||
DriverRule { leaf: "DatabaseConnection.prepare", kind: DataStoreKind::Sql, label: "Database connection" },
|
||||
DriverRule { leaf: "DatabaseConnection.commit", kind: DataStoreKind::Sql, label: "Database connection" },
|
||||
DriverRule { leaf: "FileHandle.read", kind: DataStoreKind::Filesystem, label: "Filesystem" },
|
||||
DriverRule { leaf: "FileHandle.write", kind: DataStoreKind::Filesystem, label: "Filesystem" },
|
||||
DriverRule { leaf: "FileHandle.close", kind: DataStoreKind::Filesystem, label: "Filesystem" },
|
||||
|
||||
DriverRule {
|
||||
leaf: "DatabaseConnection.cursor",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "Database connection",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "DatabaseConnection.execute",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "Database connection",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "DatabaseConnection.query",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "Database connection",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "DatabaseConnection.exec",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "Database connection",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "DatabaseConnection.prepare",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "Database connection",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "DatabaseConnection.commit",
|
||||
kind: DataStoreKind::Sql,
|
||||
label: "Database connection",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "FileHandle.read",
|
||||
kind: DataStoreKind::Filesystem,
|
||||
label: "Filesystem",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "FileHandle.write",
|
||||
kind: DataStoreKind::Filesystem,
|
||||
label: "Filesystem",
|
||||
},
|
||||
DriverRule {
|
||||
leaf: "FileHandle.close",
|
||||
kind: DataStoreKind::Filesystem,
|
||||
label: "Filesystem",
|
||||
},
|
||||
// Filesystem (best-effort: language-agnostic open()-family)
|
||||
DriverRule { leaf: "open", kind: DataStoreKind::Filesystem, label: "Filesystem" },
|
||||
DriverRule {
|
||||
leaf: "open",
|
||||
kind: DataStoreKind::Filesystem,
|
||||
label: "Filesystem",
|
||||
},
|
||||
];
|
||||
|
||||
/// Walk every function summary's callee list and emit one
|
||||
|
|
@ -127,7 +355,9 @@ pub fn detect_data_stores(summaries: &GlobalSummaries) -> Vec<SurfaceNode> {
|
|||
let mut seen: std::collections::HashSet<(String, u32, String)> =
|
||||
std::collections::HashSet::new();
|
||||
for (key, summary) in summaries.iter() {
|
||||
let typed = summaries.get_ssa(key).map(|s| s.typed_call_receivers.as_slice());
|
||||
let typed = summaries
|
||||
.get_ssa(key)
|
||||
.map(|s| s.typed_call_receivers.as_slice());
|
||||
for callee in &summary.callees {
|
||||
let rule = match_rule(&callee.name).or_else(|| {
|
||||
typed
|
||||
|
|
@ -136,11 +366,7 @@ pub fn detect_data_stores(summaries: &GlobalSummaries) -> Vec<SurfaceNode> {
|
|||
});
|
||||
let Some(rule) = rule else { continue };
|
||||
let location = call_site_location(summary, callee);
|
||||
let dedup = (
|
||||
location.file.clone(),
|
||||
location.line,
|
||||
rule.label.to_string(),
|
||||
);
|
||||
let dedup = (location.file.clone(), location.line, rule.label.to_string());
|
||||
if !seen.insert(dedup) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -170,7 +396,10 @@ fn qualify(container: &str, callee_name: &str) -> String {
|
|||
/// `Vec<(ordinal, container)>` per function. Typical lengths are 0 to a
|
||||
/// few dozen; a HashMap-per-summary would be wasteful.
|
||||
fn container_for_ordinal(typed: &[(u32, String)], ordinal: u32) -> Option<&str> {
|
||||
typed.iter().find(|(o, _)| *o == ordinal).map(|(_, c)| c.as_str())
|
||||
typed
|
||||
.iter()
|
||||
.find(|(o, _)| *o == ordinal)
|
||||
.map(|(_, c)| c.as_str())
|
||||
}
|
||||
|
||||
fn match_rule(callee: &str) -> Option<&'static DriverRule> {
|
||||
|
|
@ -285,11 +514,8 @@ mod tests {
|
|||
#[test]
|
||||
fn dedup_collapses_repeats_in_same_file() {
|
||||
let mut gs = GlobalSummaries::new();
|
||||
let (k, s) = summary_with_callees(
|
||||
"init",
|
||||
"app.py",
|
||||
&["psycopg2.connect", "psycopg2.connect"],
|
||||
);
|
||||
let (k, s) =
|
||||
summary_with_callees("init", "app.py", &["psycopg2.connect", "psycopg2.connect"]);
|
||||
gs.insert(k, s);
|
||||
let nodes = detect_data_stores(&gs);
|
||||
assert_eq!(nodes.len(), 1);
|
||||
|
|
@ -352,14 +578,12 @@ mod tests {
|
|||
file_path: "app.py".into(),
|
||||
lang: "python".into(),
|
||||
param_count: 0,
|
||||
callees: vec![
|
||||
{
|
||||
let mut c = CalleeSite::bare("conn.cursor");
|
||||
c.ordinal = 7;
|
||||
c.span = Some((4, 8));
|
||||
c
|
||||
},
|
||||
],
|
||||
callees: vec![{
|
||||
let mut c = CalleeSite::bare("conn.cursor");
|
||||
c.ordinal = 7;
|
||||
c.span = Some((4, 8));
|
||||
c
|
||||
}],
|
||||
..Default::default()
|
||||
};
|
||||
gs.insert(key.clone(), summary);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue