Skip to content

Commit 91651c5

Browse files
committed
Drop deployment ability of providers and RPM support
1 parent b9667a0 commit 91651c5

File tree

11 files changed

+44
-196
lines changed

11 files changed

+44
-196
lines changed

lib/puppet/provider/ca/katello_ssl_tool.rb

Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,19 @@
66
protected
77

88
def generate!
9-
if existing_pubkey
10-
FileUtils.mkdir_p(build_path)
11-
FileUtils.cp(existing_pubkey, build_path(File.basename(pubkey)))
12-
katello_ssl_tool('--gen-ca',
13-
'--dir', resource[:build_dir],
14-
'--ca-cert-dir', target_path('certs'),
15-
'--ca-cert', File.basename(pubkey),
16-
'--ca-cert-rpm', rpmfile_base_name,
17-
'--rpm-only')
18-
else
19-
katello_ssl_tool('--gen-ca',
20-
'--dir', resource[:build_dir],
21-
'-p', "file:#{resource[:password_file]}",
22-
'--force',
23-
'--ca-cert-dir', target_path('certs'),
24-
'--set-common-name', resource[:common_name],
25-
'--ca-cert', File.basename(pubkey),
26-
'--ca-key', File.basename(privkey),
27-
'--ca-cert-rpm', rpmfile_base_name,
28-
*common_args)
9+
katello_ssl_tool(
10+
'--gen-ca',
11+
'--dir', resource[:build_dir],
12+
'--password', "file:#{resource[:password_file]}",
13+
'--force',
14+
'--ca-cert-dir', resource[:build_dir],
15+
'--set-common-name', resource[:common_name],
16+
'--ca-cert', File.basename(pubkey),
17+
'--ca-key', File.basename(privkey),
18+
'--no-rpm',
19+
*common_args
20+
)
2921

30-
end
3122
super
3223
end
33-
34-
def existing_pubkey
35-
if resource[:ca]
36-
ca_details[:pubkey]
37-
elsif resource[:custom_pubkey]
38-
resource[:custom_pubkey]
39-
end
40-
end
41-
42-
def deploy!
43-
if File.exist?(rpmfile)
44-
# the rpm is available locally on the file system
45-
rpm('-Uvh', '--force', rpmfile)
46-
else
47-
# we search the rpm in yum repo
48-
yum("install", "-y", rpmfile_base_name)
49-
end
50-
end
51-
52-
def files_to_deploy
53-
[pubkey]
54-
end
55-
56-
def self.privkey(name)
57-
build_path("#{name}.key")
58-
end
59-
6024
end

lib/puppet/provider/cert/katello_ssl_tool.rb

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,15 @@ def generate!
1010
'--server-cert', File.basename(pubkey),
1111
'--server-cert-req', File.basename(req_file),
1212
'--server-key', File.basename(privkey),
13-
'--server-rpm', rpmfile_base_name ]
13+
'--no-rpm' ]
1414

15-
if resource[:custom_pubkey]
16-
FileUtils.mkdir_p(build_path)
17-
FileUtils.cp(resource[:custom_pubkey], build_path(File.basename(pubkey)))
18-
FileUtils.cp(resource[:custom_privkey], build_path(File.basename(privkey)))
19-
if resource[:custom_req]
20-
FileUtils.cp(resource[:custom_req], build_path(File.basename(req_file)))
21-
else
22-
File.open(build_path(File.basename(req_file)), 'w') { |f| f.write('') }
23-
end
24-
args << '--rpm-only'
25-
else
26-
resource[:common_name] ||= resource[:hostname]
27-
args.concat(['-p', "file:#{resource[:password_file]}",
28-
'--set-hostname', resource[:hostname],
29-
'--set-common-name', resource[:common_name],
30-
'--ca-cert', ca_details[:pubkey],
31-
'--ca-key', ca_details[:privkey]])
32-
args.concat(common_args)
33-
end
15+
resource[:common_name] ||= resource[:hostname]
16+
args.concat(['--password', "file:#{resource[:password_file]}",
17+
'--set-hostname', resource[:hostname],
18+
'--set-common-name', resource[:common_name],
19+
'--ca-cert', ca_details[:pubkey],
20+
'--ca-key', ca_details[:privkey]])
21+
args.concat(common_args)
3422

3523
if resource[:cname]
3624
if resource[:cname].is_a?(String)
@@ -47,10 +35,6 @@ def generate!
4735
protected
4836

