Skip to content

Commit

Permalink
Merge pull request dgolja#17 from ajmaidak/proxy
Browse files Browse the repository at this point in the history
Proxy
  • Loading branch information
dgolja authored Dec 8, 2016
2 parents 67da08a + 65c3af3 commit 74bc23a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ log/*
Gemfile.lock
junit/*
.vagrant/
.bundle
vendor
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ before the gnupg_key resource executes.

**OPTIONAL** - key type. Valid values (public|private|both). Default: public

PGP key server from where to retrieve the public key. Valid URI schemes are
*http*, *https*, *ldap* and *hkp*.
#####`proxy`

**OPTIONAL** - use a http proxy url to access the keyserver, for example: http://proxy.corp.domain:80. Default: undef

### Tests

Expand Down
6 changes: 5 additions & 1 deletion lib/puppet/provider/gnupg_key/gnupg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ def add_key
end

def add_key_from_key_server
command = "gpg --keyserver #{resource[:key_server]} --recv-keys #{resource[:key_id]}"
if resource[:proxy].empty?
command = "gpg --keyserver #{resource[:key_server]} --recv-keys #{resource[:key_id]}"
else
command = "gpg --keyserver #{resource[:key_server]} --keyserver-options http-proxy=#{resource[:proxy]} --recv-keys #{resource[:key_id]}"
end
begin
output = Puppet::Util::Execution.execute(command, :uid => user_id, :failonfail => true)
rescue Puppet::ExecutionFailure => e
Expand Down
14 changes: 14 additions & 0 deletions lib/puppet/type/gnupg_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,18 @@

defaultto :public
end

newparam(:proxy) do
desc "Set the proxy to use for HTTP and HKP keyservers."

validate do |value|
if value
uri = URI.parse(URI.escape(value))
unless uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS)
raise ArgumentError, "Invalid proxy value #{value}"
end
end
end
end

end
6 changes: 6 additions & 0 deletions spec/unit/puppet/type/gnupg_key_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
}.to raise_error(Puppet::Error)
end

it "should not accept invalid formated proxy URL" do
expect {
@gnupg_key[:proxy] = 'httk://foo.bar/'
}.to raise_error(Puppet::Error)
end

['20BC0A86', 'D50582e6', '20BC0a86', '9B7D32F2D50582E6', '3CCe8BC520bc0A86'].each do |val|
it "should allow key_id with #{val}" do
@gnupg_key[:key_id] = val
Expand Down

0 comments on commit 74bc23a

Please sign in to comment.