Skip to content

Commit

Permalink
Merge pull request #278 from teluq-pbrideau/fix/yum_gpg_key
Browse files Browse the repository at this point in the history
Deploying multiple gpgkey in one repo
  • Loading branch information
jhoblitt authored Nov 9, 2022
2 parents 52fcf65 + 6d0375d commit 509172d
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 12 deletions.
27 changes: 15 additions & 12 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,21 @@
}
# Handle GPG Key
if ('gpgkey' in $attributes) {
$matches = $attributes['gpgkey'].match('^file://(.*)$')
if $matches {
$gpgkey = $matches[1]
if $gpgkey =~ Stdlib::AbsolutePath and $gpgkey in $gpgkeys {
if !defined(Yum::Gpgkey[$gpgkey]) {
yum::gpgkey { $gpgkey:
* => $gpgkeys[$gpgkey],
before => Package[$utils_package_name], # GPG Keys for any managed repository need to be installed before we attempt to install any packages.
}
} # end if Yum::Gpgkey[$gpgkey] is not defined
} # end if $gpgkey exists in gpgkeys
} # end if gpgkey is a file:// resource
$matches = $attributes['gpgkey'].split(/\s/).match('^file://(.*)$')
$matches.each |$match| {
if $match {
$gpgkey = $match[1]
if $gpgkey =~ Stdlib::AbsolutePath and $gpgkey in $gpgkeys {
if !defined(Yum::Gpgkey[$gpgkey]) {
yum::gpgkey { $gpgkey:
* => $gpgkeys[$gpgkey],
before => Package[$utils_package_name],
# GPG Keys for any managed repository need to be installed before we attempt to install any packages.
}
} # end if Yum::Gpgkey[$gpgkey] is not defined
} # end if $gpgkey exists in gpgkeys
} # end if gpgkey is a file:// resource
} # end each matches
} # end if $attributes has a gpgkey
}
}
Expand Down
52 changes: 52 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,58 @@
it { is_expected.not_to contain_package('yum-utils') }
it { is_expected.to contain_package('dnf-utils') }
end

context 'when custom repos is set' do
let(:params) do
{
managed_repos: ['example'],
repos: {
example: {
baseurl: 'https://example.com',
gpgkey: 'file:///etc/pki/rpm-gpg/RPM-GPG-KEY-example'
}
},
gpgkeys: {
'/etc/pki/rpm-gpg/RPM-GPG-KEY-example' => {
'source' => 'http://example.com/gpg'
}
}
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to have_yumrepo_resource_count(1) }
it { is_expected.to contain_yumrepo('example') }
it { is_expected.to contain_yum__gpgkey('/etc/pki/rpm-gpg/RPM-GPG-KEY-example') }
end

context 'when custom repos with multiple gpgkeys is set' do
let(:params) do
{
managed_repos: ['example'],
repos: {
example: {
baseurl: 'https://example.com',
gpgkey: 'file:///etc/pki/rpm-gpg/RPM-GPG-KEY-example file:///etc/pki/rpm-gpg/RPM-GPG-KEY-example2',
}
},
gpgkeys: {
'/etc/pki/rpm-gpg/RPM-GPG-KEY-example' => {
'source' => 'http://example.com/gpg'
},
'/etc/pki/rpm-gpg/RPM-GPG-KEY-example2' => {
'source' => 'http://example.com/gpg2'
}
}
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to have_yumrepo_resource_count(1) }
it { is_expected.to contain_yumrepo('example') }
it { is_expected.to contain_yum__gpgkey('/etc/pki/rpm-gpg/RPM-GPG-KEY-example') }
it { is_expected.to contain_yum__gpgkey('/etc/pki/rpm-gpg/RPM-GPG-KEY-example2') }
end
end
end

Expand Down

0 comments on commit 509172d

Please sign in to comment.