From df21c6847c9b767e889647594d84238f4fc46c44 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Thu, 21 Nov 2024 14:16:57 +0100 Subject: [PATCH] Please RuboCop --- .../42-evr_extension_permissions.rb | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/hooks/pre_commit/42-evr_extension_permissions.rb b/hooks/pre_commit/42-evr_extension_permissions.rb index cbe66dac..e842d30e 100644 --- a/hooks/pre_commit/42-evr_extension_permissions.rb +++ b/hooks/pre_commit/42-evr_extension_permissions.rb @@ -2,35 +2,34 @@ def check_remote_evr_extension_permissions # Managed databases will be handled automatically. return if local_postgresql? return unless katello_enabled? - + config = load_db_config('foreman') - + # If postgres is the owner of the DB, then the permissions will not matter. return if config[:username] == 'postgres' - + evr_existence_command = pg_sql_statement("SELECT 1 FROM pg_extension WHERE extname = 'evr';") logger.debug "Checking if the evr extension exists via #{evr_existence_command}" evr_existence_output, = execute_command(evr_existence_command, false, true, pg_env(config)) - + # If the evr extension does not exist, then we can skip this check. return if evr_existence_output&.strip != '1' - - check_evr_owner_sql = "SELECT CASE" \ - " WHEN r.rolname = '#{config[:username]}' THEN 0" \ - " ELSE 1" \ - " END AS evr_owned_by_postgres" \ - " FROM pg_extension e" \ - " JOIN pg_roles r ON e.extowner = r.oid" \ - " WHERE e.extname = 'evr';" - + + check_evr_owner_sql = "SELECT CASE " \ + "WHEN r.rolname = '#{config[:username]}' THEN 0 " \ + "ELSE 1 " \ + "END AS evr_owned_by_postgres " \ + "FROM pg_extension e " \ + "JOIN pg_roles r ON e.extowner = r.oid " \ + "WHERE e.extname = 'evr';" + command = pg_sql_statement(check_evr_owner_sql) logger.debug "Checking if the evr extension is owned by the postgres user via #{command}" output, = execute_command(command, false, true, pg_env(config)) - + case output&.strip when '0' - # The evr extension is owned by the foreman DB owner, so we can skip this check. - return + logger.debug('PostgreSQL EVR extension owned by Foreman DB owner') when '1' fail_and_exit("The evr extension is not owned by the foreman DB owner. Please run the following command to fix it: " \ "UPDATE pg_extension SET extowner = (SELECT oid FROM pg_authid WHERE rolname='#{config[:username]}') WHERE extname='evr';")