Skip to content

Commit ebef1ef

Browse files
committed
(PUP-10589) Refactor private key creation
Refactor code into a private method.
1 parent bc29de8 commit ebef1ef

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

lib/puppet/application/ssl.rb

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,7 @@ def show(certname)
169169
def submit_request(ssl_context)
170170
key = @cert_provider.load_private_key(Puppet[:certname])
171171
unless key
172-
if Puppet[:key_type] == 'ec'
173-
Puppet.info _("Creating a new EC SSL key for %{name} using curve %{curve}") % { name: Puppet[:certname], curve: Puppet[:named_curve] }
174-
key = OpenSSL::PKey::EC.generate(Puppet[:named_curve])
175-
else
176-
Puppet.info _("Creating a new SSL key for %{name}") % { name: Puppet[:certname] }
177-
key = OpenSSL::PKey::RSA.new(Puppet[:keylength].to_i)
178-
end
172+
key = create_key(Puppet[:certname])
179173
@cert_provider.save_private_key(Puppet[:certname], key)
180174
end
181175

@@ -197,13 +191,7 @@ def submit_request(ssl_context)
197191
def generate_request(certname)
198192
key = @cert_provider.load_private_key(certname)
199193
unless key
200-
if Puppet[:key_type] == 'ec'
201-
Puppet.info _("Creating a new EC SSL key for %{name} using curve %{curve}") % { name: certname, curve: Puppet[:named_curve] }
202-
key = OpenSSL::PKey::EC.generate(Puppet[:named_curve])
203-
else
204-
Puppet.info _("Creating a new SSL key for %{name}") % { name: certname }
205-
key = OpenSSL::PKey::RSA.new(Puppet[:keylength].to_i)
206-
end
194+
key = create_key(certname)
207195
@cert_provider.save_private_key(certname, key)
208196
end
209197

@@ -312,4 +300,14 @@ def fingerprint(cert)
312300
def create_route(ssl_context)
313301
@session.route_to(:ca, ssl_context: ssl_context)
314302
end
303+
304+
def create_key(certname)
305+
if Puppet[:key_type] == 'ec'
306+
Puppet.info _("Creating a new EC SSL key for %{name} using curve %{curve}") % { name: certname, curve: Puppet[:named_curve] }
307+
OpenSSL::PKey::EC.generate(Puppet[:named_curve])
308+
else
309+
Puppet.info _("Creating a new SSL key for %{name}") % { name: certname }
310+
OpenSSL::PKey::RSA.new(Puppet[:keylength].to_i)
311+
end
312+
end
315313
end

0 commit comments

Comments
 (0)