Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ekohl committed Jan 15, 2021
1 parent 2c838ac commit 88ea090
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
19 changes: 7 additions & 12 deletions lib/puppet_x/certs/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ module Common
end

autorequire(:ca) do
if @parameters.has_key?(:ca)
catalog.resource(@parameters[:ca].value.to_s).to_hash[:name]
end
[self[:ca].title]
end

autorequire(:file) do
Expand Down Expand Up @@ -102,19 +100,16 @@ module Common
end
end

define_method(:autorequire_cert) do |type|
if @parameters.has_key?(:key_pair)
key_pair = catalog.resource(@parameters[:key_pair].value.to_s)
key_pair.to_hash[:name] if key_pair && key_pair.type == type
end
end

autorequire(:cert) do
autorequire_cert('Cert')
req = []
req << self[:key_pair].title if self[:key_pair].type == 'Cert'
req
end

autorequire(:ca) do
autorequire_cert('Ca')
req = []
req << self[:key_pair].title if self[:key_pair].type == 'Ca'
req
end

# Autorequire the nearest ancestor directory found in the catalog.
Expand Down
12 changes: 5 additions & 7 deletions manifests/ca.pp
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,21 @@
}

if $deploy {
Ca[$default_ca_name] ~>
pubkey { $ca_cert:
key_pair => $default_ca,
} ~>
pubkey { $ca_cert_stripped:
strip => true,
key_pair => $default_ca,
} ~>
file { $ca_cert:
ensure => file,
owner => 'root',
group => $group,
mode => '0644',
}

Ca[$server_ca_name] ~>
pubkey { $ca_cert_stripped:
strip => true,
key_pair => $default_ca,
}

pubkey { $katello_server_ca_cert:
key_pair => $server_ca,
} ~>
Expand All @@ -98,7 +97,6 @@
}

if $generate {
Ca[$default_ca_name] ~>
privkey { $ca_key:
key_pair => $default_ca,
unprotect => true,
Expand Down
17 changes: 13 additions & 4 deletions spec/classes/certs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,27 @@
.that_requires('File[/etc/pki/katello/private/katello-default-ca.pwd]')
end

it { is_expected.to contain_privkey('/etc/pki/katello/private/katello-default-ca.key').that_requires('Ca[katello-default-ca]') }
it do
is_expected.to contain_privkey('/etc/pki/katello/private/katello-default-ca.key')
.that_requires(['Ca[katello-default-ca]', 'File[/etc/pki/katello/private/katello-default-ca.pwd]'])
end

it do
is_expected.to contain_file('/etc/pki/katello/private/katello-default-ca.key')
.that_subscribes_to(['Ca[katello-default-ca]', 'Privkey[/etc/pki/katello/private/katello-default-ca.key]'])
.that_requires('Ca[katello-default-ca]')
.that_subscribes_to('Privkey[/etc/pki/katello/private/katello-default-ca.key]')
end

it { is_expected.to contain_pubkey('/etc/pki/katello/certs/katello-default-ca-stripped.crt').that_subscribes_to('Ca[katello-default-ca]') }
it do
is_expected.to contain_pubkey('/etc/pki/katello/certs/katello-default-ca-stripped.crt')
.that_requires('Ca[katello-default-ca]')
end

it { is_expected.to contain_pubkey('/etc/pki/katello/certs/katello-default-ca.crt').that_subscribes_to('Ca[katello-default-ca]') }
it do
is_expected.to contain_file('/etc/pki/katello/certs/katello-default-ca.crt')
.that_subscribes_to(['Ca[katello-default-ca]', 'Pubkey[/etc/pki/katello/certs/katello-default-ca.crt]'])
.that_requires('Ca[katello-default-ca]')
.that_subscribes_to('Pubkey[/etc/pki/katello/certs/katello-default-ca.crt]')
end

it do
Expand Down

0 comments on commit 88ea090

Please sign in to comment.