Skip to content

Commit df21c68

Browse files
ekohlehelms
authored andcommitted
Please RuboCop
1 parent e9b5d30 commit df21c68

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

hooks/pre_commit/42-evr_extension_permissions.rb

+15-16
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,34 @@ def check_remote_evr_extension_permissions
22
# Managed databases will be handled automatically.
33
return if local_postgresql?
44
return unless katello_enabled?
5-
5+
66
config = load_db_config('foreman')
7-
7+
88
# If postgres is the owner of the DB, then the permissions will not matter.
99
return if config[:username] == 'postgres'
10-
10+
1111
evr_existence_command = pg_sql_statement("SELECT 1 FROM pg_extension WHERE extname = 'evr';")
1212
logger.debug "Checking if the evr extension exists via #{evr_existence_command}"
1313
evr_existence_output, = execute_command(evr_existence_command, false, true, pg_env(config))
14-
14+
1515
# If the evr extension does not exist, then we can skip this check.
1616
return if evr_existence_output&.strip != '1'
17-
18-
check_evr_owner_sql = "SELECT CASE" \
19-
" WHEN r.rolname = '#{config[:username]}' THEN 0" \
20-
" ELSE 1" \
21-
" END AS evr_owned_by_postgres" \
22-
" FROM pg_extension e" \
23-
" JOIN pg_roles r ON e.extowner = r.oid" \
24-
" WHERE e.extname = 'evr';"
25-
17+
18+
check_evr_owner_sql = "SELECT CASE " \
19+
"WHEN r.rolname = '#{config[:username]}' THEN 0 " \
20+
"ELSE 1 " \
21+
"END AS evr_owned_by_postgres " \
22+
"FROM pg_extension e " \
23+
"JOIN pg_roles r ON e.extowner = r.oid " \
24+
"WHERE e.extname = 'evr';"
25+
2626
command = pg_sql_statement(check_evr_owner_sql)
2727
logger.debug "Checking if the evr extension is owned by the postgres user via #{command}"
2828
output, = execute_command(command, false, true, pg_env(config))
29-
29+
3030
case output&.strip
3131
when '0'
32-
# The evr extension is owned by the foreman DB owner, so we can skip this check.
33-
return
32+
logger.debug('PostgreSQL EVR extension owned by Foreman DB owner')
3433
when '1'
3534
fail_and_exit("The evr extension is not owned by the foreman DB owner. Please run the following command to fix it: " \
3635
"UPDATE pg_extension SET extowner = (SELECT oid FROM pg_authid WHERE rolname='#{config[:username]}') WHERE extname='evr';")

0 commit comments

Comments
 (0)