logstash-output-azure 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,65 @@
1
+ # Encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/outputs/blob/uploader"
4
+ require "logstash/outputs/blob/temporary_file"
5
+ require "azure"
6
+ require "stud/temporary"
7
+
8
+ describe LogStash::Outputs::LogstashAzureBlobOutput::Uploader do
9
+ let(:logger) { spy(:logger ) }
10
+ let(:max_upload_workers) { 1 }
11
+ let(:storage_account_name) { "test-cointainer" }
12
+ let(:temporary_directory) { Stud::Temporary.pathname }
13
+ let(:temporary_file) { Stud::Temporary.file }
14
+ let(:storage_access_key) { "foobar" }
15
+ let(:upload_options) { {} }
16
+ let(:threadpool) do
17
+ Concurrent::ThreadPoolExecutor.new({
18
+ :min_threads => 1,
19
+ :max_threads => 8,
20
+ :max_queue => 1,
21
+ :fallback_policy => :caller_runs
22
+ })
23
+ end
24
+
25
+ let(:file) do
26
+ f = LogStash::Outputs::LogstashAzureBlobOutput::TemporaryFile.new(storage_access_key, temporary_file, temporary_directory)
27
+ f.write("random content")
28
+ f.fsync
29
+ f
30
+ end
31
+
32
+ subject { described_class.new(storage_account_name, logger, threadpool) }
33
+
34
+ it "upload file to the blob" do
35
+ expect { subject.upload(file) }.not_to raise_error
36
+ end
37
+
38
+ it "execute a callback when the upload is complete" do
39
+ callback = proc { |f| }
40
+
41
+ expect(callback).to receive(:call).with(file)
42
+ subject.upload(file, { :on_complete => callback })
43
+ end
44
+
45
+ it 'the content in the blob and sent should be equal' do
46
+ blob = subject.upload(file)
47
+ md5 = Digest::MD5.base64digest(Object::File.open(file.path).read)
48
+ expect(blob.properties[:content_md5]).to eq(md5)
49
+ end
50
+
51
+ xit "retries errors indefinitively" do
52
+ blob = double("blob").as_null_object
53
+
54
+ expect(logger).to receive(:error).with(any_args).once
55
+
56
+ expect(storage_account_name).to receive(:object).with(file.key).and_return(blob).twice
57
+
58
+ expect(blob).to receive(:upload_file).with(any_args).and_raise(StandardError)
59
+
60
+ expect(blob).to receive(:upload_file).with(any_args).and_return(true)
61
+
62
+
63
+ subject.upload(file)
64
+ end
65
+ end
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/outputs/blob/writable_directory_validator"
4
+ require "stud/temporary"
5
+
6
+ describe LogStash::Outputs::LogstashAzureBlobOutput::WritableDirectoryValidator do
7
+ let(:temporary_directory) { File.join(Stud::Temporary.directory, Time.now.to_i.to_s) }
8
+
9
+ subject { described_class }
10
+
11
+ context "when the directory doesn't exists" do
12
+ it "creates the directory" do
13
+ expect(Dir.exist?(temporary_directory)).to be_falsey
14
+ expect(subject.valid?(temporary_directory)).to be_truthy
15
+ expect(Dir.exist?(temporary_directory)).to be_truthy
16
+ end
17
+ end
18
+
19
+ context "when the directory exist" do
20
+ before do
21
+ FileUtils.mkdir_p(temporary_directory)
22
+ end
23
+
24
+ it "doesn't change the directory" do
25
+ expect(Dir.exist?(temporary_directory)).to be_truthy
26
+ expect(subject.valid?(temporary_directory)).to be_truthy
27
+ expect(Dir.exist?(temporary_directory)).to be_truthy
28
+ end
29
+ end
30
+
31
+ it "return false if the directory is not writable" do
32
+ expect(::File).to receive(:writable?).with(temporary_directory).and_return(false)
33
+ expect(subject.valid?(temporary_directory)).to be_falsey
34
+ end
35
+
36
+ it "return true if the directory is writable" do
37
+ expect(::File).to receive(:writable?).with(temporary_directory).and_return(true)
38
+ expect(subject.valid?(temporary_directory)).to be_truthy
39
+ end
40
+ end
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require_relative "supports/helpers"
4
+ require "logstash/logging/logger"
5
+
6
+ LogStash::Logging::Logger::configure_logging("debug") if ENV["DEBUG"]
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+ shared_context "setup plugin" do
3
+ let(:temporary_directory) { Stud::Temporary.pathname }
4
+ let(:storage_account_name) { ENV["AWS_LOGSTASH_TEST_BUCKET"] }
5
+ let(:storage_access_key) { ENV["AWS_ACCESS_KEY_ID"] }
6
+ let(:size_file) { 100 }
7
+ let(:time_file) { 100 }
8
+ let(:tags) { [] }
9
+ let(:prefix) { "home" }
10
+
11
+ let(:main_options) do
12
+ {
13
+ "storage_account_name" => bucket,
14
+ "prefix" => prefix,
15
+ "temporary_directory" => temporary_directory,
16
+ "storage_access_key" => access_key_id,
17
+ "size_file" => size_file,
18
+ "time_file" => time_file,
19
+ "tags" => []
20
+ }
21
+ end
22
+
23
+ subject { LogStash::Outputs::LogstashAzureBlobOutput.new(options) }
24
+ end
25
+
26
+ def clean_remote_files(prefix = "")
27
+ bucket_resource.objects(:prefix => prefix).each do |object|
28
+ object.delete
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-output-azure
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tuffk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-14 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: '0.7'
47
+ name: azure
48
+ prerelease: false
49
+ type: :runtime
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.7'
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ name: logstash-devutils
62
+ prerelease: false
63
+ type: :development
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email: tuffkmulhall@gmail.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - CHANGELOG.md
76
+ - CONTRIBUTORS
77
+ - DEVELOPER.md
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - lib/logstash/outputs/Logstash_Azure_Blob_Output.rb
82
+ - lib/logstash/outputs/blob/file_repository.rb
83
+ - lib/logstash/outputs/blob/path_validator.rb
84
+ - lib/logstash/outputs/blob/size_and_time_rotation_policy.rb
85
+ - lib/logstash/outputs/blob/size_rotation_policy.rb
86
+ - lib/logstash/outputs/blob/temporary_file.rb
87
+ - lib/logstash/outputs/blob/temporary_file_factory.rb
88
+ - lib/logstash/outputs/blob/time_rotation_policy.rb
89
+ - lib/logstash/outputs/blob/uploader.rb
90
+ - lib/logstash/outputs/blob/writable_directory_validator.rb
91
+ - logstash-output-Logstash_Azure_Blob_Output.gemspec
92
+ - spec/outputs/Logstash_Azure_Blob_Output_spec.rb
93
+ - spec/outputs/blob/file_repository_spec.rb
94
+ - spec/outputs/blob/size_and_time_rotation_policy_spec.rb
95
+ - spec/outputs/blob/size_rotation_policy_spec.rb
96
+ - spec/outputs/blob/temporary_file_factory_spec.rb
97
+ - spec/outputs/blob/temporary_file_spec.rb
98
+ - spec/outputs/blob/time_rotation_policy_spec.rb
99
+ - spec/outputs/blob/uploader_spec.rb
100
+ - spec/outputs/blob/writable_directory_validator_spec.rb
101
+ - spec/spec_helper.rb
102
+ - spec/supports/helpers.rb
103
+ homepage:
104
+ licenses:
105
+ - Apache-2.0
106
+ metadata:
107
+ logstash_plugin: 'true'
108
+ logstash_group: output
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.6.8
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Plugin for logstash to send output to Microsoft Azure Blob
129
+ test_files:
130
+ - spec/outputs/Logstash_Azure_Blob_Output_spec.rb
131
+ - spec/outputs/blob/file_repository_spec.rb
132
+ - spec/outputs/blob/size_and_time_rotation_policy_spec.rb
133
+ - spec/outputs/blob/size_rotation_policy_spec.rb
134
+ - spec/outputs/blob/temporary_file_factory_spec.rb
135
+ - spec/outputs/blob/temporary_file_spec.rb
136
+ - spec/outputs/blob/time_rotation_policy_spec.rb
137
+ - spec/outputs/blob/uploader_spec.rb
138
+ - spec/outputs/blob/writable_directory_validator_spec.rb
139
+ - spec/spec_helper.rb
140
+ - spec/supports/helpers.rb