4937
def req_file
50-
"#{self.pubkey}.req"
51-
end
52-
53-
def build_path(file_name = '')
54-
self.class.build_path(File.join(resource[:hostname], file_name))
38+
"#{pubkey}.req"
5539
end
5640
end

lib/puppet/provider/katello_ssl_tool.rb

Lines changed: 22 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,24 @@ class Cert < Puppet::Provider
55

66
initvars
77

8-
commands :rpm => 'rpm'
9-
commands :yum => 'yum'
108
commands :katello_ssl_tool_command => 'katello-ssl-tool'
119

1210
def exists?
13-
! generate? && ! deploy?
11+
!generate?
1412
end
1513

1614
def create
1715
generate! if generate?
18-
deploy! if deploy?
1916
end
2017

2118
def destroy
22-
files_to_deploy.each do |file|
23-
FileUtils.rm_f(file)
24-
end
25-
26-
output = execute([:rpm, '-q', rpmfile_base_name], failonfail: false)
27-
if output.exitstatus == 0
28-
rpm('-e', rpmfile_base_name)
29-
end
30-
end
31-
32-
def self.details(cert_name)
33-
details = { :pubkey => pubkey(cert_name),
34-
:privkey => privkey(cert_name) }
35-
36-
return details
3719
end
3820

39-
def self.pubkey(name)
40-
target_path("certs/#{name}.crt")
41-
end
42-
43-
def self.privkey(name)
44-
target_path("private/#{name}.key")
21+
def details(cert_name)
22+
return {
23+
:pubkey => pubkey(cert_name),
24+
:privkey => privkey(cert_name)
25+
}
4526
end
4627

4728
protected
@@ -59,49 +40,12 @@ def generate!
5940
def generate?
6041
return false unless resource[:generate]
6142
return true if resource[:regenerate]
62-
return true if File.exist?(update_file)
63-
return files_to_generate.any? { |file| ! File.exist?(file) }
43+
return true if File.exists?(update_file)
44+
return true unless (File.exist?(pubkey) && File.exist?(privkey))
6445
end
6546

66-
def files_to_generate
67-
[rpmfile]
68-
end
69-
70-
def deploy?
71-
return false unless resource[:deploy]
72-
return true if resource[:regenerate]
73-
return true if files_to_deploy.any? { |file| ! File.exist?(file) }
74-
return true if needs_deploy?
75-
end
76-
77-
def files_to_deploy
78-
[pubkey, privkey]
79-
end
80-
81-
def deploy!
82-
if File.exist?(rpmfile)
83-
if(system("rpm -q #{rpmfile_base_name} &>/dev/null"))
84-
rpm('-e', rpmfile_base_name)
85-
end
86-
rpm('-Uvh', '--force', rpmfile)
87-
else
88-
# we search the rpm in yum repo
89-
yum("install", "-y", rpmfile_base_name)
90-
end
91-
end
92-
93-
def needs_deploy?
94-
if File.exist?(rpmfile)
95-
# the installed version doesn't match the rpmfile
96-
!system("rpm --verify -p #{rpmfile} &>/dev/null")
97-
else
98-
`yum check-update #{rpmfile_base_name} &>/dev/null`
99-
$?.exitstatus == 100
100-
end
101-
end
102-
103-
def version_from_name(rpmname)
104-
rpmname.scan(/\d+/).map(&:to_i)
47+
def update_file
48+
build_path("#{resource[:name]}.update")
10549
end
10650

10751
def common_args
@@ -114,56 +58,29 @@ def common_args
11458
'--cert-expiration', resource[:expiration]]
11559
end
11660

117-
def rpmfile
118-
path = self.build_path("#{rpmfile_base_name}")
119-
path = path + "-[0-9].*" + "noarch.rpm"
120-
121-
rpmfile = Dir[path].max_by do |file|
122-
version_from_name(file)
123-
end
124-
125-
rpmfile ||= self.build_path("#{rpmfile_base_name}.noarch.rpm")
126-
return rpmfile
127-
end
128-
129-
# file that indicates that a new version of the rpm should be updated
130-
def update_file
131-
self.build_path("#{rpmfile_base_name}.update")
132-
end
133-
134-
def rpmfile_base_name
135-
resource[:name]
136-
end
137-
138-
def pubkey
139-
self.class.pubkey(resource[:name])
140-
end
141-
142-
def privkey
143-
self.class.privkey(resource[:name])
61+
def pubkey(cert_name = resource[:name])
62+
build_path("#{cert_name}.crt")
14463
end
14564

