Skip to content

Commit

Permalink
fix style
Browse files Browse the repository at this point in the history
* Prefer single-quoted strings
  • Loading branch information
HatsuneMiku3939 committed Dec 21, 2018
1 parent eff7ac2 commit 0c03bf1
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 118 deletions.
30 changes: 15 additions & 15 deletions fluent-plugin-http-pull.gemspec
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
lib = File.expand_path("../lib", __FILE__)
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Gem::Specification.new do |spec|
spec.name = "fluent-plugin-http-pull"
spec.version = "0.8.3"
spec.authors = ["filepang"]
spec.email = ["filepang@gmail.com"]
spec.name = 'fluent-plugin-http-pull'
spec.version = '0.8.3'
spec.authors = ['filepang']
spec.email = ['filepang@gmail.com']

spec.summary = %q{fluent-plugin-http-pull}
spec.description = %q{The input plugin of fluentd to pull log from rest api}
spec.homepage = "https://github.com/HatsuneMiku3939/fluent-plugin-http-pull"
spec.license = "Apache-2.0"
spec.homepage = 'https://github.com/HatsuneMiku3939/fluent-plugin-http-pull'
spec.license = 'Apache-2.0'

test_files, files = `git ls-files -z`.split("\x0").partition do |f|
f.match(%r{^(test|spec|features)/})
end
spec.files = files
spec.executables = files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = test_files
spec.require_paths = ["lib"]
spec.require_paths = ['lib']

spec.required_ruby_version = '>= 2.1'

spec.add_development_dependency "rake", "~> 12.0"
spec.add_development_dependency "simplecov", "~> 0.7"
spec.add_development_dependency "test-unit", "~> 3.0"
spec.add_development_dependency "test-unit-rr", "~> 1.0", "~> 1.0.2"
spec.add_development_dependency "coveralls", "~> 0.7"
spec.add_development_dependency 'rake', '~> 12.0'
spec.add_development_dependency 'simplecov', '~> 0.7'
spec.add_development_dependency 'test-unit', '~> 3.0'
spec.add_development_dependency 'test-unit-rr', '~> 1.0', '~> 1.0.2'
spec.add_development_dependency 'coveralls', '~> 0.7'

spec.add_runtime_dependency "fluentd", [">= 0.14.10", "< 2"]
spec.add_runtime_dependency "rest-client", [">= 2.0.0", "< 3"]
spec.add_runtime_dependency 'fluentd', ['>= 0.14.10', '< 2']
spec.add_runtime_dependency 'rest-client', ['>= 2.0.0', '< 3']
end
36 changes: 18 additions & 18 deletions lib/fluent/plugin/in_http_pull.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

require "fluent/plugin/input"
require "rest-client"
require 'fluent/plugin/input'
require 'rest-client'

module Fluent
module Plugin
class HttpPullInput < Fluent::Plugin::Input
Fluent::Plugin.register_input("http_pull", self)
Fluent::Plugin.register_input('http_pull', self)
helpers :timer, :parser, :compat_parameters

def initialize
Expand All @@ -37,7 +37,7 @@ def initialize
config_param :interval, :time

desc 'The user agent string of request'
config_param :agent, :string, default: "fluent-plugin-http-pull"
config_param :agent, :string, default: 'fluent-plugin-http-pull'

desc 'status_only'
config_param :status_only, :bool, default: false
Expand Down Expand Up @@ -77,10 +77,10 @@ def initialize
desc 'verify_ssl'
config_param :verify_ssl, :bool, default: true

desc "The absolute path of directory where ca_file stored"
desc 'The absolute path of directory where ca_file stored'
config_param :ca_path, :string, default: nil

desc "The absolute path of ca_file"
desc 'The absolute path of ca_file'
config_param :ca_file, :string, default: nil


Expand All @@ -90,11 +90,11 @@ def configure(conf)

@parser = parser_create unless @status_only
@_request_headers = {
"Content-Type" => "application/x-www-form-urlencoded",
"User-Agent" => @agent
'Content-Type' => 'application/x-www-form-urlencoded',
'User-Agent' => @agent
}.merge(@request_headers.map do |section|
header = section["header"]
value = section["value"]
header = section['header']
value = section['value']

[header.to_sym, value]
end.to_h)
Expand All @@ -117,11 +117,11 @@ def on_timer
record, body = get_record(res)

