Skip to content
This repository has been archived by the owner on Sep 25, 2019. It is now read-only.

Support 'Account-Email' header for multi-user #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
32 changes: 23 additions & 9 deletions libraries/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,56 @@
module Pingdom
class Client

def initialize(username, password, key)
def initialize(username, password, key, account_email)
require 'rest-client'
@key ||= key
@api ||= RestClient::Resource.new(
'https://api.pingdom.com/api/2.0',
'https://api.pingdom.com/api/2.1',
username,
password
)
@account_email = account_email
end

def get(uri, options = {})
options.merge!({ app_key: @key })
add_creds!(options)
@api[uri].get options
end

def put(uri, body, options = {})
options.merge!({ app_key: @key })
add_creds!(options)
@api[uri].put body, options
end

def post(uri, body, options = {})
options.merge!({ app_key: @key })
add_creds!(options)
@api[uri].post body, options
end

def delete(uri, options = {})
options.merge!({ app_key: @key })
add_creds!(options)
@api[uri].delete options
end

def checks(options = {})
require 'json'
response = get('/checks')
data = ::JSON.parse(response)
data['checks']
add_creds!(options)
response = get('/checks', options)
if response.code == 200
Chef::Log.info("got checks")
data = ::JSON.parse(response)
data['checks']
else
Chef::Log.fatal("failed to get checks, unexpected response from api: " + response.parsed_response.inspect)
raise unless new_resource.ignore_failure
end
end

private

def add_creds!(options)
options.merge!({ app_key: @key })
options.merge!({ account_email: @account_email }) if @account_email
end
end
end
3 changes: 2 additions & 1 deletion providers/check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ def pingdom_api
pingdom_api ||= Pingdom::Client.new(
new_resource.username,
new_resource.password,
new_resource.api_key
new_resource.api_key,
new_resource.account_email
)
end

Expand Down
1 change: 1 addition & 0 deletions resources/check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def initialize(*args)
attribute :api_key, :kind_of => String, :required => true
attribute :username, :kind_of => String, :required => true
attribute :password, :kind_of => String, :required => true
attribute :account_email, :kind_of => String, :required => false, :default => nil
attribute :ignore_failure, :kind_of => [TrueClass,FalseClass], :default => false
attribute :check_params, :kind_of => Hash, :default => {}
attribute :id, :kind_of => [NilClass,Fixnum], :default => nil