Skip to content

Commit

Permalink
Update Fedora initdb commands
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Webb <dan.webb@damacus.io>
  • Loading branch information
damacus committed Nov 4, 2024
1 parent 259bc83 commit e664e36
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion documentation/postgresql_ident.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ postgresql_access 'local_foo_user' do
database 'all'
user 'foo'
address '127.0.0.1/32'
auth_method 'md5'
auth_method 'scram-sha-256'
end
```

Expand Down
6 changes: 5 additions & 1 deletion libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def default_yum_gpg_key_uri
if platform_family?('rhel') && node['platform_version'].to_i == 7
'https://download.postgresql.org/pub/repos/yum/keys/PGDG-RPM-GPG-KEY-RHEL7'
elsif platform_family?('fedora')
'https://download.postgresql.org/pub/repos/yum/keys/PGDG-KEY-fedora'
'https://download.postgresql.org/pub/repos/yum/keys/PGDG-RPM-GPG-KEY-Fedora'
else
'https://download.postgresql.org/pub/repos/yum/keys/PGDG-RPM-GPG-KEY-RHEL'
end
Expand All @@ -173,6 +173,10 @@ def rhel_init_db_command(new_resource)
cmd << " -D '#{data_dir}'"
end

def fedora_init_db_command
'usr/bin/postgresql-setup --initdb'
end

# Given the base URL build the complete URL string for a yum repo
def yum_repo_url(base_url)
"#{base_url}/#{new_resource.version}/#{yum_repo_platform_family_string}/#{yum_repo_platform_string}"
Expand Down
5 changes: 3 additions & 2 deletions resources/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ def install_method_repo?
def do_repository_action(repo_action)
case node['platform_family']
when 'rhel', 'fedora', 'amazon'
# Disable the PostgreSQL module if we're on RHEL 8 not on fedora
dnf_module 'postgresql' do
action :disable
end if dnf_module_platform?
end if dnf_module_platform? && !platform_family?('fedora')

remote_file '/etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY' do
source new_resource.yum_gpg_key_uri
Expand Down Expand Up @@ -272,7 +273,7 @@ def do_server_package_action(package_action)

converge_by('Init PostgreSQL') do
execute 'init_db' do
command rhel_init_db_command(new_resource)
command platform_family?('fedora') ? fedora_init_db_command : rhel_init_db_command(new_resource)
user new_resource.initdb_user
end
end
Expand Down
14 changes: 7 additions & 7 deletions test/cookbooks/test/recipes/access.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
database 'all'
user 'postgres'
address '127.0.0.1/32'
auth_method 'md5'
auth_method 'scram-sha-256'
end

postgresql_service 'postgresql' do
Expand Down Expand Up @@ -45,7 +45,7 @@
type 'host'
database 'all'
user 'sous_chef'
auth_method 'md5'
auth_method 'scram-sha-256'
address '127.0.0.1/32'
position 5

Expand Down Expand Up @@ -74,7 +74,7 @@
type 'host'
database 'all'
user 'hostname_user'
auth_method 'md5'
auth_method 'scram-sha-256'
address 'host.domain'

notifies :restart, 'postgresql_service[postgresql]', :delayed
Expand All @@ -84,7 +84,7 @@
type 'host'
database 'all'
user 'hostname.user'
auth_method 'md5'
auth_method 'scram-sha-256'
address 'host.domain'

notifies :restart, 'postgresql_service[postgresql]', :delayed
Expand All @@ -94,7 +94,7 @@
type 'host'
database 'my_database'
user 'hostname.user'
auth_method 'md5'
auth_method 'scram-sha-256'
address 'host.domain'

notifies :restart, 'postgresql_service[postgresql]', :delayed
Expand All @@ -104,7 +104,7 @@
type 'host'
database 'my_database'
user 'hostname.user'
auth_method 'md5'
auth_method 'scram-sha-256'
address 'a.very.long.host.domain.that.exceeds.the.max.of.24.characters'

notifies :restart, 'postgresql_service[postgresql]', :delayed
Expand Down Expand Up @@ -135,5 +135,5 @@
database 'foo,bar'
user 'john,doe'
address '127.0.0.1/32'
auth_method 'md5'
auth_method 'scram-sha-256'
end
2 changes: 1 addition & 1 deletion test/cookbooks/test/recipes/ident.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
database 'all'
user 'postgres'
address '127.0.0.1/32'
auth_method 'md5'
auth_method 'scram-sha-256'

notifies :reload, 'postgresql_service[postgresql]', :delayed
end
Expand Down
4 changes: 2 additions & 2 deletions test/cookbooks/test/recipes/server_install_os.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
database 'all'
user 'postgres'
address '127.0.0.1/32'
auth_method 'md5'
auth_method 'scram-sha-256'
end

postgresql_user 'postgres' do
Expand Down Expand Up @@ -77,7 +77,7 @@
type 'host'
database 'all'
user 'sous_chef'
auth_method 'md5'
auth_method 'scram-sha-256'
address '127.0.0.1/32'

notifies :restart, 'postgresql_service[postgresql]', :delayed
Expand Down
8 changes: 4 additions & 4 deletions test/integration/access/controls/base_access.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
describe postgres_hba_conf.where { type == 'host' && user == 'postgres' } do
its('database') { should cmp 'all' }
its('user') { should cmp 'postgres' }
its('auth_method') { should cmp 'md5' }
its('auth_method') { should cmp 'scram-sha-256' }
its('address') { should cmp '127.0.0.1/32' }
end

Expand All @@ -23,7 +23,7 @@
describe postgres_hba_conf.where { user == 'sous_chef' } do
its('database') { should cmp 'all' }
its('type') { should cmp 'host' }
its('auth_method') { should cmp 'md5' }
its('auth_method') { should cmp 'scram-sha-256' }
its('address') { should cmp '127.0.0.1/32' }
end

Expand All @@ -41,7 +41,7 @@
describe postgres_hba_conf.where { user == 'hostname_user' } do
its('database') { should cmp 'all' }
its('type') { should cmp 'host' }
its('auth_method') { should cmp 'md5' }
its('auth_method') { should cmp 'scram-sha-256' }
its('address') { should cmp 'host.domain' }
end
end
Expand All @@ -53,7 +53,7 @@
describe postgres_hba_conf.where { address == 'a.very.long.host.domain.that.exceeds.the.max.of.24.characters' } do
its('database') { should cmp 'my_database' }
its('type') { should cmp 'host' }
its('auth_method') { should cmp 'md5' }
its('auth_method') { should cmp 'scram-sha-256' }
its('address') { should cmp 'a.very.long.host.domain.that.exceeds.the.max.of.24.characters' }
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/integration/server_install_os/controls/access.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
describe postgres_hba_conf.where { type == 'host' && user == 'postgres' } do
its('database') { should cmp 'all' }
its('user') { should cmp 'postgres' }
its('auth_method') { should cmp 'md5' }
its('auth_method') { should cmp 'scram-sha-256' }
its('address') { should cmp '127.0.0.1/32' }
end

Expand All @@ -23,7 +23,7 @@
describe postgres_hba_conf.where { user == 'sous_chef' } do
its('database') { should cmp 'all' }
its('type') { should cmp 'host' }
its('auth_method') { should cmp 'md5' }
its('auth_method') { should cmp 'scram-sha-256' }
its('address') { should cmp '127.0.0.1/32' }
end

Expand Down

0 comments on commit e664e36

Please sign in to comment.