Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#13125) Apt keys should be case insensitive #34

Merged
merged 1 commit into from
Mar 15, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions manifests/key.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

include apt::params

$upkey = upcase($key)

if $key_content {
$method = "content"
} elsif $key_source {
Expand All @@ -20,7 +22,7 @@
# It is used as a unique identifier for this instance of apt::key. It gets
# hashed to ensure that the resource name doesn't end up being pages and
# pages (e.g. in the situation where key_content is specified).
$digest = sha1("${key}/${key_content}/${key_source}/${key_server}/")
$digest = sha1("${upkey}/${key_content}/${key_source}/${key_server}/")

# Allow multiple ensure => present for the same key to account for many
# apt::source resources that all reference the same key.
Expand All @@ -29,40 +31,40 @@

anchor { "apt::key/$title":; }

if defined(Exec["apt::key $key absent"]) {
fail ("Cannot ensure Apt::Key[$key] present; $key already ensured absent")
if defined(Exec["apt::key $upkey absent"]) {
fail ("Cannot ensure Apt::Key[$upkey] present; $upkey already ensured absent")
}

if !defined(Anchor["apt::key $key present"]) {
anchor { "apt::key $key present":; }
if !defined(Anchor["apt::key $upkey present"]) {
anchor { "apt::key $upkey present":; }
}

if !defined(Exec[$digest]) {
exec { $digest:
path => "/bin:/usr/bin",
unless => "/usr/bin/apt-key list | /bin/grep '${key}'",
before => Anchor["apt::key $key present"],
unless => "/usr/bin/apt-key list | /bin/grep '${upkey}'",
before => Anchor["apt::key $upkey present"],
command => $method ? {
"content" => "echo '${key_content}' | /usr/bin/apt-key add -",
"source" => "wget -q '${key_source}' -O- | apt-key add -",
"server" => "apt-key adv --keyserver '${key_server}' --recv-keys '${key}'",
"server" => "apt-key adv --keyserver '${key_server}' --recv-keys '${upkey}'",
};
}
}

Anchor["apt::key $key present"] -> Anchor["apt::key/$title"]
Anchor["apt::key $upkey present"] -> Anchor["apt::key/$title"]

}
absent: {

if defined(Anchor["apt::key $key present"]) {
fail ("Cannot ensure Apt::Key[$key] absent; $key already ensured present")
if defined(Anchor["apt::key $upkey present"]) {
fail ("Cannot ensure Apt::Key[$upkey] absent; $upkey already ensured present")
}

exec { "apt::key $key absent":
exec { "apt::key $upkey absent":
path => "/bin:/usr/bin",
onlyif => "apt-key list | grep '$key'",
command => "apt-key del '$key'",
onlyif => "apt-key list | grep '$upkey'",
command => "apt-key del '$upkey'",
user => "root",
group => "root",
}
Expand Down
4 changes: 3 additions & 1 deletion spec/defines/key_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
].each do |param_set|

let :param_hash do
default_params.merge(param_set)
param_hash = default_params.merge(param_set)
param_hash[:key].upcase! if param_hash[:key]
param_hash
end

let :params do
Expand Down