|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +case platform.family |
| 4 | +when 'redhat', 'fedora', 'suse' |
| 5 | + os_name_repo_file = { |
| 6 | + 'opensuse' => '/etc/zypp/repos.d/pgdg-sles-13.repo' |
| 7 | + } |
| 8 | + os_name_repo_file.default = '/etc/yum.repos.d/pgdg13.repo' |
| 9 | + |
| 10 | + os_name_repo_url = { |
| 11 | + 'amazon' => 'https://download.postgresql.org/pub/repos/yum/13/redhat/rhel-7-$basearch', |
| 12 | + 'fedora' => 'https://download.postgresql.org/pub/repos/yum/13/fedora/fedora-$releasever-$basearch', |
| 13 | + 'opensuse' => 'https://download.postgresql.org/pub/repos/zypp/13/suse/sles-$releasever-$basearch' |
| 14 | + } |
| 15 | + os_name_repo_url.default = 'https://download.postgresql.org/pub/repos/yum/13/redhat/rhel-$releasever-$basearch' |
| 16 | + |
| 17 | + repo_url = os_name_repo_url[platform.name] |
| 18 | + repo_file = os_name_repo_file[platform.name] |
| 19 | + |
| 20 | +when 'debian' |
| 21 | + # Inspec does not provide a `codename` matcher, so we add ours |
| 22 | + finger_codename = { |
| 23 | + 'ubuntu-18.04' => 'bionic', |
| 24 | + 'ubuntu-20.04' => 'focal', |
| 25 | + 'debian-9' => 'stretch', |
| 26 | + 'debian-10' => 'buster', |
| 27 | + 'debian-11' => 'bullseye' |
| 28 | + } |
| 29 | + codename = finger_codename[system.platform[:finger]] |
| 30 | + |
| 31 | + repo_keyring = '/usr/share/postgresql-common/pgdg/apt.postgresql.org.gpg' |
| 32 | + repo_file = '/etc/apt/sources.list.d/pgdg.list' |
| 33 | + # rubocop:disable Metrics/LineLength |
| 34 | + repo_url = "deb [signed-by=#{repo_keyring}] http://apt.postgresql.org/pub/repos/apt #{codename}-pgdg main" |
| 35 | + # rubocop:enable Metrics/LineLength |
| 36 | +end |
| 37 | + |
| 38 | +control 'Postgresql repository keyring' do |
| 39 | + title 'should be installed' |
| 40 | + |
| 41 | + only_if('Requirement for Debian family') do |
| 42 | + os.debian? |
| 43 | + end |
| 44 | + |
| 45 | + describe package('pgdg-keyring') do |
| 46 | + it { should be_installed } |
| 47 | + end |
| 48 | + |
| 49 | + describe file(repo_keyring) do |
| 50 | + it { should exist } |
| 51 | + it { should be_owned_by 'root' } |
| 52 | + it { should be_grouped_into 'root' } |
| 53 | + its('mode') { should cmp '0644' } |
| 54 | + end |
| 55 | +end |
| 56 | + |
| 57 | +control 'Postgresql repository' do |
| 58 | + impact 1 |
| 59 | + title 'should be configured' |
| 60 | + describe file(repo_file) do |
| 61 | + its('content') { should include repo_url } |
| 62 | + end |
| 63 | +end |
0 commit comments