Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ jobs:
- name: Install toolchain
uses: moonrepo/setup-rust@v1
with:
components: clippy
cache-base: main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion crates/pgls_cli/src/service/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn spawn_daemon(
cmd.arg(format!("--log-path={}", log_path.display()));
}
if let Some(log_file_name_prefix) = log_file_name_prefix {
cmd.arg(format!("--log-prefix-name={}", log_file_name_prefix));
cmd.arg(format!("--log-prefix-name={log_file_name_prefix}"));
}
cmd.creation_flags(CREATE_NEW_PROCESS_GROUP);

Expand Down
69 changes: 8 additions & 61 deletions crates/pgls_splinter/src/convert.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use pgls_diagnostics::{Category, DatabaseObjectOwned, Severity, category};
use pgls_diagnostics::{DatabaseObjectOwned, Severity};
use serde_json::Value;

use crate::{SplinterAdvices, SplinterDiagnostic, SplinterQueryResult};
use crate::{SplinterAdvices, SplinterDiagnostic, SplinterQueryResult, registry};

impl From<SplinterQueryResult> for SplinterDiagnostic {
fn from(result: SplinterQueryResult) -> Self {
Expand All @@ -18,8 +18,13 @@ impl From<SplinterQueryResult> for SplinterDiagnostic {
.map(|s| s.to_lowercase())
.unwrap_or_else(|| "unknown".to_string());

let category = registry::get_rule_category(&result.name).unwrap_or_else(|| {
eprintln!("Warning: Unknown splinter rule: {group}/{}", result.name);
pgls_diagnostics::category!("splinter")
});

SplinterDiagnostic {
category: rule_name_to_category(&result.name, &group),
category,
message: result.detail.into(),
severity,
db_object: object_name.as_ref().map(|name| DatabaseObjectOwned {
Expand Down Expand Up @@ -49,64 +54,6 @@ fn parse_severity(level: &str) -> Severity {
}
}

/// Convert rule name and group to a Category
/// Note: Rule names use snake_case, but categories use camelCase
fn rule_name_to_category(name: &str, group: &str) -> &'static Category {
// we cannot use convert_case here because category! macro requires a string literal
match (group, name) {
("performance", "unindexed_foreign_keys") => {
category!("splinter/performance/unindexedForeignKeys")
}
("performance", "auth_rls_initplan") => {
category!("splinter/performance/authRlsInitplan")
}
("performance", "no_primary_key") => category!("splinter/performance/noPrimaryKey"),
("performance", "unused_index") => category!("splinter/performance/unusedIndex"),
("performance", "duplicate_index") => category!("splinter/performance/duplicateIndex"),
("performance", "table_bloat") => category!("splinter/performance/tableBloat"),
("performance", "multiple_permissive_policies") => {
category!("splinter/performance/multiplePermissivePolicies")
}
("security", "auth_users_exposed") => category!("splinter/security/authUsersExposed"),
("security", "extension_versions_outdated") => {
category!("splinter/security/extensionVersionsOutdated")
}
("security", "policy_exists_rls_disabled") => {
category!("splinter/security/policyExistsRlsDisabled")
}
("security", "rls_enabled_no_policy") => {
category!("splinter/security/rlsEnabledNoPolicy")
}
("security", "security_definer_view") => {
category!("splinter/security/securityDefinerView")
}
("security", "function_search_path_mutable") => {
category!("splinter/security/functionSearchPathMutable")
}
("security", "rls_disabled_in_public") => {
category!("splinter/security/rlsDisabledInPublic")
}
("security", "extension_in_public") => category!("splinter/security/extensionInPublic"),
("security", "rls_references_user_metadata") => {
category!("splinter/security/rlsReferencesUserMetadata")
}
("security", "materialized_view_in_api") => {
category!("splinter/security/materializedViewInApi")
}
("security", "foreign_table_in_api") => {
category!("splinter/security/foreignTableInApi")
}
("security", "unsupported_reg_types") => {
category!("splinter/security/unsupportedRegTypes")
}
("security", "insecure_queue_exposed_in_api") => {
category!("splinter/security/insecureQueueExposedInApi")
}
("security", "fkey_to_auth_unique") => category!("splinter/security/fkeyToAuthUnique"),
_ => panic!("Unknown splinter rule: {group}/{name}"),
}
}

/// Extract common metadata fields and return the rest as additional_metadata
fn extract_metadata_fields(
metadata: &Value,
Expand Down
Loading