logstash-output-qingstor 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/outputs/qingstor/uploader"
4
+ require "logstash/outputs/qingstor/temporary_file"
5
+ require "qingstor/sdk"
6
+ require "stud/temporary"
7
+
8
+ require_relative "../qs_access_helper"
9
+
10
+ describe LogStash::Outputs::Qingstor::Uploader do
11
+ let(:bucket) { qs_init_bucket }
12
+ let(:key) { "foobar" }
13
+ let(:tmp_file) { Stud::Temporary.file }
14
+ let(:tmp_path) { tmp_file.path }
15
+ let(:logger) { spy(:logger) }
16
+
17
+ let(:threadpool) do
18
+ Concurrent::ThreadPoolExecutor.new({
19
+ :min_threads => 1,
20
+ :max_threads => 4,
21
+ :max_queue => 1,
22
+ :fallback_policy => :caller_runs
23
+ })
24
+ end
25
+
26
+ let(:file) do
27
+ f = LogStash::Outputs::Qingstor::TemporaryFile.new(key, tmp_file, tmp_path)
28
+ f.write("May the code be with you!")
29
+ f.fsync
30
+ f
31
+ end
32
+
33
+ subject { described_class.new(bucket, logger, threadpool) }
34
+
35
+ after do
36
+ delete_remote_file key
37
+ end
38
+
39
+ it "upload file to the qingstor bucket" do
40
+ subject.upload(file)
41
+ expect(list_remote_file.size).to eq(3)
42
+ end
43
+
44
+ it "execute a callback when the upload is complete" do
45
+ callback = proc { |f| }
46
+ expect(callback).to receive(:call).with(file)
47
+ subject.upload(file, { :on_complete => callback })
48
+ end
49
+ end
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/outputs/qingstor"
4
+ require "logstash/event"
5
+ require "openssl"
6
+ require "fileutils"
7
+ require_relative "./qs_access_helper"
8
+ require_relative "./spec_helper"
9
+
10
+ describe LogStash::Outputs::Qingstor do
11
+ let(:prefix) { "ss/%{server}"}
12
+ let(:event) { LogStash::Event.new({ "server" => "overwatch" }) }
13
+ let(:event_encoded) { "May the code be with you!" }
14
+ let(:events_and_encoded) {{ event => event_encoded}}
15
+ let(:options) {{
16
+ "access_key_id" => ENV['access_key_id'],
17
+ "secret_access_key" => ENV['secret_access_key'],
18
+ "bucket" => ENV['bucket'],
19
+ "region" => ENV['region'],
20
+ "prefix" => prefix
21
+ }}
22
+ let(:tmpdir){File.join(Dir.tmpdir, "logstash_restore_dir")}
23
+
24
+ after do
25
+ clean_remote_files
26
+ end
27
+
28
+ it "done work with minimal options" do
29
+ fetch_event(options, events_and_encoded)
30
+ expect(list_remote_file.size).to eq(1)
31
+ end
32
+
33
+ it "use aes256 to encrpytion in the server side" do
34
+ cipher = OpenSSL::Cipher::AES256.new(:CBC)
35
+ cipher.encrypt
36
+ key = cipher.random_key
37
+ fetch_event(options.merge({"server_side_encryption_algorithm" => "AES256","customer_key" => key}), events_and_encoded)
38
+ expect(list_remote_file.size).to eq(1)
39
+ end
40
+
41
+ it "upload existing file if turn on restore function" do
42
+ FileUtils.mkdir_p(File.join(tmpdir, "uuid_dir")) unless File.exists?(File.join(tmpdir, "uuid_dir"))
43
+ f = File.open(File.join(tmpdir, "uuid_dir/temp"), 'w')
44
+ f.write(event_encoded * 10)
45
+ f.close
46
+ fetch_event(options.merge({"restore" => true, "tmpdir" => tmpdir}), events_and_encoded)
47
+ expect(list_remote_file.size).to eq(2)
48
+ end
49
+
50
+ end
@@ -0,0 +1,38 @@
1
+ def fetch_event(settings, events_and_encoded)
2
+ qs = LogStash::Outputs::Qingstor.new(settings)
3
+ qs.register
4
+ qs.multi_receive_encoded(events_and_encoded)
5
+ qs.close
6
+ end
7
+
8
+ def qs_init_config(access_key_id = ENV['access_key_id'],
9
+ secret_access_key = ENV['secret_access_key'])
10
+ QingStor::SDK::Config.init access_key_id, secret_access_key
11
+ end
12
+
13
+ def qs_init_bucket(bucket = ENV['bucket'], region = ENV['region'])
14
+ config = qs_init_config
15
+ properties = {'bucket-name' => bucket, 'zone' => region }
16
+ QingStor::SDK::Bucket.new(config, properties)
17
+ end
18
+
19
+ def delete_remote_file(key)
20
+ bucket = qs_init_bucket
21
+ bucket.delete_object key
22
+ end
23
+
24
+ def list_remote_file(bucket = ENV['bucket'], region = ENV['region'])
25
+ bucket = qs_init_bucket(bucket, region)
26
+ bucket.list_objects[:keys]
27
+ end
28
+
29
+ def delete_bucket(bucket)
30
+ bucket = qs_init_bucket(bucket)
31
+ bucket.delete
32
+ end
33
+
34
+ def clean_remote_files
35
+ list_remote_file.each do |record|
36
+ qs_init_bucket.delete_object record[:key]
37
+ end
38
+ end
@@ -0,0 +1,4 @@
1
+ require "logstash/devutils/rspec/spec_helper"
2
+ require "logstash/logging/logger"
3
+
4
+ LogStash::Logging::Logger::configure_logging("debug")
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-output-qingstor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Evan Zhao
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ name: logstash-core-plugin-api
20
+ prerelease: false
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ name: logstash-codec-plain
34
+ prerelease: false
35
+ type: :runtime
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - '='
45
+ - !ruby/object:Gem::Version
46
+ version: 1.9.2
47
+ name: qingstor-sdk
48
+ prerelease: false
49
+ type: :runtime
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.9.2
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ name: concurrent-ruby
62
+ prerelease: false
63
+ type: :runtime
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.0.22
75
+ name: stud
76
+ prerelease: false
77
+ type: :development
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.0.22
83
+ - !ruby/object:Gem::Dependency
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ name: logstash-devutils
90
+ prerelease: false
91
+ type: :development
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Put the outcomes of logstash into qingstor
98
+ email: tacingiht@gmail.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - CHANGELOG.md
104
+ - CODE_OF_CONDUCT.md
105
+ - CONTRIBUTING.md
106
+ - CONTRIBUTORS
107
+ - DEVELOPER.md
108
+ - Gemfile
109
+ - LICENSE
110
+ - README.md
111
+ - lib/logstash/outputs/qingstor.rb
112
+ - lib/logstash/outputs/qingstor/file_repository.rb
113
+ - lib/logstash/outputs/qingstor/qingstor_validator.rb
114
+ - lib/logstash/outputs/qingstor/size_and_time_rotation_policy.rb
115
+ - lib/logstash/outputs/qingstor/size_rotation_policy.rb
116
+ - lib/logstash/outputs/qingstor/temporary_file.rb
117
+ - lib/logstash/outputs/qingstor/temporary_file_factory.rb
118
+ - lib/logstash/outputs/qingstor/time_rotation_policy.rb
119
+ - lib/logstash/outputs/qingstor/uploader.rb
120
+ - logstash-output-qingstor.gemspec
121
+ - spec/outputs/qingstor/file_repository_spec.rb
122
+ - spec/outputs/qingstor/qingstor_validator_spec.rb
123
+ - spec/outputs/qingstor/size_and_time_rotation_policy_spec.rb
124
+ - spec/outputs/qingstor/size_rotation_policy_spec.rb
125
+ - spec/outputs/qingstor/temporary_file_factory_spec.rb
126
+ - spec/outputs/qingstor/temporary_file_spec.rb
127
+ - spec/outputs/qingstor/time_rotation_policy_spec.rb
128
+ - spec/outputs/qingstor/uploader_spec.rb
129
+ - spec/outputs/qingstor_spec.rb
130
+ - spec/outputs/qs_access_helper.rb
131
+ - spec/outputs/spec_helper.rb
132
+ homepage: https://github.com/tacinight/logstash-output-qingstor
133
+ licenses:
134
+ - Apache License (2.0)
135
+ metadata:
136
+ logstash_plugin: 'true'
137
+ logstash_group: output
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.4.8
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: logstash output plugin for qingstor
158
+ test_files:
159
+ - spec/outputs/qingstor/file_repository_spec.rb
160
+ - spec/outputs/qingstor/qingstor_validator_spec.rb
161
+ - spec/outputs/qingstor/size_and_time_rotation_policy_spec.rb
162
+ - spec/outputs/qingstor/size_rotation_policy_spec.rb
163
+ - spec/outputs/qingstor/temporary_file_factory_spec.rb
164
+ - spec/outputs/qingstor/temporary_file_spec.rb
165
+ - spec/outputs/qingstor/time_rotation_policy_spec.rb
166
+ - spec/outputs/qingstor/uploader_spec.rb
167
+ - spec/outputs/qingstor_spec.rb
168
+ - spec/outputs/qs_access_helper.rb
169
+ - spec/outputs/spec_helper.rb