phill 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0742ffb15896bb0e9af18cc3aafc48daf368da4
4
- data.tar.gz: 378fa52a23fd2bb5d675a45ea3b368b4b13d690b
3
+ metadata.gz: 02bcea78612b59bcfbda71a37edee09882e7e050
4
+ data.tar.gz: a8bae8a0820052dbdf03e92a529a48ac98e221f1
5
5
  SHA512:
6
- metadata.gz: bf71517e72d4b51fa4b79aca821cdf823d0323c37b556504a39c07ed550524959dc98fbeb95584f7c64f62d7df99cbaf44c6613021077518d9a2718e7f6cb395
7
- data.tar.gz: 9acc2de7705a827c19fab61ff676509ee556c1e3d8c83905989fe2ed18914e450ede22f9e67c52baed5d7ab9dba838c31d063e72a1d93f4e6ae4300fe2bdbbcc
6
+ metadata.gz: 60853dfc5a2878c148c44c4346a06a31c76ee8f99af2567ca6a0a190063eeda9ca37a402ff37d9c24f5754ed75ddf2d58b4058e31af0bb2bb75af0a5f89b0d8d
7
+ data.tar.gz: 8be8ed4e7cfc786305ad912f6d5ea8dbf8cde48090f53c22e0134b7f38112ecd5508a76e0aa292c7bd0430a45c0aac826b72392be5cf13907bf755d0a6f91fde
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
- Gemfile.lock
1
+ config/*.yml
2
+ coverage/
data/Gemfile.lock ADDED
@@ -0,0 +1,234 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ phill (1.0.0)
5
+ activesupport
6
+ awscli
7
+ minitar
8
+ recursive-open-struct
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ CFPropertyList (2.3.3)
14
+ activemodel (5.0.0.1)
15
+ activesupport (= 5.0.0.1)
16
+ activerecord (5.0.0.1)
17
+ activemodel (= 5.0.0.1)
18
+ activesupport (= 5.0.0.1)
19
+ arel (~> 7.0)
20
+ activesupport (5.0.0.1)
21
+ concurrent-ruby (~> 1.0, >= 1.0.2)
22
+ i18n (~> 0.7)
23
+ minitest (~> 5.1)
24
+ tzinfo (~> 1.1)
25
+ arel (7.1.4)
26
+ awscli (0.2.8)
27
+ fog (>= 1.16.0)
28
+ highline
29
+ multi_json
30
+ thor (>= 0.17.0)
31
+ builder (3.2.2)
32
+ codeclimate-test-reporter (0.6.0)
33
+ simplecov (>= 0.7.1, < 1.0.0)
34
+ coderay (1.1.1)
35
+ concurrent-ruby (1.0.2)
36
+ diff-lcs (1.2.5)
37
+ docile (1.1.5)
38
+ excon (0.54.0)
39
+ fission (0.5.0)
40
+ CFPropertyList (~> 2.2)
41
+ fog (1.38.0)
42
+ fog-aliyun (>= 0.1.0)
43
+ fog-atmos
44
+ fog-aws (>= 0.6.0)
45
+ fog-brightbox (~> 0.4)
46
+ fog-cloudatcost (~> 0.1.0)
47
+ fog-core (~> 1.32)
48
+ fog-dynect (~> 0.0.2)
49
+ fog-ecloud (~> 0.1)
50
+ fog-google (<= 0.1.0)
51
+ fog-json
52
+ fog-local
53
+ fog-openstack
54
+ fog-powerdns (>= 0.1.1)
55
+ fog-profitbricks
56
+ fog-rackspace
57
+ fog-radosgw (>= 0.0.2)
58
+ fog-riakcs
59
+ fog-sakuracloud (>= 0.0.4)
60
+ fog-serverlove
61
+ fog-softlayer
62
+ fog-storm_on_demand
63
+ fog-terremark
64
+ fog-vmfusion
65
+ fog-voxel
66
+ fog-vsphere (>= 0.4.0)
67
+ fog-xenserver
68
+ fog-xml (~> 0.1.1)
69
+ ipaddress (~> 0.5)
70
+ fog-aliyun (0.1.0)
71
+ fog-core (~> 1.27)
72
+ fog-json (~> 1.0)
73
+ ipaddress (~> 0.8)
74
+ xml-simple (~> 1.1)
75
+ fog-atmos (0.1.0)
76
+ fog-core
77
+ fog-xml
78
+ fog-aws (0.12.0)
79
+ fog-core (~> 1.38)
80
+ fog-json (~> 1.0)
81
+ fog-xml (~> 0.1)
82
+ ipaddress (~> 0.8)
83
+ fog-brightbox (0.11.0)
84
+ fog-core (~> 1.22)
85
+ fog-json
86
+ inflecto (~> 0.0.2)
87
+ fog-cloudatcost (0.1.2)
88
+ fog-core (~> 1.36)
89
+ fog-json (~> 1.0)
90
+ fog-xml (~> 0.1)
91
+ ipaddress (~> 0.8)
92
+ fog-core (1.43.0)
93
+ builder
94
+ excon (~> 0.49)
95
+ formatador (~> 0.2)
96
+ fog-dynect (0.0.3)
97
+ fog-core
98
+ fog-json
99
+ fog-xml
100
+ fog-ecloud (0.3.0)
101
+ fog-core
102
+ fog-xml
103
+ fog-google (0.1.0)
104
+ fog-core
105
+ fog-json
106
+ fog-xml
107
+ fog-json (1.0.2)
108
+ fog-core (~> 1.0)
109
+ multi_json (~> 1.10)
110
+ fog-local (0.3.1)
111
+ fog-core (~> 1.27)
112
+ fog-openstack (0.1.15)
113
+ fog-core (>= 1.40)
114
+ fog-json (>= 1.0)
115
+ ipaddress (>= 0.8)
116
+ fog-powerdns (0.1.1)
117
+ fog-core (~> 1.27)
118
+ fog-json (~> 1.0)
119
+ fog-xml (~> 0.1)
120
+ fog-profitbricks (2.0.1)
121
+ fog-core (~> 1.42)
122
+ fog-json (~> 1.0)
123
+ fog-rackspace (0.1.1)
124
+ fog-core (>= 1.35)
125
+ fog-json (>= 1.0)
126
+ fog-xml (>= 0.1)
127
+ ipaddress (>= 0.8)
128
+ fog-radosgw (0.0.5)
129
+ fog-core (>= 1.21.0)
130
+ fog-json
131
+ fog-xml (>= 0.0.1)
132
+ fog-riakcs (0.1.0)
133
+ fog-core
134
+ fog-json
135
+ fog-xml
136
+ fog-sakuracloud (1.7.5)
137
+ fog-core
138
+ fog-json
139
+ fog-serverlove (0.1.2)
140
+ fog-core
141
+ fog-json
142
+ fog-softlayer (1.1.4)
143
+ fog-core
144
+ fog-json
145
+ fog-storm_on_demand (0.1.1)
146
+ fog-core
147
+ fog-json
148
+ fog-terremark (0.1.0)
149
+ fog-core
150
+ fog-xml
151
+ fog-vmfusion (0.1.0)
152
+ fission
153
+ fog-core
154
+ fog-voxel (0.1.0)
155
+ fog-core
156
+ fog-xml
157
+ fog-vsphere (1.5.0)
158
+ fog-core
159
+ rbvmomi (~> 1.9)
160
+ fog-xenserver (0.2.3)
161
+ fog-core
162
+ fog-xml
163
+ fog-xml (0.1.2)
164
+ fog-core
165
+ nokogiri (~> 1.5, >= 1.5.11)
166
+ formatador (0.2.5)
167
+ highline (1.7.8)
168
+ i18n (0.7.0)
169
+ inflecto (0.0.2)
170
+ ipaddress (0.8.3)
171
+ json (2.0.2)
172
+ method_source (0.8.2)
173
+ mini_portile2 (2.1.0)
174
+ minitar (0.5.4)
175
+ minitest (5.9.1)
176
+ multi_json (1.12.1)
177
+ nokogiri (1.6.8.1)
178
+ mini_portile2 (~> 2.1.0)
179
+ pry (0.10.4)
180
+ coderay (~> 1.1.0)
181
+ method_source (~> 0.8.1)
182
+ slop (~> 3.4)
183
+ pry-nav (0.2.4)
184
+ pry (>= 0.9.10, < 0.11.0)
185
+ rake (11.3.0)
186
+ rbvmomi (1.9.4)
187
+ builder (~> 3.2)
188
+ json (>= 1.8)
189
+ nokogiri (~> 1.5)
190
+ trollop (~> 2.1)
191
+ recursive-open-struct (1.0.1)
192
+ rspec (3.4.0)
193
+ rspec-core (~> 3.4.0)
194
+ rspec-expectations (~> 3.4.0)
195
+ rspec-mocks (~> 3.4.0)
196
+ rspec-core (3.4.4)
197
+ rspec-support (~> 3.4.0)
198
+ rspec-expectations (3.4.0)
199
+ diff-lcs (>= 1.2.0, < 2.0)
200
+ rspec-support (~> 3.4.0)
201
+ rspec-mocks (3.4.1)
202
+ diff-lcs (>= 1.2.0, < 2.0)
203
+ rspec-support (~> 3.4.0)
204
+ rspec-support (3.4.1)
205
+ simplecov (0.12.0)
206
+ docile (~> 1.1.0)
207
+ json (>= 1.8, < 3)
208
+ simplecov-html (~> 0.10.0)
209
+ simplecov-html (0.10.0)
210
+ slop (3.6.0)
211
+ sqlite3 (1.3.12)
212
+ thor (0.19.1)
213
+ thread_safe (0.3.5)
214
+ trollop (2.1.2)
215
+ tzinfo (1.2.2)
216
+ thread_safe (~> 0.1)
217
+ xml-simple (1.1.5)
218
+
219
+ PLATFORMS
220
+ ruby
221
+
222
+ DEPENDENCIES
223
+ activerecord
224
+ bundler
225
+ codeclimate-test-reporter
226
+ phill!
227
+ pry-nav
228
+ rake
229
+ rspec (~> 3.4.0)
230
+ simplecov
231
+ sqlite3
232
+
233
+ BUNDLED WITH
234
+ 1.12.5
@@ -0,0 +1,28 @@
1
+ require 'recursive-open-struct'
2
+ require 'awscli'
3
+
4
+ class Phill::AwsClient
5
+ class << self
6
+ include Phill::Configurable
7
+
8
+ def upload(locations)
9
+ locations.each do |location|
10
+ location.files.each do |file|
11
+ client.put_object(
12
+ bucket: location.bucket,
13
+ key: [ location.aws_folder, file.compressed_name ].join('/').gsub(/^\/*/,''),
14
+ body: file.compressed_file,
15
+ )
16
+ end
17
+ end
18
+ end
19
+
20
+ def client
21
+ @client ||= Aws::S3::Client.new(
22
+ access_key_id: config.access_key_id,
23
+ secret_access_key: config.secret_access_key,
24
+ region: config.region
25
+ )
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,7 @@
1
+ module Phill::Configurable
2
+ attr_reader :config
3
+
4
+ def config=(hash)
5
+ @config = RecursiveOpenStruct.new(hash, recurse_over_arrays: true)
6
+ end
7
+ end
data/lib/phill/file.rb ADDED
@@ -0,0 +1,45 @@
1
+ require 'zlib'
2
+ require 'archive/tar/minitar'
3
+ require 'time'
4
+
5
+ class Phill::File
6
+ include Archive::Tar
7
+
8
+ attr_reader :path
9
+
10
+ def initialize(path)
11
+ @path = path
12
+ end
13
+
14
+ def process
15
+ compress
16
+ File.open(path, 'w').close
17
+ end
18
+
19
+ def compressed_file
20
+ @compressed_file ||= File.open(compressed_path, 'rb')
21
+ end
22
+
23
+ def compressed_name
24
+ @compressed_name ||= compressed_path.gsub(/.*\//, '')
25
+ end
26
+
27
+ private
28
+
29
+ def compress
30
+ Minitar.pack(path, gzip_file)
31
+ end
32
+
33
+ def compressed_path
34
+ @compressed_path ||= "#{path}.#{date_string}.tar.gz"
35
+ end
36
+
37
+ def date_string
38
+ @date_string ||= Time.now.strftime '%Y%m%d'
39
+ end
40
+
41
+ def gzip_file
42
+ @gzip_file ||= Zlib::GzipWriter.open(compressed_path)
43
+ end
44
+ end
45
+
@@ -0,0 +1,9 @@
1
+ class Phill::Location < DelegateClass(RecursiveOpenStruct)
2
+ def files
3
+ @files ||= super.map { |f| Phill::File.new(f) }
4
+ end
5
+
6
+ def process
7
+ files.each(&:process)
8
+ end
9
+ end
data/lib/phill/version.rb CHANGED
@@ -1,4 +1,3 @@
1
1
  class Phill
2
- VERSION = '0.0.1'
2
+ VERSION='0.1.0'
3
3
  end
4
-
data/lib/phill.rb CHANGED
@@ -1,2 +1,23 @@
1
+ require 'recursive-open-struct'
2
+ require 'yaml'
3
+
1
4
  class Phill
5
+ require 'phill/version'
6
+ require 'phill/configurable'
7
+ require 'phill/aws_client'
8
+ require 'phill/location'
9
+ require 'phill/file'
10
+
11
+ class << self
12
+ include Phill::Configurable
13
+
14
+ def locations
15
+ @locations ||= config.locations.map { |l| Location.new(l) }
16
+ end
17
+
18
+ def process
19
+ locations.each(&:process)
20
+ AwsClient.upload(locations)
21
+ end
22
+ end
2
23
  end
data/phill.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
9
9
  gem.authors = ["Bidu Dev's Team"]
10
10
  gem.email = ["dev@bidu.com.br"]
11
11
  gem.homepage = 'https://github.com/Bidu/phill'
12
- gem.description = 'Gem for log rotation and S3 upload'
12
+ gem.description = 'Gem for easy log rotation and S3 upload'
13
13
  gem.summary = gem.description
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
@@ -17,9 +17,18 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|gem|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
 
20
- gem.add_development_dependency "bundler", "~> 1.6"
20
+ gem.add_runtime_dependency 'activesupport'
21
+ gem.add_runtime_dependency 'awscli'
22
+ gem.add_runtime_dependency 'recursive-open-struct'
23
+ gem.add_runtime_dependency 'minitar'
24
+
25
+ gem.add_development_dependency "activerecord"
26
+ gem.add_development_dependency "sqlite3"
27
+
28
+ gem.add_development_dependency "bundler"
21
29
  gem.add_development_dependency "rake"
22
- gem.add_development_dependency "rspec", "~> 2.14"
30
+ gem.add_development_dependency "rspec", "~> 3.4.0"
31
+ gem.add_development_dependency 'pry-nav'
23
32
  gem.add_development_dependency 'simplecov'
24
33
  gem.add_development_dependency 'codeclimate-test-reporter'
25
34
  end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Phill::AwsClient do
4
+ it_behaves_like 'a module that is configurable'
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Phill do
4
+ it_behaves_like 'a module that is configurable'
5
+ end
data/spec/spec_helper.rb CHANGED
@@ -11,12 +11,12 @@ end
11
11
  SimpleCov.start 'gem'
12
12
 
13
13
  require 'phill'
14
+ require 'pry'
14
15
 
15
16
  support_files = File.expand_path("spec/support/**/*.rb")
16
17
  Dir[support_files].each { |file| require file }
17
18
 
18
19
  RSpec.configure do |config|
19
- config.treat_symbols_as_metadata_keys_with_true_values = true
20
20
  config.run_all_when_everything_filtered = true
21
21
  config.filter_run :focus
22
22
  config.filter_run_excluding :integration unless ENV['ALL']
@@ -0,0 +1,23 @@
1
+ shared_examples 'a module that is configurable' do
2
+ it { expect(described_class).to respond_to(:config) }
3
+ it { expect(described_class).to respond_to(:config=) }
4
+
5
+ describe '.config' do
6
+ context 'after configuration' do
7
+ let(:config) { { a: 1, b: [{ c: 2 }] } }
8
+ before do
9
+ described_class.config = config
10
+ end
11
+
12
+ it { expect(described_class.config).to be_a(RecursiveOpenStruct) }
13
+
14
+ it do
15
+ expect(described_class.config.to_h).to eq(config)
16
+ end
17
+
18
+ it 'recurse over arrays' do
19
+ expect(described_class.config.b.first).to be_a(RecursiveOpenStruct)
20
+ end
21
+ end
22
+ end
23
+ end
metadata CHANGED
@@ -1,29 +1,113 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phill
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bidu Dev's Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-21 00:00:00.000000000 Z
11
+ date: 2016-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: awscli
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: recursive-open-struct
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitar
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activerecord
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sqlite3
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
13
97
  - !ruby/object:Gem::Dependency
14
98
  name: bundler
15
99
  requirement: !ruby/object:Gem::Requirement
16
100
  requirements:
17
- - - "~>"
101
+ - - ">="
18
102
  - !ruby/object:Gem::Version
19
- version: '1.6'
103
+ version: '0'
20
104
  type: :development
21
105
  prerelease: false
22
106
  version_requirements: !ruby/object:Gem::Requirement
23
107
  requirements:
24
- - - "~>"
108
+ - - ">="
25
109
  - !ruby/object:Gem::Version
26
- version: '1.6'
110
+ version: '0'
27
111
  - !ruby/object:Gem::Dependency
28
112
  name: rake
29
113
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +128,28 @@ dependencies:
44
128
  requirements:
45
129
  - - "~>"
46
130
  - !ruby/object:Gem::Version
47
- version: '2.14'
131
+ version: 3.4.0
48
132
  type: :development
49
133
  prerelease: false
50
134
  version_requirements: !ruby/object:Gem::Requirement
51
135
  requirements:
52
136
  - - "~>"
53
137
  - !ruby/object:Gem::Version
54
- version: '2.14'
138
+ version: 3.4.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry-nav
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
55
153
  - !ruby/object:Gem::Dependency
56
154
  name: simplecov
57
155
  requirement: !ruby/object:Gem::Requirement
@@ -80,7 +178,7 @@ dependencies:
80
178
  - - ">="
81
179
  - !ruby/object:Gem::Version
82
180
  version: '0'
83
- description: Gem for log rotation and S3 upload
181
+ description: Gem for easy log rotation and S3 upload
84
182
  email:
85
183
  - dev@bidu.com.br
86
184
  executables: []
@@ -90,13 +188,21 @@ files:
90
188
  - ".gitignore"
91
189
  - ".rspec"
92
190
  - Gemfile
191
+ - Gemfile.lock
93
192
  - LICENSE
94
193
  - README.md
95
194
  - Rakefile
96
195
  - lib/phill.rb
196
+ - lib/phill/aws_client.rb
197
+ - lib/phill/configurable.rb
198
+ - lib/phill/file.rb
199
+ - lib/phill/location.rb
97
200
  - lib/phill/version.rb
98
201
  - phill.gemspec
202
+ - spec/lib/phill/aws_client_spec.rb
203
+ - spec/lib/phill_spec.rb
99
204
  - spec/spec_helper.rb
205
+ - spec/support/shared_examples/configurable.rb
100
206
  homepage: https://github.com/Bidu/phill
101
207
  licenses: []
102
208
  metadata: {}
@@ -119,5 +225,5 @@ rubyforge_project:
119
225
  rubygems_version: 2.5.1
120
226
  signing_key:
121
227
  specification_version: 4
122
- summary: Gem for log rotation and S3 upload
228
+ summary: Gem for easy log rotation and S3 upload
123
229
  test_files: []