Skip to content

Commit 2aee4df

Browse files
bastelfreakjst-cyr
authored andcommitted
Make keytool path configureable
Usecase: I need to manipulate the PE keystore. The provided `keytool` binary lives at /opt/puppetlabs/server/bin/keytool. This patch makes it configureable. The default is still the relative `keytool`, which will be used in $PATH. This makes it an enhancement, not a breaking change.
1 parent d2a0ea1 commit 2aee4df

4 files changed

Lines changed: 33 additions & 2 deletions

File tree

‎lib/puppet/provider/java_ks/keytool.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
desc 'Uses a combination of openssl and keytool to manage Java keystores'
99

1010
def command_keytool
11-
'keytool'
11+
@resource[:keytool]
1212
end
1313

1414
# Keytool can only import a keystore if the format is pkcs12. Generating and

‎lib/puppet/type/java_ks.rb‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ def value=(*values)
181181
defaultto 120
182182
end
183183

184+
newparam(:keytool) do
185+
desc 'Path to the keytool executable used by the provider.'
186+
187+
defaultto 'keytool'
188+
end
189+
184190
newparam(:source_password) do
185191
munge do |value|
186192
value = value.unwrap if value.respond_to?(:unwrap)

‎spec/unit/puppet/provider/java_ks/keytool_spec.rb‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,21 @@
5959
end
6060
end
6161

62+
describe '#command_keytool' do
63+
it 'uses the keytool parameter default' do
64+
allow(provider).to receive(:command_keytool).and_call_original
65+
66+
expect(provider.command_keytool).to eq('keytool')
67+
end
68+
69+
it 'uses a custom keytool parameter when provided' do
70+
allow(provider).to receive(:command_keytool).and_call_original
71+
resource[:keytool] = '/usr/lib/jvm/java-17-openjdk/bin/keytool'
72+
73+
expect(provider.command_keytool).to eq('/usr/lib/jvm/java-17-openjdk/bin/keytool')
74+
end
75+
end
76+
6277
describe 'when running keystore commands', if: !Puppet.features.microsoft_windows? do
6378
it 'calls the passed command' do
6479
cmd = '/bin/echo testing 1 2 3'

‎spec/unit/puppet/type/java_ks_spec.rb‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
end
3939

4040
describe 'when validating attributes' do
41-
[:name, :target, :private_key, :private_key_type, :certificate, :password_file, :trustcacerts, :destkeypass, :password_fail_reset, :source_password].each do |param|
41+
[:name, :target, :private_key, :private_key_type, :certificate, :password_file, :trustcacerts, :destkeypass, :password_fail_reset, :source_password, :keytool].each do |param|
4242
it "has a #{param} parameter" do
4343
expect(described_class.attrtype(param)).to eq(:param)
4444
end
@@ -214,6 +214,16 @@
214214
described_class.new(jks)
215215
}.to raise_error(Puppet::Error, %r{You must provide 'source_password' when using a 'pkcs12' storetype})
216216
end
217+
218+
it 'uses keytool as the default :keytool value' do
219+
expect(described_class.new(jks_resource)[:keytool]).to eq('keytool')
220+
end
221+
222+
it 'accepts a custom :keytool value' do
223+
jks = jks_resource.merge(keytool: '/usr/lib/jvm/java-17-openjdk/bin/keytool')
224+
225+
expect(described_class.new(jks)[:keytool]).to eq('/usr/lib/jvm/java-17-openjdk/bin/keytool')
226+
end
217227
end
218228

219229
describe 'when ensure is set to latest' do

0 commit comments

Comments
 (0)