-
Notifications
You must be signed in to change notification settings - Fork 107
refractor(splinter): allow non-supabase rules to run always #597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
59d1c1d
9d34d82
f3fd30c
964de40
09c5718
bc721f7
92005d8
1dcb8d7
60fd54e
e7a2dd5
c35affc
81b811c
79f4c9f
154e3bb
6babd1a
600f273
3469bbf
2cdf3e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ pub struct SplinterParams<'a> { | |
| pub conn: &'a PgPool, | ||
| } | ||
|
|
||
| async fn check_required_roles(conn: &PgPool) -> Result<bool, sqlx::Error> { | ||
| async fn check_supabase_roles(conn: &PgPool) -> Result<bool, sqlx::Error> { | ||
| let required_roles = ["anon", "authenticated", "service_role"]; | ||
|
|
||
| let existing_roles: Vec<String> = | ||
|
|
@@ -32,17 +32,19 @@ async fn check_required_roles(conn: &PgPool) -> Result<bool, sqlx::Error> { | |
| pub async fn run_splinter( | ||
| params: SplinterParams<'_>, | ||
| ) -> Result<Vec<SplinterDiagnostic>, sqlx::Error> { | ||
| // check if required supabase roles exist | ||
| // if they don't exist, return empty diagnostics since splinter is supabase-specific | ||
| // opened an issue to make it less supabase-specific: https://github.com/supabase/splinter/issues/135 | ||
| let has_roles = check_required_roles(params.conn).await?; | ||
| if !has_roles { | ||
| return Ok(Vec::new()); | ||
| } | ||
| let mut all_results = Vec::new(); | ||
|
|
||
| let generic_results = query::load_generic_splinter_results(params.conn).await?; | ||
| all_results.extend(generic_results); | ||
|
|
||
| let results = query::load_splinter_results(params.conn).await?; | ||
| // Only run Supabase-specific rules if the required roles exist | ||
| let has_supabase_roles = check_supabase_roles(params.conn).await?; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice! curious: did the supabase team confirm that this check is the best way to identify a supabase database?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nope, but for squawk this is what is required to exist for the rules query to not crash :D |
||
| if has_supabase_roles { | ||
| let supabase_results = query::load_supabase_splinter_results(params.conn).await?; | ||
| all_results.extend(supabase_results); | ||
| } | ||
|
|
||
| let diagnostics: Vec<SplinterDiagnostic> = results.into_iter().map(Into::into).collect(); | ||
| let diagnostics: Vec<SplinterDiagnostic> = all_results.into_iter().map(Into::into).collect(); | ||
|
|
||
| Ok(diagnostics) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as I understand it, rules are per default put into the generic category.
what happens if supabase adds a new rule to the spliter that's supabase-specific?
that might break linting in case a table isn't defined for non-supabase databases, right?
should we throw during build if there's an unknown rule in the splinter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great catch!