@@ -2,35 +2,34 @@ def check_remote_evr_extension_permissions
2
2
# Managed databases will be handled automatically.
3
3
return if local_postgresql?
4
4
return unless katello_enabled?
5
-
5
+
6
6
config = load_db_config ( 'foreman' )
7
-
7
+
8
8
# If postgres is the owner of the DB, then the permissions will not matter.
9
9
return if config [ :username ] == 'postgres'
10
-
10
+
11
11
evr_existence_command = pg_sql_statement ( "SELECT 1 FROM pg_extension WHERE extname = 'evr';" )
12
12
logger . debug "Checking if the evr extension exists via #{ evr_existence_command } "
13
13
evr_existence_output , = execute_command ( evr_existence_command , false , true , pg_env ( config ) )
14
-
14
+
15
15
# If the evr extension does not exist, then we can skip this check.
16
16
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
+
26
26
command = pg_sql_statement ( check_evr_owner_sql )
27
27
logger . debug "Checking if the evr extension is owned by the postgres user via #{ command } "
28
28
output , = execute_command ( command , false , true , pg_env ( config ) )
29
-
29
+
30
30
case output &.strip
31
31
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' )
34
33
when '1'
35
34
fail_and_exit ( "The evr extension is not owned by the foreman DB owner. Please run the following command to fix it: " \
36
35
"UPDATE pg_extension SET extowner = (SELECT oid FROM pg_authid WHERE rolname='#{ config [ :username ] } ') WHERE extname='evr';" )
0 commit comments