1- use pgls_diagnostics:: { Category , Severity , category } ;
1+ use pgls_diagnostics:: { category , Category , Severity } ;
22use serde_json:: Value ;
33
44use crate :: { SplinterAdvices , SplinterDiagnostic , SplinterQueryResult } ;
@@ -11,8 +11,15 @@ impl From<SplinterQueryResult> for SplinterDiagnostic {
1111 let ( schema, object_name, object_type, additional_metadata) =
1212 extract_metadata_fields ( & result. metadata ) ;
1313
14+ // for now, we just take the first category as the group
15+ let group = result
16+ . categories
17+ . first ( )
18+ . map ( |s| s. to_lowercase ( ) )
19+ . unwrap_or_else ( || "unknown" . to_string ( ) ) ;
20+
1421 SplinterDiagnostic {
15- category : rule_name_to_category ( & result. name ) ,
22+ category : rule_name_to_category ( & result. name , & group ) ,
1623 message : result. detail . into ( ) ,
1724 severity,
1825 advices : SplinterAdvices {
@@ -37,32 +44,60 @@ fn parse_severity(level: &str) -> Severity {
3744 }
3845}
3946
40- /// Convert rule name to a Category
47+ /// Convert rule name and group to a Category
4148/// Note: Rule names use snake_case, but categories use camelCase
42- fn rule_name_to_category ( name : & str ) -> & ' static Category {
43- match name {
44- "unindexed_foreign_keys" => category ! ( "dblint/splinter/unindexedForeignKeys" ) ,
45- "auth_users_exposed" => category ! ( "dblint/splinter/authUsersExposed" ) ,
46- "auth_rls_initplan" => category ! ( "dblint/splinter/authRlsInitplan" ) ,
47- "no_primary_key" => category ! ( "dblint/splinter/noPrimaryKey" ) ,
48- "unused_index" => category ! ( "dblint/splinter/unusedIndex" ) ,
49- "multiple_permissive_policies" => category ! ( "dblint/splinter/multiplePermissivePolicies" ) ,
50- "policy_exists_rls_disabled" => category ! ( "dblint/splinter/policyExistsRlsDisabled" ) ,
51- "rls_enabled_no_policy" => category ! ( "dblint/splinter/rlsEnabledNoPolicy" ) ,
52- "duplicate_index" => category ! ( "dblint/splinter/duplicateIndex" ) ,
53- "security_definer_view" => category ! ( "dblint/splinter/securityDefinerView" ) ,
54- "function_search_path_mutable" => category ! ( "dblint/splinter/functionSearchPathMutable" ) ,
55- "rls_disabled_in_public" => category ! ( "dblint/splinter/rlsDisabledInPublic" ) ,
56- "extension_in_public" => category ! ( "dblint/splinter/extensionInPublic" ) ,
57- "rls_references_user_metadata" => category ! ( "dblint/splinter/rlsReferencesUserMetadata" ) ,
58- "materialized_view_in_api" => category ! ( "dblint/splinter/materializedViewInApi" ) ,
59- "foreign_table_in_api" => category ! ( "dblint/splinter/foreignTableInApi" ) ,
60- "unsupported_reg_types" => category ! ( "dblint/splinter/unsupportedRegTypes" ) ,
61- "insecure_queue_exposed_in_api" => category ! ( "dblint/splinter/insecureQueueExposedInApi" ) ,
62- "table_bloat" => category ! ( "dblint/splinter/tableBloat" ) ,
63- "fkey_to_auth_unique" => category ! ( "dblint/splinter/fkeyToAuthUnique" ) ,
64- "extension_versions_outdated" => category ! ( "dblint/splinter/extensionVersionsOutdated" ) ,
65- _ => category ! ( "dblint/splinter/unknown" ) ,
49+ fn rule_name_to_category ( name : & str , group : & str ) -> & ' static Category {
50+ match ( group, name) {
51+ ( "performance" , "unindexed_foreign_keys" ) => {
52+ category ! ( "splinter/performance/unindexedForeignKeys" )
53+ }
54+ ( "performance" , "auth_rls_initplan" ) => {
55+ category ! ( "splinter/performance/authRlsInitplan" )
56+ }
57+ ( "performance" , "no_primary_key" ) => category ! ( "splinter/performance/noPrimaryKey" ) ,
58+ ( "performance" , "unused_index" ) => category ! ( "splinter/performance/unusedIndex" ) ,
59+ ( "performance" , "duplicate_index" ) => category ! ( "splinter/performance/duplicateIndex" ) ,
60+ ( "performance" , "table_bloat" ) => category ! ( "splinter/performance/tableBloat" ) ,
61+ ( "performance" , "multiple_permissive_policies" ) => {
62+ category ! ( "splinter/performance/multiplePermissivePolicies" )
63+ }
64+ ( "security" , "auth_users_exposed" ) => category ! ( "splinter/security/authUsersExposed" ) ,
65+ ( "security" , "extension_versions_outdated" ) => {
66+ category ! ( "splinter/security/extensionVersionsOutdated" )
67+ }
68+ ( "security" , "policy_exists_rls_disabled" ) => {
69+ category ! ( "splinter/security/policyExistsRlsDisabled" )
70+ }
71+ ( "security" , "rls_enabled_no_policy" ) => {
72+ category ! ( "splinter/security/rlsEnabledNoPolicy" )
73+ }
74+ ( "security" , "security_definer_view" ) => {
75+ category ! ( "splinter/security/securityDefinerView" )
76+ }
77+ ( "security" , "function_search_path_mutable" ) => {
78+ category ! ( "splinter/security/functionSearchPathMutable" )
79+ }
80+ ( "security" , "rls_disabled_in_public" ) => {
81+ category ! ( "splinter/security/rlsDisabledInPublic" )
82+ }
83+ ( "security" , "extension_in_public" ) => category ! ( "splinter/security/extensionInPublic" ) ,
84+ ( "security" , "rls_references_user_metadata" ) => {
85+ category ! ( "splinter/security/rlsReferencesUserMetadata" )
86+ }
87+ ( "security" , "materialized_view_in_api" ) => {
88+ category ! ( "splinter/security/materializedViewInApi" )
89+ }
90+ ( "security" , "foreign_table_in_api" ) => {
91+ category ! ( "splinter/security/foreignTableInApi" )
92+ }
93+ ( "security" , "unsupported_reg_types" ) => {
94+ category ! ( "splinter/security/unsupportedRegTypes" )
95+ }
96+ ( "security" , "insecure_queue_exposed_in_api" ) => {
97+ category ! ( "splinter/security/insecureQueueExposedInApi" )
98+ }
99+ ( "security" , "fkey_to_auth_unique" ) => category ! ( "splinter/security/fkeyToAuthUnique" ) ,
100+ _ => category ! ( "splinter/unknown/unknown" ) ,
66101 }
67102}
68103
0 commit comments