Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploying multiple gpgkey in one repo #278

Merged
merged 3 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -706,6 +706,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