Skip to content
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

run_process_utility_hook is tangled everywhere, making logic hard to follow #79

Open
steve-chavez opened this issue Feb 2, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@steve-chavez
Copy link
Member

Problem

Right now the different modules logic are tangled per statement and the standard hook (run_process_utility_hook) is scattered everywhere. This makes it harder to maintain the code and to disable modules according to the pg version (#78, #50 (comment)).

static void
supautils_hook(PROCESS_UTILITY_PARAMS)
{
	Node   *utility_stmt = pstmt->utilityStmt;

	switch (utility_stmt->type)
	{
     		case T_AlterRoleStmt:
                  // privileged role logic..
                  // reserved role logic..   
                case T_CreateExtensionStmt:
                 // constrained extensions logic..
                 // privileged extensions logic..

Solution

Refactor the codebase so each module has a single entrypoint and the standard hook is invoked in one single place. Basically:

static void
supautils_hook(PROCESS_UTILITY_PARAMS)
{
  Node   *utility_stmt = pstmt->utilityStmt;
  ret1 = privileged_role_setup(utility_stmt)
  ret2 = reserved_roles_setup(utility_stmt)
  ret3 = privileged_extensions_setup(utility_stmt)
  ret4 = constrained_extensions_setup(utility_stmt)
  
  run_process_utility_hook(prev_hook);

  cleanup(ret1, ret2, ret3, ret4); // or have multiple cleanups depending on the module
@steve-chavez steve-chavez added the enhancement New feature or request label Feb 2, 2024
@steve-chavez steve-chavez changed the title Refactor to allow disabling features according to pg version run_process_utility_hook is tangled everywhere, making logic hard to follow Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant