summaryrefslogtreecommitdiff
path: root/lib/oxidized/output/http.rb
diff options
context:
space:
mode:
authorytti <saku@ytti.fi>2018-06-22 19:25:10 +0300
committerGitHub <noreply@github.com>2018-06-22 19:25:10 +0300
commit428708ef376884c3dc35aee1951cb8e1c55fac9f (patch)
tree8e209bdceb34385373f11796178b8706ba7e55c9 /lib/oxidized/output/http.rb
parentf0947761b46e4ee6cdadd866b1cf3cf25bdfeedd (diff)
Refactor smells
* reduce no/resolve_repo smell * reduce input/ssh/connect smell * reduce source/http load smell * reduce node/worker smell * reduce source/csv smell * reduce output/http smell Get's code climate from B to A, so I'm sure it's super duper important.
Diffstat (limited to 'lib/oxidized/output/http.rb')
-rw-r--r--lib/oxidized/output/http.rb31
1 files changed, 19 insertions, 12 deletions
diff --git a/lib/oxidized/output/http.rb b/lib/oxidized/output/http.rb
index 0467261..756b9ad 100644
--- a/lib/oxidized/output/http.rb
+++ b/lib/oxidized/output/http.rb
@@ -14,28 +14,19 @@ module Oxidized
raise NoConfig, 'no output http config, edit ~/.config/oxidized/config'
end
end
+
require "net/http"
require "uri"
require "json"
+
def store node, outputs, opt = {}
@commitref = nil
- json = JSON.pretty_generate(
- {
- 'msg' => opt[:msg],
- 'user' => opt[:user],
- 'email' => opt[:email],
- 'group' => opt[:group],
- 'node' => node,
- 'config' => outputs.to_cfg,
- # actually we need to also iterate outputs, for other types like in gitlab. But most people don't use 'type' functionality.
- }
- )
uri = URI.parse @cfg.url
http = Net::HTTP.new uri.host, uri.port
# http.use_ssl = true if uri.scheme = 'https'
req = Net::HTTP::Post.new(uri.request_uri, initheader = { 'Content-Type' => 'application/json' })
req.basic_auth @cfg.user, @cfg.password
- req.body = json
+ req.body = generate_json(node, outputs, opt)
response = http.request req
case response.code.to_i
@@ -50,5 +41,21 @@ module Oxidized
Oxidized.logger.info "Configuration http backup for #{node} failed status: #{response.body}"
end
end
+
+ private
+
+ def generate_json node, outputs, opt
+ JSON.pretty_generate(
+ {
+ 'msg' => opt[:msg],
+ 'user' => opt[:user],
+ 'email' => opt[:email],
+ 'group' => opt[:group],
+ 'node' => node,
+ 'config' => outputs.to_cfg,
+ # actually we need to also iterate outputs, for other types like in gitlab. But most people don't use 'type' functionality.
+ }
+ )
+ end
end
end