Skip to content

Commit

Permalink
Merge pull request express42#80 from bbaugher/master
Browse files Browse the repository at this point in the history
Hide password when raising error
  • Loading branch information
aladmit authored Aug 29, 2017
2 parents d5be3da + 3ba0acf commit 4f6c9f9
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/zabbixapi/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,19 @@ def http_request(body)
def _request(body)
puts "[DEBUG] Send request: #{body}" if @options[:debug]
result = JSON.parse(http_request(body))
raise ApiError.new("Server answer API error\n #{JSON.pretty_unparse(result['error'])}\n on request:\n #{JSON.pretty_unparse(JSON.parse(body))}", result) if result['error']
raise ApiError.new("Server answer API error\n #{JSON.pretty_unparse(result['error'])}\n on request:\n #{pretty_body(body)}", result) if result['error']
result['result']
end

def pretty_body(body)
parsed_body = JSON.parse(body)

# If password is in body hide it
parsed_body['params']['password'] = '***' if parsed_body['params'].is_a?(Hash) && parsed_body['params'].key?('password')

JSON.pretty_unparse(parsed_body)
end

# Execute Zabbix API requests and return response
#
# @param body [Hash]
Expand Down

0 comments on commit 4f6c9f9

Please sign in to comment.