1- use pgls_diagnostics:: { Category , DatabaseObjectOwned , Severity , category } ;
1+ use pgls_diagnostics:: { DatabaseObjectOwned , Severity } ;
22use serde_json:: Value ;
33
4- use crate :: { SplinterAdvices , SplinterDiagnostic , SplinterQueryResult } ;
4+ use crate :: { SplinterAdvices , SplinterDiagnostic , SplinterQueryResult , registry } ;
55
66impl From < SplinterQueryResult > for SplinterDiagnostic {
77 fn from ( result : SplinterQueryResult ) -> Self {
@@ -18,8 +18,13 @@ impl From<SplinterQueryResult> for SplinterDiagnostic {
1818 . map ( |s| s. to_lowercase ( ) )
1919 . unwrap_or_else ( || "unknown" . to_string ( ) ) ;
2020
21+ let category = registry:: get_rule_category ( & result. name ) . unwrap_or_else ( || {
22+ eprintln ! ( "Warning: Unknown splinter rule: {group}/{}" , result. name) ;
23+ pgls_diagnostics:: category!( "splinter" )
24+ } ) ;
25+
2126 SplinterDiagnostic {
22- category : rule_name_to_category ( & result . name , & group ) ,
27+ category,
2328 message : result. detail . into ( ) ,
2429 severity,
2530 db_object : object_name. as_ref ( ) . map ( |name| DatabaseObjectOwned {
@@ -49,64 +54,6 @@ fn parse_severity(level: &str) -> Severity {
4954 }
5055}
5156
52- /// Convert rule name and group to a Category
53- /// Note: Rule names use snake_case, but categories use camelCase
54- fn rule_name_to_category ( name : & str , group : & str ) -> & ' static Category {
55- // we cannot use convert_case here because category! macro requires a string literal
56- match ( group, name) {
57- ( "performance" , "unindexed_foreign_keys" ) => {
58- category ! ( "splinter/performance/unindexedForeignKeys" )
59- }
60- ( "performance" , "auth_rls_initplan" ) => {
61- category ! ( "splinter/performance/authRlsInitplan" )
62- }
63- ( "performance" , "no_primary_key" ) => category ! ( "splinter/performance/noPrimaryKey" ) ,
64- ( "performance" , "unused_index" ) => category ! ( "splinter/performance/unusedIndex" ) ,
65- ( "performance" , "duplicate_index" ) => category ! ( "splinter/performance/duplicateIndex" ) ,
66- ( "performance" , "table_bloat" ) => category ! ( "splinter/performance/tableBloat" ) ,
67- ( "performance" , "multiple_permissive_policies" ) => {
68- category ! ( "splinter/performance/multiplePermissivePolicies" )
69- }
70- ( "security" , "auth_users_exposed" ) => category ! ( "splinter/security/authUsersExposed" ) ,
71- ( "security" , "extension_versions_outdated" ) => {
72- category ! ( "splinter/security/extensionVersionsOutdated" )
73- }
74- ( "security" , "policy_exists_rls_disabled" ) => {
75- category ! ( "splinter/security/policyExistsRlsDisabled" )
76- }
77- ( "security" , "rls_enabled_no_policy" ) => {
78- category ! ( "splinter/security/rlsEnabledNoPolicy" )
79- }
80- ( "security" , "security_definer_view" ) => {
81- category ! ( "splinter/security/securityDefinerView" )
82- }
83- ( "security" , "function_search_path_mutable" ) => {
84- category ! ( "splinter/security/functionSearchPathMutable" )
85- }
86- ( "security" , "rls_disabled_in_public" ) => {
87- category ! ( "splinter/security/rlsDisabledInPublic" )
88- }
89- ( "security" , "extension_in_public" ) => category ! ( "splinter/security/extensionInPublic" ) ,
90- ( "security" , "rls_references_user_metadata" ) => {
91- category ! ( "splinter/security/rlsReferencesUserMetadata" )
92- }
93- ( "security" , "materialized_view_in_api" ) => {
94- category ! ( "splinter/security/materializedViewInApi" )
95- }
96- ( "security" , "foreign_table_in_api" ) => {
97- category ! ( "splinter/security/foreignTableInApi" )
98- }
99- ( "security" , "unsupported_reg_types" ) => {
100- category ! ( "splinter/security/unsupportedRegTypes" )
101- }
102- ( "security" , "insecure_queue_exposed_in_api" ) => {
103- category ! ( "splinter/security/insecureQueueExposedInApi" )
104- }
105- ( "security" , "fkey_to_auth_unique" ) => category ! ( "splinter/security/fkeyToAuthUnique" ) ,
106- _ => panic ! ( "Unknown splinter rule: {group}/{name}" ) ,
107- }
108- }
109-
11057/// Extract common metadata fields and return the rest as additional_metadata
11158fn extract_metadata_fields (
11259 metadata : & Value ,
0 commit comments