Skip to content
Snippets Groups Projects
Verified Commit 77d089d9 authored by Alexander Olofsson's avatar Alexander Olofsson
Browse files

Fix some rubocop issues

parent e8647ff3
Branches
Tags
No related merge requests found
Pipeline #3380 failed
...@@ -4,8 +4,8 @@ module Passwordstate ...@@ -4,8 +4,8 @@ module Passwordstate
class Client class Client
USER_AGENT = "RubyPasswordstate/#{Passwordstate::VERSION}".freeze USER_AGENT = "RubyPasswordstate/#{Passwordstate::VERSION}".freeze
DEFAULT_HEADERS = { DEFAULT_HEADERS = {
'accept' => 'application/json', 'accept' => 'application/json',
'user-agent' => USER_AGENT 'user-agent' => USER_AGENT
}.freeze }.freeze
attr_accessor :server_url, :auth_data, :headers, :validate_certificate attr_accessor :server_url, :auth_data, :headers, :validate_certificate
...@@ -103,11 +103,13 @@ module Passwordstate ...@@ -103,11 +103,13 @@ module Passwordstate
data = JSON.parse(res_obj.body) rescue nil data = JSON.parse(res_obj.body) rescue nil
if data if data
return data if res_obj.is_a? Net::HTTPSuccess return data if res_obj.is_a? Net::HTTPSuccess
data = data&.first data = data&.first
raise Passwordstate::HTTPError.new_by_code(res_obj.code, req_obj, res_obj, data&.fetch('errors', []) || []) raise Passwordstate::HTTPError.new_by_code(res_obj.code, req_obj, res_obj, data&.fetch('errors', []) || [])
else else
return res_obj.body if res_obj.is_a?(Net::HTTPSuccess) && options.fetch(:allow_html, true) return res_obj.body if res_obj.is_a?(Net::HTTPSuccess) && options.fetch(:allow_html, true)
raise Passwordstate::HTTPError.new_by_code(res_obj.code, req_obj, res_obj, [{ 'message' => res_obj.body }]) raise Passwordstate::HTTPError.new_by_code(res_obj.code, req_obj, res_obj, [{ 'message' => res_obj.body }])
end end
end end
...@@ -144,6 +146,7 @@ module Passwordstate ...@@ -144,6 +146,7 @@ module Passwordstate
logger.debug dir logger.debug dir
return if http.body.nil? return if http.body.nil?
clean_body = JSON.parse(http.body) rescue nil clean_body = JSON.parse(http.body) rescue nil
if clean_body if clean_body
clean_body = clean_body.each { |k, v| v.replace('[ REDACTED ]') if k.is_a?(String) && %w[password apikey].include?(k.downcase) }.to_json if http.body clean_body = clean_body.each { |k, v| v.replace('[ REDACTED ]') if k.is_a?(String) && %w[password apikey].include?(k.downcase) }.to_json if http.body
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment