vault-tools 0.5.8 → 0.5.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vault-tools (0.5.7)
4
+ vault-tools (0.5.9)
5
5
  aws-sdk
6
6
  fernet (= 2.0.rc2)
7
7
  heroku-api
@@ -17,20 +17,20 @@ GEM
17
17
  remote: https://rubygems.org/
18
18
  specs:
19
19
  ansi (1.4.3)
20
- aws-sdk (1.53.0)
21
- aws-sdk-v1 (= 1.53.0)
22
- aws-sdk-v1 (1.53.0)
20
+ aws-sdk (1.57.0)
21
+ aws-sdk-v1 (= 1.57.0)
22
+ aws-sdk-v1 (1.57.0)
23
23
  json (~> 1.4)
24
24
  nokogiri (>= 1.4.4)
25
25
  celluloid (0.16.0)
26
26
  timers (~> 4.0.0)
27
27
  coderay (1.1.0)
28
- excon (0.39.6)
28
+ excon (0.41.0)
29
29
  fernet (2.0.rc2)
30
30
  valcro (= 0.1)
31
- ffi (1.9.3)
31
+ ffi (1.9.6)
32
32
  formatador (0.2.5)
33
- guard (2.6.1)
33
+ guard (2.8.1)
34
34
  formatador (>= 0.2.4)
35
35
  listen (~> 2.7)
36
36
  lumberjack (~> 1.0)
@@ -46,18 +46,18 @@ GEM
46
46
  honeybadger (1.16.5)
47
47
  json
48
48
  json (1.8.1)
49
- listen (2.7.9)
49
+ listen (2.7.11)
50
50
  celluloid (>= 0.15.2)
51
51
  rb-fsevent (>= 0.9.3)
52
52
  rb-inotify (>= 0.9)
53
- logfmt (0.0.6)
53
+ logfmt (0.0.7)
54
54
  lumberjack (1.0.9)
55
55
  method_source (0.8.2)
56
- mini_portile (0.6.0)
56
+ mini_portile (0.6.1)
57
57
  minitest (4.7.5)
58
58
  multi_json (1.10.1)
59
- nokogiri (1.6.3.1)
60
- mini_portile (= 0.6.0)
59
+ nokogiri (1.6.4)
60
+ mini_portile (~> 0.6.0)
61
61
  pry (0.10.1)
62
62
  coderay (~> 1.1.0)
63
63
  method_source (~> 0.8.1)
@@ -68,7 +68,7 @@ GEM
68
68
  rack-ssl-enforcer (0.2.8)
69
69
  rack-test (0.6.2)
70
70
  rack (>= 1.0)
71
- rake (10.1.0)
71
+ rake (10.3.2)
72
72
  rb-fsevent (0.9.4)
73
73
  rb-inotify (0.9.5)
74
74
  ffi (>= 0.5.0)
@@ -85,14 +85,14 @@ GEM
85
85
  slop (3.6.0)
86
86
  thor (0.19.1)
87
87
  tilt (1.4.1)
88
- timers (4.0.0)
88
+ timers (4.0.1)
89
89
  hitimes
90
90
  turn (0.9.7)
91
91
  ansi
92
92
  minitest (~> 4)
93
93
  uuidtools (2.1.5)
94
94
  valcro (0.1)
95
- vault-test-tools (0.3.8)
95
+ vault-test-tools (0.3.9)
96
96
  guard-minitest
97
97
  logfmt
98
98
  minitest (~> 4.7.4)
@@ -101,7 +101,7 @@ GEM
101
101
  rr
102
102
  scrolls
103
103
  turn
104
- yard (0.8.7.3)
104
+ yard (0.8.7.6)
105
105
  yard-sinatra (1.0.0)
106
106
  yard (~> 0.7)
107
107
 
@@ -82,3 +82,4 @@ require 'vault-tools/pipeline'
82
82
  require 'vault-tools/text_processor'
83
83
  require 'vault-tools/time'
84
84
  require 'vault-tools/s3'