rescue StandardError => err
record = { "url" => @url, "error" => err.message }
record = { 'url' => @url, 'error' => err.message }
if err.respond_to? :http_code
record["status"] = err.http_code || 0
record['status'] = err.http_code || 0
else
record["status"] = 0
record['status'] = 0
end
end

Expand Down Expand Up @@ -153,13 +153,13 @@ def request_options

def get_record(response)
body = response.body
record = { "url" => @url, "status" => response.code }
record["header"] = {} unless @response_headers.empty?
record = { 'url' => @url, 'status' => response.code }
record['header'] = {} unless @response_headers.empty?
@response_headers.each do |section|
name = section["header"]
name = section['header']
symbolize_name = name.downcase.gsub(/-/, '_').to_sym

record["header"][name] = response.headers[symbolize_name]
record['header'][name] = response.headers[symbolize_name]
end

return record, body
Expand All @@ -168,7 +168,7 @@ def get_record(response)
def parse(record, body)
if !@status_only && body != nil
@parser.parse(body) do |time, message|
record["message"] = message
record['message'] = message
record_time = time
end
end
Expand Down
16 changes: 8 additions & 8 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
end

# load our target code
$LOAD_PATH.unshift(File.expand_path("../../", __FILE__))
require "test-unit"
require "fluent/test"
require "fluent/test/driver/input"
require "fluent/test/helpers"
$LOAD_PATH.unshift(File.expand_path('../../', __FILE__))
require 'test-unit'
require 'fluent/test'
require 'fluent/test/driver/input'
require 'fluent/test/helpers'

require "test/unit/rr"
require 'test/unit/rr'

# require stub_server
require "test/helper/stub_server"
require "test/helper/stub_proxy"
require 'test/helper/stub_server'
require 'test/helper/stub_proxy'

Test::Unit::TestCase.include(Fluent::Test::Helpers)
Test::Unit::TestCase.extend(Fluent::Test::Helpers)
2 changes: 1 addition & 1 deletion test/helper/stub_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def shutdown

