Project

General

Profile

« Previous | Next » 

Revision 6c125adc

Added by Lukas Zapletal about 10 years ago

fixes #5395 - smart proxy provider V2 API w/ timeout

View differences:

lib/puppet/feature/apipie_bindings.rb
require 'puppet/util/feature'
Puppet.features.add(:apipie_bindings, :libs => %{apipie_bindings})
lib/puppet/provider/foreman_smartproxy/rest_v2.rb
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
lib/puppet/type/foreman_smartproxy.rb
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

Also available in: Unified diff