85
+ require 'vault-tools/statement_store'
@@ -0,0 +1,81 @@
1
+ module Vault
2
+ # The StatementStore knows how to save and retrieve invoices from S3
3
+ class StatementStore
4
+ def initialize(opts = {})
5
+ @key_id = opts.fetch(:key_id, ENV['AWS_ACCESS_KEY_ID'])
6
+ @key = opts.fetch(:key, ENV['AWS_SECRET_ACCESS_KEY'])
7
+ end
8
+
9
+ # Retrieve invoice JSON from S3
10
+ def get_json(opts)
11
+ contents = retrieve(:json, opts)
12
+ begin
13
+ JSON.parse(contents)
14
+ rescue
15
+ contents
16
+ end
17
+ end
18
+
19
+ # Write as JSON to S3
20
+ def write_json(opts)
21
+ write(:json, opts)
22
+ end
23
+
24
+ # Retrieve invoice HTML from S3
25
+ def get_html(opts)
26
+ retrieve(:html, opts)
27
+ end
28
+
29
+ # Write contents as is to HTML bucket on S3
30
+ def write_html(opts)
31
+ write(:html, opts)
32
+ end
33
+
34
+ # Retrieve the contents in a given format of a given file from S3
35
+ def retrieve(format, opts)
36
+ s3.buckets[bucket_for(format, opts)].objects[path_for(opts)].read
37
+ end
38
+
39
+ # Write the contents in the given format to S3
40
+ def write(format, opts)
41
+ obj = s3.buckets[bucket_for(format, opts)].objects[path_for(opts)]
42
+ obj.write(opts[:contents])
43
+ end
44
+
45
+ # Get an instance of the S3 client to work with
46
+ def s3
47
+ @s3 ||= AWS::S3.new(access_key_id: @key_id, secret_access_key: @key,
48
+ use_ssl: true)
49
+ end
50
+
51
+ # Determine which bucket an invoice should live in
52
+ def bucket_for(format, opts)
53
+ version = opts[:version]
54
+ invoice_bucket = ENV['INVOICE_BUCKET_NAME'] || 'invoice-test'
55
+ if format == :html
56
+ "vault-v#{version}-#{invoice_bucket}"
57
+ else
58
+ "vault-v#{version}-json-#{invoice_bucket}"
59
+ end
60
+ end
61
+
62
+ # Determine the path on S3 for the given invoice
63
+ def path_for(opts = {})
64
+ validate_path_opts(opts)
65
+ start = DateTime.parse(opts[:start_time].to_s)
66
+ stop = DateTime.parse(opts[:stop_time].to_s)
67
+ user_hid = opts[:user_hid] || "user#{opts[:user_id]}@heroku.com"
68
+ sprintf('%s/%s/%s_v%s', start, stop, user_hid, opts[:version])
69
+ end
70
+
71
+ private
72
+
73
+ def validate_path_opts(opts)
74
+ fail(ArgumentError, 'start_time required!') unless opts[:start_time]
75
+ fail(ArgumentError, 'stop_time required!') unless opts[:stop_time]
76
+ fail(ArgumentError, 'version required!') unless opts[:version]
77
+ user = opts[:user_hid] || opts[:user_id]
78
+ fail(ArgumentError, 'user_hid or or user_id required!') unless user
79
+ end
80
+ end
81
+ end
@@ -1,5 +1,5 @@
1
1
  module Vault
2
2
  module Tools
3
- VERSION = '0.5.8'
3
+ VERSION = '0.5.9'
4
4
  end
5
5
  end
@@ -38,4 +38,72 @@ class Vault::TestCase
38
38
  include HoneybadgerHelper
39
39
  end
40
40
 
41
+ module StubbedS3
42
+ class FakeFile
43
+ def initialize(contents=nil)
44
+ @contents = contents
45
+ end
46
+
47
+ def write(contents)
48
+ @contents = contents
49
+ end
50
+
51
+ def read
52
+ @contents
53
+ end
54
+ end
55
+
56
+ class FakeBucket
57
+ def initialize
58
+ @files = {}
59
+ end
60
+
61
+ def [](file_name)
62
+ @files[file_name] ||= FakeFile.new
63
+ end
64
+
65
+ def write(file_name, contents)
66
+ @files[file_name].write(contents)
67
+ end
68
+
69
+ def objects
70
+ self
71
+ end
72
+ end
73
+
74
+ class FakeClient
75
+ def initialize
76
+ @buckets = {}
77
+ end
78
+
79
+ def [](bucket_name)
80
+ @buckets[bucket_name] ||= FakeBucket.new
81
+ end
82
+
83
+ def buckets
84
+ self
85
+ end
86
+ end
87
+
88
+ class << self
89
+ def seed(bucket, file, contents)
90
+ fake_client.buckets[bucket].objects[file].write(contents)
91
+ end
92
+
93
+ def fake_client
94
+ @client ||= FakeClient.new
95
+ end
96
+
97
+ def enable!(env, opts={})
98
+ AWS.stub!
99
+ expected_aws_args = {
100
+ access_key_id: opts.fetch(:access_key_id, 'FAKE_ID'),
101
+ secret_access_key: opts.fetch(:secret_access_key, 'FAKE_KEY'),
102
+ use_ssl: opts.fetch(:use_ssl, true)
103
+ }
104
+ env.stub(AWS::S3).new(expected_aws_args) { fake_client }
105
+ end
106
+ end
107
+ end
108
+
41
109
  Vault.setup
@@ -0,0 +1,54 @@
1
+ require 'helper'
2
+
3
+ class StatementStoreTest < Vault::TestCase
4
+ def setup
5
+ super
6
+ StubbedS3.enable!(self)
7
+ StubbedS3.seed('vault-v2-json-invoice-test',
8
+ '2014-10-01T00:00:00+00:00/2014-11-01T00:00:00+00:00/user8@heroku.com_v2',
9
+ '{"foo": 1}')
10
+
11
+ end
12
+
13
+ def test_invoice_path_with_user_id
14
+ inv = Vault::StatementStore.new(key_id: 'FAKE_ID', key: 'FAKE_KEY')
15
+ path = inv.path_for(start_time: '2014-10-01', stop_time: '2014-11-01',
16
+ user_id: 7, version: 2)
17
+ assert_equal '2014-10-01T00:00:00+00:00/2014-11-01T00:00:00+00:00/user7@heroku.com_v2', path
18
+ end
19
+
20
+ def test_invoice_path_with_user_hid
21
+ inv = Vault::StatementStore.new(key_id: 'FAKE_ID', key: 'FAKE_KEY')
22
+ path = inv.path_for(start_time: '2014-10-01', stop_time: '2014-11-01',
23
+ user_hid: 'user8@heroku.com', version: 2)
24
+ assert_equal '2014-10-01T00:00:00+00:00/2014-11-01T00:00:00+00:00/user8@heroku.com_v2', path
25
+ end
26
+
27
+ def test_retrieve_invoice_json
28
+ inv = Vault::StatementStore.new(key_id: 'FAKE_ID', key: 'FAKE_KEY')
29
+ doc = inv.get_json(start_time: '2014-10-01', stop_time: '2014-11-01',
30
+ user_hid: 'user8@heroku.com', version: 2)
31
+ expected = {"foo" => 1}
32
+ assert_equal expected, doc
33
+ end
34
+
35
+ def test_write_invoice_json
36
+ inv = Vault::StatementStore.new(key_id: 'FAKE_ID', key: 'FAKE_KEY')
37
+ # Nothing Before Write
38
+ doc = inv.get_json(start_time: '2014-10-01', stop_time: '2014-11-01',
39
+ user_hid: 'user9@heroku.com', version: 2)
40
+ expected = nil
41
+ assert_equal expected, doc
42
+
43
+ # Write to S3 updating expectation
44
+ expected = {"bar" => 3}
45
+ inv.write_json(start_time: '2014-10-01', stop_time: '2014-11-01',
46
+ user_hid: 'user9@heroku.com', version: 2,
47
+ contents: expected)
48
+
49
+ # There after write
50
+ doc = inv.get_json(start_time: '2014-10-01', stop_time: '2014-11-01',
51
+ user_hid: 'user9@heroku.com', version: 2)
52
+ assert_equal expected, doc
53
+ end
54
+ end
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vault-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.8
4
+ version: 0.5.9
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Chris Continanza
@@ -9,11 +10,12 @@ authors:
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2014-10-22 00:00:00.000000000 Z
13
+ date: 2014-11-11 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: scrolls
16
17
  requirement: !ruby/object:Gem::Requirement
18
+ none: false
17
19
  requirements:
18
20
  - - ! '>='
19
21
  - !ruby/object:Gem::Version
@@ -21,6 +23,7 @@ dependencies:
21
23
  type: :runtime
22
24
  prerelease: false
23
25
  version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
24
27
  requirements:
25
28
  - - ! '>='
26
29
  - !ruby/object:Gem::Version
@@ -28,6 +31,7 @@ dependencies:
28
31
  - !ruby/object:Gem::Dependency
29
32
  name: sinatra
30
33
  requirement: !ruby/object:Gem::Requirement
34
+ none: false
31
35
  requirements:
32
36
  - - ~>
33
37
  - !ruby/object:Gem::Version
@@ -35,6 +39,7 @@ dependencies:
35
39
  type: :runtime
36
40
  prerelease: false
37
41
  version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
38
43
  requirements:
39
44
  - - ~>
40
45
  - !ruby/object:Gem::Version
@@ -42,6 +47,7 @@ dependencies:
42
47
  - !ruby/object:Gem::Dependency
43
48
  name: uuidtools
44
49
  requirement: !ruby/object:Gem::Requirement
50
+ none: false
45
51
  requirements:
46
52
  - - ! '>='
47
53
  - !ruby/object:Gem::Version
@@ -49,6 +55,7 @@ dependencies:
49
55
  type: :runtime
50
56
  prerelease: false
51
57
  version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
52
59
  requirements:
53
60
  - - ! '>='
54
61
  - !ruby/object:Gem::Version
@@ -56,6 +63,7 @@ dependencies:
56
63
  - !ruby/object:Gem::Dependency
57
64
  name: rack-ssl-enforcer
58
65
  requirement: !ruby/object:Gem::Requirement
66
+ none: false
59
67
  requirements:
60
68
  - - ! '>='
61
69
  - !ruby/object:Gem::Version
@@ -63,6 +71,7 @@ dependencies:
63
71
  type: :runtime
64
72
  prerelease: false
65
73
  version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
66
75
  requirements:
67
76
  - - ! '>='
68
77
  - !ruby/object:Gem::Version
@@ -70,6 +79,7 @@ dependencies:
70
79
  - !ruby/object:Gem::Dependency
71
80
  name: heroku-api
72
81
  requirement: !ruby/object:Gem::Requirement
82
+ none: false
73
83
  requirements:
74
84
  - - ! '>='
75
85
  - !ruby/object:Gem::Version
@@ -77,6 +87,7 @@ dependencies:
77
87
  type: :runtime
78
88
  prerelease: false
79
89
  version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
80
91
  requirements:
81
92
  - - ! '>='
82
93
  - !ruby/object:Gem::Version
@@ -84,6 +95,7 @@ dependencies:
84
95
  - !ruby/object:Gem::Dependency
85
96
  name: fernet
86
97
  requirement: !ruby/object:Gem::Requirement
98
+ none: false
87
99
  requirements:
88
100
  - - '='
89
101
  - !ruby/object:Gem::Version
@@ -91,6 +103,7 @@ dependencies:
91
103
  type: :runtime
92
104
  prerelease: false
93
105
  version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
94
107
  requirements:
95
108
  - - '='
96
109
  - !ruby/object:Gem::Version
@@ -98,6 +111,7 @@ dependencies:
98
111
  - !ruby/object:Gem::Dependency
99
112
  name: honeybadger
100
113
  requirement: !ruby/object:Gem::Requirement
114
+ none: false
101
115
  requirements:
102
116
  - - ! '>='
103
117
  - !ruby/object:Gem::Version
@@ -105,6 +119,7 @@ dependencies:
105
119
  type: :runtime
106
120
  prerelease: false
107
121
  version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
108
123
  requirements:
109
124
  - - ! '>='
110
125
  - !ruby/object:Gem::Version
@@ -112,6 +127,7 @@ dependencies:
112
127
  - !ruby/object:Gem::Dependency
113
128
  name: rdoc
114
129
  requirement: !ruby/object:Gem::Requirement
130
+ none: false
115
131
  requirements:
116
132
  - - ! '>='
117
133
  - !ruby/object:Gem::Version
@@ -119,6 +135,7 @@ dependencies:
119
135
  type: :runtime
120
136
  prerelease: false
121
137
  version_requirements: !ruby/object:Gem::Requirement
138
+ none: false
122
139
  requirements:
123
140
  - - ! '>='
124
141
  - !ruby/object:Gem::Version
@@ -126,6 +143,7 @@ dependencies:
126
143
  - !ruby/object:Gem::Dependency
127
144
  name: yard
128
145
  requirement: !ruby/object:Gem::Requirement
146
+ none: false
129
147
  requirements:
130
148
  - - ! '>='
131
149
  - !ruby/object:Gem::Version
@@ -133,6 +151,7 @@ dependencies:
133
151
  type: :runtime
134
152
  prerelease: false
135
153
  version_requirements: !ruby/object:Gem::Requirement
154
+ none: false
136
155
  requirements:
137
156
  - - ! '>='
138
157
  - !ruby/object:Gem::Version
@@ -140,6 +159,7 @@ dependencies:
140
159
  - !ruby/object:Gem::Dependency
141
160
  name: aws-sdk
142
161
  requirement: !ruby/object:Gem::Requirement
162
+ none: false
143
163
  requirements:
144
164
  - - ! '>='
145
165
  - !ruby/object:Gem::Version
@@ -147,6 +167,7 @@ dependencies:
147
167
  type: :runtime
148
168
  prerelease: false
149
169
  version_requirements: !ruby/object:Gem::Requirement
170
+ none: false
150
171
  requirements:
151
172
  - - ! '>='
152
173
  - !ruby/object:Gem::Version
@@ -184,6 +205,7 @@ files:
184
205
  - lib/vault-tools/product.rb
185
206
  - lib/vault-tools/s3.rb
186
207
  - lib/vault-tools/sinatra_helpers/html_serializer.rb
208
+ - lib/vault-tools/statement_store.rb
187
209
  - lib/vault-tools/tasks.rb
188
210
  - lib/vault-tools/text_processor.rb
189
211
  - lib/vault-tools/time.rb
@@ -201,6 +223,7 @@ files:
201
223
  - test/pipeline_test.rb
202
224
  - test/product_test.rb
203
225
  - test/s3_test.rb
226
+ - test/statement_store_test.rb
204
227
  - test/text_processor_test.rb
205
228
  - test/time_test.rb
206
229
  - test/user_test.rb
@@ -208,26 +231,27 @@ files:
208
231
  - vault-tools.gemspec
209
232
  homepage: ''
210
233
  licenses: []
211
- metadata: {}
212
234
  post_install_message:
213
235
  rdoc_options: []
214
236
  require_paths:
215
237
  - lib
216
238
  required_ruby_version: !ruby/object:Gem::Requirement
239
+ none: false
217
240
  requirements:
218
241
  - - ! '>='
219
242
  - !ruby/object:Gem::Version
220
243
  version: '0'
221
244
  required_rubygems_version: !ruby/object:Gem::Requirement
245
+ none: false
222
246
  requirements:
223
247
  - - ! '>='
224
248
  - !ruby/object:Gem::Version
225
249
  version: '0'
226
250
  requirements: []
227
251
  rubyforge_project:
228
- rubygems_version: 2.2.2
252
+ rubygems_version: 1.8.23
229
253
  signing_key:
230
- specification_version: 4
254
+ specification_version: 3
231
255
  summary: Test classes, base web classes, and helpers - oh my!
232
256
  test_files: []
233
257
  has_rdoc:
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YTA5MzFhZjViMjA3ODU3NDBmMjdmMzNkYzk4NzU3MjlmMDhkMTBjOQ==
5
- data.tar.gz: !binary |-
6
- ZDlkZGQ5NjRhNDUwNGExMGQ2Y2NkODU2M2I5ZjYyMzczY2U2YTQyMQ==
7
- SHA512:
8
- metadata.gz: !binary |-
9
- NGQ2MDYwNDk1NmMyMTIyYTAyZTA4MGVmZjI2ZjYxODZjZGEzZTBmMTZiOThk
10
- ZDY5MTM2NDQyZGFmNjNkMzE3MDZjMWQxYWIwYTVhOTY0N2I5MGMxYzRiYmEw
11
- YjZkMjA0NzJlY2I1ZDBmY2FiYjM0MGQyMDFhZTNmNjc3MzAyNTU=
12
- data.tar.gz: !binary |-
13
- YjcxZTY5NzMwZDg5NDFmY2ZiNTVlNGE0ZjRjMGQ3MGUzZTlkOGE2MjY5NjRj
14
- ZWI2ODJmNGM1NWI1NWM5ZDRhMzZjZmJkOWNlZjI5MmFkYWE4MmQzZTI3ZDg4
15
- M2Y3ZmYwYmVhYzI2NjMzNjhlYWJmMzg0ZWQ1N2EyZTQ5NTdlNzg=