private
def create_proxy
@log_file = File.open("stub_proxy.log", "a+")
@log_file = File.open('stub_proxy.log', 'a+')
@log = WEBrick::Log.new @log_file
@access_log = [
[@log_file, WEBrick::AccessLog::COMBINED_LOG_FORMAT],
Expand Down
18 changes: 9 additions & 9 deletions test/helper/stub_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class DeleteService < WEBrick::HTTPServlet::AbstractServlet
def service(req, res)
if req.request_method != "DELETE"
if req.request_method != 'DELETE'
res.status = 405
else
res.status = 200
Expand Down Expand Up @@ -55,21 +55,21 @@ def shutdown

private
def create_server
@log_file = File.open("stub_server.log", "a+")
@log_file = File.open('stub_server.log', 'a+')
@log = WEBrick::Log.new @log_file
@access_log = [
[@log_file, WEBrick::AccessLog::COMBINED_LOG_FORMAT],
]


if @ssl_enable
ssl_basepath = File.join(File.dirname(__FILE__), ".ssl")
ssl_basepath = File.join(File.dirname(__FILE__), '.ssl')
@server = WEBrick::HTTPServer.new :Port => @port,
:SSLEnable => true,
:Logger => @log, :AccessLog => @access_log,
:SSLPrivateKey => OpenSSL::PKey::RSA.new(File.open(File.join(ssl_basepath, "server.key")).read),
:SSLCertificate => OpenSSL::X509::Certificate.new(File.open(File.join(ssl_basepath, "server.crt")).read),
:SSLCertName => [["CN", "localhost"]]
:SSLPrivateKey => OpenSSL::PKey::RSA.new(File.open(File.join(ssl_basepath, 'server.key')).read),
:SSLCertificate => OpenSSL::X509::Certificate.new(File.open(File.join(ssl_basepath, 'server.crt')).read),
:SSLCertName => [['CN', 'localhost']]
else
@server = WEBrick::HTTPServer.new :Port => @port,
:Logger => @log, :AccessLog => @access_log
Expand Down Expand Up @@ -101,7 +101,7 @@ def internal_error(req, res)
end

def redirect(req, res)
res.set_redirect WEBrick::HTTPStatus::TemporaryRedirect, "http://127.0.0.1:3939/"
res.set_redirect WEBrick::HTTPStatus::TemporaryRedirect, 'http://127.0.0.1:3939/'
end

def protected(req, res)
Expand All @@ -115,15 +115,15 @@ def protected(req, res)
end

def custom_header(req, res)
res.header["HATSUNE-MIKU"] = req["HATSUNE-MIKU"] if req["HATSUNE-MIKU"]
res.header['HATSUNE-MIKU'] = req['HATSUNE-MIKU'] if req['HATSUNE-MIKU']

res.status = 200
res['Content-Type'] = 'application/json'
res.body = '{ "status": "OK" }'
end

def method_post(req, res)
if req.request_method != "POST"
if req.request_method != 'POST'
res.status = 405
else
res.status = 200
Expand Down
28 changes: 14 additions & 14 deletions test/plugin/test_in_http_pull.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require "helper"
require "fluent/plugin/in_http_pull.rb"
require 'helper'
require 'fluent/plugin/in_http_pull.rb'

require 'ostruct'

class HttpPullInputTestDefaultOptions < Test::Unit::TestCase
sub_test_case "default value of each options" do
sub_test_case 'default value of each options' do
TEST_DEFAULT_VALUE_CONFIG = %[
tag test
url http://localhost:3939
Expand All @@ -15,70 +15,70 @@ class HttpPullInputTestDefaultOptions < Test::Unit::TestCase

test 'status_only' do
d = create_driver TEST_DEFAULT_VALUE_CONFIG
assert_equal("test", d.instance.tag)
assert_equal('test', d.instance.tag)

assert_equal(false, d.instance.status_only)
end

test 'timeout' do
d = create_driver TEST_DEFAULT_VALUE_CONFIG
assert_equal("test", d.instance.tag)
assert_equal('test', d.instance.tag)

assert_equal(10, d.instance.timeout)
end

test 'user' do
d = create_driver TEST_DEFAULT_VALUE_CONFIG
assert_equal("test", d.instance.tag)
assert_equal('test', d.instance.tag)

assert_equal(nil, d.instance.user)
end

test 'password' do
d = create_driver TEST_DEFAULT_VALUE_CONFIG
assert_equal("test", d.instance.tag)
assert_equal('test', d.instance.tag)

assert_equal(nil, d.instance.password)
end

test 'proxy' do
d = create_driver TEST_DEFAULT_VALUE_CONFIG
assert_equal("test", d.instance.tag)
assert_equal('test', d.instance.tag)

assert_equal(nil, d.instance.proxy)
end

test 'http_method' do
d = create_driver TEST_DEFAULT_VALUE_CONFIG
assert_equal("test", d.instance.tag)
assert_equal('test', d.instance.tag)

assert_equal(:get, d.instance.http_method)
end

test 'agent' do
d = create_driver TEST_DEFAULT_VALUE_CONFIG
assert_equal("test", d.instance.tag)
assert_equal('test', d.instance.tag)

assert_equal("fluent-plugin-http-pull", d.instance.agent)
assert_equal('fluent-plugin-http-pull', d.instance.agent)
end

test 'verify_ssl' do
d = create_driver TEST_DEFAULT_VALUE_CONFIG
assert_equal("test", d.instance.tag)
assert_equal('test', d.instance.tag)

assert_equal(true, d.instance.verify_ssl)
end

test 'ca_path' do
d = create_driver TEST_DEFAULT_VALUE_CONFIG
assert_equal("test", d.instance.tag)
assert_equal('test', d.instance.tag)

assert_equal(nil, d.instance.ca_path)
end

test 'ca_file' do
d = create_driver TEST_DEFAULT_VALUE_CONFIG
assert_equal("test", d.instance.tag)
assert_equal('test', d.instance.tag)

assert_equal(nil, d.instance.ca_file)
end
Expand Down
Loading

0 comments on commit 0c03bf1

Please sign in to comment.