Skip to content

Commit 509172d

Browse files
authored
Merge pull request #278 from teluq-pbrideau/fix/yum_gpg_key
Deploying multiple gpgkey in one repo
2 parents 52fcf65 + 6d0375d commit 509172d

File tree

2 files changed

+67
-12
lines changed

2 files changed

+67
-12
lines changed

manifests/init.pp

+15-12
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,21 @@
152152
}
153153
# Handle GPG Key
154154
if ('gpgkey' in $attributes) {
155-
$matches = $attributes['gpgkey'].match('^file://(.*)$')
156-
if $matches {
157-
$gpgkey = $matches[1]
158-
if $gpgkey =~ Stdlib::AbsolutePath and $gpgkey in $gpgkeys {
159-
if !defined(Yum::Gpgkey[$gpgkey]) {
160-
yum::gpgkey { $gpgkey:
161-
* => $gpgkeys[$gpgkey],
162-
before => Package[$utils_package_name], # GPG Keys for any managed repository need to be installed before we attempt to install any packages.
163-
}
164-
} # end if Yum::Gpgkey[$gpgkey] is not defined
165-
} # end if $gpgkey exists in gpgkeys
166-
} # end if gpgkey is a file:// resource
155+
$matches = $attributes['gpgkey'].split(/\s/).match('^file://(.*)$')
156+
$matches.each |$match| {
157+
if $match {
158+
$gpgkey = $match[1]
159+
if $gpgkey =~ Stdlib::AbsolutePath and $gpgkey in $gpgkeys {
160+
if !defined(Yum::Gpgkey[$gpgkey]) {
161+
yum::gpgkey { $gpgkey:
162+
* => $gpgkeys[$gpgkey],
163+
before => Package[$utils_package_name],
164+
# GPG Keys for any managed repository need to be installed before we attempt to install any packages.
165+
}
166+
} # end if Yum::Gpgkey[$gpgkey] is not defined
167+
} # end if $gpgkey exists in gpgkeys
168+
} # end if gpgkey is a file:// resource
169+
} # end each matches
167170
} # end if $attributes has a gpgkey
168171
}
169172
}

spec/classes/init_spec.rb

+52
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,58 @@
744744
it { is_expected.not_to contain_package('yum-utils') }
745745
it { is_expected.to contain_package('dnf-utils') }
746746
end
747+
748+
context 'when custom repos is set' do
749+
let(:params) do
750+
{
751+
managed_repos: ['example'],
752+
repos: {
753+
example: {
754+
baseurl: 'https://example.com',
755+
gpgkey: 'file:///etc/pki/rpm-gpg/RPM-GPG-KEY-example'
756+
}
757+
},
758+
gpgkeys: {
759+
'/etc/pki/rpm-gpg/RPM-GPG-KEY-example' => {
760+
'source' => 'http://example.com/gpg'
761+
}
762+
}
763+
}
764+
end
765+
766+
it { is_expected.to compile.with_all_deps }
767+
it { is_expected.to have_yumrepo_resource_count(1) }
768+
it { is_expected.to contain_yumrepo('example') }
769+
it { is_expected.to contain_yum__gpgkey('/etc/pki/rpm-gpg/RPM-GPG-KEY-example') }
770+
end
771+
772+
context 'when custom repos with multiple gpgkeys is set' do
773+
let(:params) do
774+
{
775+
managed_repos: ['example'],
776+
repos: {
777+
example: {
778+
baseurl: 'https://example.com',
779+
gpgkey: 'file:///etc/pki/rpm-gpg/RPM-GPG-KEY-example file:///etc/pki/rpm-gpg/RPM-GPG-KEY-example2',
780+
}
781+
},
782+
gpgkeys: {
783+
'/etc/pki/rpm-gpg/RPM-GPG-KEY-example' => {
784+
'source' => 'http://example.com/gpg'
785+
},
786+
'/etc/pki/rpm-gpg/RPM-GPG-KEY-example2' => {
787+
'source' => 'http://example.com/gpg2'
788+
}
789+
}
790+
}
791+
end
792+
793+
it { is_expected.to compile.with_all_deps }
794+
it { is_expected.to have_yumrepo_resource_count(1) }
795+
it { is_expected.to contain_yumrepo('example') }
796+
it { is_expected.to contain_yum__gpgkey('/etc/pki/rpm-gpg/RPM-GPG-KEY-example') }
797+
it { is_expected.to contain_yum__gpgkey('/etc/pki/rpm-gpg/RPM-GPG-KEY-example2') }
798+
end
747799
end
748800
end
749801

0 commit comments

Comments
 (0)