146-
def target_path(file_name = '')
147-
self.class.target_path(file_name)
148-
end
149-
150-
def self.target_path(file_name = '')
151-
File.join("/etc/pki/katello-certs-tools", file_name)
65+
def privkey(key_name = resource[:name])
66+
build_path("#{key_name}.key")
15267
end
15368

15469
def build_path(file_name = '')
155-
self.class.build_path(file_name)
156-
end
70+
path = resource[:build_dir]
71+
72+
if resource.to_hash.key?(:hostname)
73+
path = "#{path}/#{resource[:hostname]}"
74+
end
15775

158-
def self.build_path(file_name = '')
159-
File.join("/root/ssl-build", file_name)
76+
File.join(path, file_name)
16077
end
16178

16279
def ca_details
16380
return @ca_details if defined? @ca_details
16481
if ca_resource = resource.catalog.resource(@resource[:ca].to_s)
16582
name = ca_resource.to_hash[:name]
166-
@ca_details = Puppet::Provider::KatelloSslTool::Cert.details(name)
83+
@ca_details = details(name)
16784
else
16885
raise 'Wanted to generate cert without ca specified'
16986
end
@@ -221,7 +138,7 @@ def cert_details
221138
return @cert_details if defined? @cert_details
222139
if cert_resource = resource.catalog.resource(@resource[:key_pair].to_s)
223140
name = cert_resource.to_hash[:name]
224-
@cert_details = Puppet::Provider::KatelloSslTool::Cert.details(name)
141+
@cert_details = details(name)
225142
else
226143
raise 'Cert or Ca was not specified'
227144
end

lib/puppet_x/certs/common.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ module Common
1010

1111
newparam(:name, :namevar => true)
1212

13-
newparam(:custom_pubkey)
14-
15-
newparam(:custom_privkey)
16-
17-
newparam(:custom_req)
18-
1913
newparam(:common_name)
2014

2115
newparam(:cname)
@@ -38,8 +32,6 @@ module Common
3832

3933
newparam(:regenerate)
4034

41-
newparam(:deploy)
42-
4335
newparam(:password_file)
4436

4537
newparam(:build_dir) do

manifests/apache.pp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@
102102
ca => $certs::default_ca,
103103
generate => $generate,
104104
regenerate => $regenerate,
105-
deploy => false,
106105
password_file => $ca_key_password_file,
107106
build_dir => $certs::ssl_build_dir,
108107
}

manifests/ca.pp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,9 @@
4545
org_unit => $org_unit,
4646
expiration => $ca_expiration,
4747
generate => $generate,
48-
deploy => false,
4948
password_file => $ca_key_password_file,
5049
build_dir => $certs::ssl_build_dir,
5150
}
52-
$default_ca = Ca[$default_ca_name]
5351

5452
if $certs::server_ca_cert {
5553
file { $server_ca_path:

manifests/candlepin.pp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
ca => $certs::default_ca,
4343
generate => $generate,
4444
regenerate => $regenerate,
45-
deploy => false,
4645
password_file => $ca_key_password_file,
4746
build_dir => $certs::ssl_build_dir,
4847
}
@@ -62,7 +61,6 @@
6261
ca => $certs::default_ca,
6362
generate => $generate,
6463
regenerate => $regenerate,
65-
deploy => false,
6664
password_file => $ca_key_password_file,
6765
build_dir => $certs::ssl_build_dir,
6866
}

manifests/foreman.pp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
ca => $certs::default_ca,
3737
generate => $generate,
3838
regenerate => $regenerate,
39-
deploy => false,
4039
password_file => $ca_key_password_file,
4140
build_dir => $certs::ssl_build_dir,
4241
}

manifests/foreman_proxy.pp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
ca => $certs::default_ca,
7272
generate => $generate,
7373
regenerate => $regenerate,
74-
deploy => false,
7574
password_file => $ca_key_password_file,
7675
build_dir => $certs::ssl_build_dir,
7776
}
@@ -93,7 +92,6 @@
9392
ca => $certs::default_ca,
9493
generate => $generate,
9594
regenerate => $regenerate,
96-
deploy => false,
9795
password_file => $ca_key_password_file,
9896
build_dir => $certs::ssl_build_dir,
9997
}

manifests/init.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,5 @@
123123
Class['certs::config'] ->
124124
Class['certs::ca']
125125

126-
$default_ca = $certs::ca::default_ca
126+
$default_ca = Ca[$default_ca_name]
127127
}

0 commit comments

Comments
 (0)