Skip to content

Commit bb1d5fc

Browse files
committed
manage gpg key with apt::keyring
1 parent 9e973c6 commit bb1d5fc

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

REFERENCE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ The following parameters are available in the `elastic_stack::repo` class:
3434
* [`base_repo_url`](#-elastic_stack--repo--base_repo_url)
3535
* [`gpg_key_source`](#-elastic_stack--repo--gpg_key_source)
3636
* [`apt_keyring_name`](#-elastic_stack--repo--apt_keyring_name)
37+
* [`gpg_key_path`](#-elastic_stack--repo--gpg_key_path)
3738

3839
##### <a name="-elastic_stack--repo--oss"></a>`oss`
3940

@@ -101,3 +102,11 @@ Use `.asc` if the key is armored and `.gpg` if it's unarmored
101102

102103
Default value: `'elastic-keyring.asc'`
103104

105+
##### <a name="-elastic_stack--repo--gpg_key_path"></a>`gpg_key_path`
106+
107+
Data type: `Stdlib::Absolutepath`
108+
109+
The path where the GPG key should be stored (APT only)
110+
111+
Default value: `'/usr/share/keyrings'`
112+

manifests/repo.pp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@
1414
# @param gpg_key_source The gpg key for the repo
1515
# @param apt_keyring_name The keyring filename to create (APT only)
1616
# The filename extention is important here.
17-
# Use `.asc` if the key is armored and `.gpg` if it's unarmored
17+
# Use `.asc` if the key is armored and `.gpg` if it's unarmored
18+
# @param gpg_key_path The path where the GPG key should be stored (APT only)
1819
class elastic_stack::repo (
19-
Boolean $oss = false,
20-
Boolean $prerelease = false,
21-
Optional[Integer] $priority = undef,
22-
String $proxy = 'absent',
23-
Integer $version = 7,
24-
Stdlib::Filesource $gpg_key_source = 'https://artifacts.elastic.co/GPG-KEY-elasticsearch',
25-
String[1] $apt_keyring_name = 'elastic-keyring.asc',
26-
Optional[String] $base_repo_url = undef,
20+
Boolean $oss = false,
21+
Boolean $prerelease = false,
22+
Optional[Integer] $priority = undef,
23+
String $proxy = 'absent',
24+
Integer $version = 7,
25+
Stdlib::Filesource $gpg_key_source = 'https://artifacts.elastic.co/GPG-KEY-elasticsearch',
26+
String[1] $apt_keyring_name = 'elastic-keyring.asc',
27+
Stdlib::Absolutepath $gpg_key_path = '/usr/share/keyrings',
28+
Optional[String] $base_repo_url = undef,
2729
) {
2830
if $prerelease {
2931
$version_suffix = '.x-prerelease'
@@ -72,16 +74,20 @@
7274
'Debian': {
7375
include apt
7476

77+
apt::keyring { $apt_keyring_name:
78+
ensure => present,
79+
source => $gpg_key_source,
80+
dir => $gpg_key_path,
81+
}
82+
7583
apt::source { 'elastic':
7684
comment => $description,
7785
location => $base_url,
7886
release => 'stable',
7987
repos => 'main',
80-
key => {
81-
'name' => $apt_keyring_name,
82-
'source' => $gpg_key_source,
83-
},
8488
pin => $priority,
89+
keyring => "${gpg_key_path}/${apt_keyring_name}",
90+
require => Apt::Keyring[$apt_keyring_name],
8591
}
8692
}
8793
'RedHat', 'Linux': {

spec/classes/repo_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ def declare_zypper(version: '7.x', **params)
3838
case facts[:os]['family']
3939
when 'Debian'
4040
it { is_expected.to declare_apt }
41+
it { is_expected.to contain_apt__keyring('elastic-keyring.asc') }
4142
when 'RedHat'
4243
it { is_expected.to declare_yum }
44+
it { is_expected.to contain_exec('elastic_yumrepo_yum_clean') }
4345
when 'Suse'
4446
it { is_expected.to declare_zypper }
4547
it { is_expected.to contain_exec('elastic_suse_import_gpg').with(command: rpm_key_cmd) }

0 commit comments

Comments
 (0)