Skip to content

Commit

Permalink
fixes #5395 - smart proxy provider V2 API w/ timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
lzap authored and Dominic Cleal committed May 13, 2014
1 parent eb7410a commit 6c125ad
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/puppet/feature/apipie_bindings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'puppet/util/feature'

Puppet.features.add(:apipie_bindings, :libs => %{apipie_bindings})
61 changes: 61 additions & 0 deletions lib/puppet/provider/foreman_smartproxy/rest_v2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
Puppet::Type.type(:foreman_smartproxy).provide(:rest_v2) do

confine :feature => :apipie_bindings

# when both rest and rest_v2 providers are installed, use this one
def self.specificity
super + 1
end

def api
@api ||= ApipieBindings::API.new({
:uri => resource[:base_url],
:api_version => 2,
:oauth => {
:consumer_key => resource[:consumer_key],
:consumer_secret => resource[:consumer_secret]
},
:timeout => resource[:timeout],
:headers => {
:foreman_user => resource[:effective_user]
}}).resource(:smart_proxies)
end

# proxy hash or nil
def proxy
if @proxy
@proxy
else
@proxy = api.call(:index, :search => "name=#{resource[:name]}")['results'][0]
end
end

def id
proxy ? proxy['id'] : nil
end

def exists?
! id.nil?
end

def create
api.call(:create, {
'name' => resource[:name],
'url' => resource[:url]
})
end

def destroy
api.call(:destroy, :id => id)
@proxy = nil
end

def url
proxy ? proxy['url'] : nil
end

def url=(value)
api.call(:update, :id => id, :url => value)
end

end
16 changes: 16 additions & 0 deletions lib/puppet/type/foreman_smartproxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,20 @@
newvalues(URI.regexp)
end

newparam(:timeout) do
desc "Timeout for HTTP(s) requests"

munge do |value|
value = value.shift if value.is_a?(Array)
begin
value = Integer(value)
rescue ArgumentError
raise ArgumentError, "The timeout must be a number.", $!.backtrace
end
[value, 0].max
end

defaultto 500
end

end

0 comments on commit 6c125ad

Please sign in to comment.