clientside_aws 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/Dockerfile +46 -0
  4. data/Gemfile +23 -0
  5. data/Gemfile.lock +99 -0
  6. data/README.md +105 -0
  7. data/bin/clientside_aws_build +6 -0
  8. data/bin/clientside_aws_run +5 -0
  9. data/bin/clientside_aws_test +4 -0
  10. data/clientside_aws.gemspec +31 -0
  11. data/clientside_aws/dynamodb.rb +722 -0
  12. data/clientside_aws/ec2.rb +103 -0
  13. data/clientside_aws/elastic_transcoder.rb +179 -0
  14. data/clientside_aws/firehose.rb +13 -0
  15. data/clientside_aws/kinesis.rb +13 -0
  16. data/clientside_aws/mock/core.rb +7 -0
  17. data/clientside_aws/mock/firehose.rb +14 -0
  18. data/clientside_aws/mock/kinesis.rb +18 -0
  19. data/clientside_aws/mock/s3.rb +59 -0
  20. data/clientside_aws/mock/ses.rb +74 -0
  21. data/clientside_aws/mock/sns.rb +17 -0
  22. data/clientside_aws/s3.rb +223 -0
  23. data/clientside_aws/ses.rb +9 -0
  24. data/clientside_aws/sns.rb +41 -0
  25. data/clientside_aws/sqs.rb +233 -0
  26. data/docker/clientside-aws-run +3 -0
  27. data/docker/redis-server-run +2 -0
  28. data/index.rb +57 -0
  29. data/lib/clientside_aws.rb +27 -0
  30. data/lib/clientside_aws/configuration.rb +14 -0
  31. data/lib/clientside_aws/mock.rb +224 -0
  32. data/lib/clientside_aws/version.rb +3 -0
  33. data/public/images/jscruff.jpg +0 -0
  34. data/public/images/spacer.gif +0 -0
  35. data/public/images/stock_video.mp4 +0 -0
  36. data/spec/dynamodb_spec.rb +1069 -0
  37. data/spec/ec2_spec.rb +138 -0
  38. data/spec/firehose_spec.rb +16 -0
  39. data/spec/kinesis_spec.rb +22 -0
  40. data/spec/s3_spec.rb +219 -0
  41. data/spec/sns_spec.rb +72 -0
  42. data/spec/spec_helper.rb +71 -0
  43. data/spec/sqs_spec.rb +87 -0
  44. data/spec/test_client/test.rb +45 -0
  45. data/spec/transcoder_spec.rb +138 -0
  46. metadata +241 -0
@@ -0,0 +1,71 @@
1
+ # Set your path to the redis-server binary here
2
+ ENV['RACK_ENV'] = 'test'
3
+
4
+ require 'pry'
5
+ require 'aws-sdk-v1'
6
+ require 'aws-sdk'
7
+ require 'rspec'
8
+ require 'rack/test'
9
+ require 'sinatra'
10
+
11
+ # Configure sinatra as being in test before we include
12
+ # index
13
+ Sinatra::Base.set :environment, :test
14
+ Sinatra::Base.set :run, false
15
+ Sinatra::Base.set :raise_errors, true
16
+ Sinatra::Base.set :logging, false
17
+ Sinatra::Base.set :clientside_aws_testing, true
18
+
19
+ require 'index'
20
+ require 'clientside_aws'
21
+
22
+ RSpec.configure do |config|
23
+ config.include Rack::Test::Methods
24
+
25
+ config.before(:suite) do
26
+ PID1 = fork do
27
+ $stdout = File.new('/dev/null', 'w')
28
+ File.open('test1.conf', 'w') { |f| f.write("port 6380\ndbfilename test1.rdb\nloglevel warning") }
29
+ exec 'redis-server test1.conf'
30
+ end
31
+ puts "PID1 is #{PID1}\n\n"
32
+ sleep(3)
33
+
34
+ clean_redis
35
+
36
+ config = { region: 'us-mockregion-1',
37
+ access_key_id: '...',
38
+ secret_access_key: '...' }
39
+
40
+ begin
41
+ Aws.config.update(config)
42
+ rescue NoMethodError
43
+ # aws-sdk is not imported in the project
44
+ end
45
+
46
+ begin
47
+ AWS.config(access_key_id: '...',
48
+ secret_access_key: '...',
49
+ region: 'us-mockregion-1')
50
+ rescue NoMethodError
51
+ # aws-sdk-v1 is not imported in the project
52
+ end
53
+ end
54
+
55
+ config.after(:suite) do
56
+ clean_redis
57
+
58
+ puts 'Killing redis-server'
59
+
60
+ STDOUT.flush
61
+ Process.kill('KILL', PID1)
62
+ FileUtils.rm 'test1.rdb' if File.exist?('test1.rdb')
63
+ FileUtils.rm 'test1.conf' if File.exist?('test1.conf')
64
+ Process.waitall
65
+ end
66
+ end
67
+
68
+ def clean_redis
69
+ raise 'cannot flush' unless ENV['RACK_ENV'] == 'test'
70
+ AWS_REDIS.flushdb
71
+ end
data/spec/sqs_spec.rb ADDED
@@ -0,0 +1,87 @@
1
+ $LOAD_PATH << "#{File.dirname(__FILE__)}/../"
2
+
3
+ require 'aws-sdk'
4
+ require 'aws-sdk-v1'
5
+ require 'spec/spec_helper'
6
+
7
+ describe 'Profiles Spec' do
8
+ include Rack::Test::Methods
9
+ def app
10
+ Sinatra::Application
11
+ end
12
+
13
+ it 'v1: should post to SQS okay' do
14
+ sqs = AWS::SQS.new
15
+
16
+ queue_name = 'http://sqs.us-mockregion-1.amazonaws.com/v1/test'
17
+ (1..5).each do |i|
18
+ sqs.queues.named(queue_name).send_message("test#{i}")
19
+ end
20
+
21
+ idx = 1
22
+ sqs.queues.named(queue_name).poll(idle_timeout: 3) do |msg|
23
+ expect(msg.body).to eq "test#{idx}"
24
+ msg.delete
25
+ idx += 1
26
+ break if idx > 5
27
+ end
28
+
29
+ sqs.queues.named(queue_name).send_message('test')
30
+
31
+ expect(sqs.queues.named(queue_name).approximate_number_of_messages).to eq 1
32
+ end
33
+
34
+ it 'v2: should post to SQS okay' do
35
+ old_blackout_time = SQS_DEFAULT_VISIBILITY_TIMEOUT
36
+ SQS_DEFAULT_VISIBILITY_TIMEOUT = 5
37
+
38
+ client = Aws::SQS::Client.new
39
+ resource = Aws::SQS::Resource.new(client: client)
40
+ queue =
41
+ resource.get_queue_by_name(
42
+ queue_name: 'http://sqs.us-mockregion-1.amazonaws.com/v2/test'
43
+ )
44
+
45
+ (1..5).each do |i|
46
+ queue.send_message(message_body: "test#{i}")
47
+ end
48
+
49
+ poller = Aws::SQS::QueuePoller.new(queue.url)
50
+
51
+ idx = 1
52
+ poller.poll(idle_timeout: 1) do |msg|
53
+ expect(msg.body).to eq "test#{idx}"
54
+ idx += 1
55
+ end
56
+
57
+ sent_msg = queue.send_message(message_body: 'test')
58
+ expect(queue.attributes['ApproximateNumberOfMessages'].to_i).to eq 1
59
+
60
+ poller.poll(idle_timeout: 1, skip_delete: true) do |msg|
61
+ expect(msg.body).to eq 'test'
62
+ expect(sent_msg.message_id).to eq msg.message_id
63
+ end
64
+
65
+ expect(queue.attributes['ApproximateNumberOfMessages'].to_i).to eq 1
66
+ sleep SQS_DEFAULT_VISIBILITY_TIMEOUT
67
+ queue =
68
+ resource.get_queue_by_name(
69
+ queue_name: 'http://sqs.us-mockregion-1.amazonaws.com/v2/test'
70
+ )
71
+ expect(queue.attributes['ApproximateNumberOfMessages'].to_i).to eq 1
72
+
73
+ poller.poll(idle_timeout: 1, skip_delete: true) do |msg|
74
+ expect(msg.body).to eq 'test'
75
+ expect(sent_msg.message_id).to eq msg.message_id
76
+ poller.delete_message(msg)
77
+ end
78
+
79
+ queue =
80
+ resource.get_queue_by_name(
81
+ queue_name: 'http://sqs.us-mockregion-1.amazonaws.com/v2/test'
82
+ )
83
+ expect(queue.attributes['ApproximateNumberOfMessages'].to_i).to eq 0
84
+
85
+ SQS_DEFAULT_VISIBILITY_TIMEOUT = old_blackout_time
86
+ end
87
+ end
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'aws-sdk-v1'
3
+ require 'aws-sdk'
4
+ require 'clientside_aws'
5
+ require 'pry'
6
+
7
+ ClientsideAws.configure do |config|
8
+ config.host = 'localhost'
9
+ config.port = 5567
10
+ end
11
+
12
+ config = { region: 'us-mockregion-1',
13
+ access_key_id: '...',
14
+ secret_access_key: '...' }
15
+
16
+ Aws.config.update(config)
17
+ AWS.config(config)
18
+
19
+
20
+ # s3 = Aws::S3::Client.new
21
+ # s3.create_bucket(bucket: 'test')
22
+
23
+ # bucket = Aws::S3::Resource.new.bucket('test')
24
+
25
+ # # Now, store a JSON document
26
+ # json_value = { foo: 'bar' }.to_json
27
+ # object = bucket.object('test.json')
28
+ # object.put(body: json_value, content_type: 'application/json')
29
+
30
+ # object = bucket.object('test.json')
31
+
32
+ # puts object.get.body.read
33
+
34
+ AWS::ElasticTranscoder::Client.new.create_pipeline(
35
+ name: 'SCRUFF_CHAT_VIDEO',
36
+ input_bucket: 'foo',
37
+ output_bucket: 'bar',
38
+ role: '...',
39
+ notifications: {
40
+ progressing: '',
41
+ completed: '',
42
+ warning: '',
43
+ error: '' })
44
+
45
+ puts "Done"
@@ -0,0 +1,138 @@
1
+
2
+ $LOAD_PATH << "#{File.dirname(__FILE__)}/../"
3
+
4
+ require 'spec/spec_helper'
5
+
6
+ describe 'Profiles Spec' do
7
+ include Rack::Test::Methods
8
+ def app
9
+ Sinatra::Application
10
+ end
11
+
12
+ it 'v1: should post to transcoder okay' do
13
+ guid = SecureRandom.hex(10)
14
+ video_file = File.new("#{File.dirname(__FILE__)}" \
15
+ '/../public/images/stock_video.mp4')
16
+
17
+ s3 = AWS::S3.new
18
+ s3.buckets.create('test')
19
+ bucket = s3.buckets['test']
20
+ expect(bucket.exists?).to be true
21
+ object = bucket.objects["#{guid}-video"]
22
+ object.write(file: video_file)
23
+
24
+ expect(AWS_REDIS.exists("s3:bucket:#{bucket.name}:#{guid}-video"))\
25
+ .to be true
26
+ object = bucket.objects["#{guid}-video"]
27
+ expect(object.exists?).to be true
28
+ expect(object.content_length).to be > 0
29
+
30
+ transcoder = AWS::ElasticTranscoder::Client.new
31
+
32
+ pipeline_name = 'SCRUFF'
33
+ input_bucket = 'test'
34
+ output_bucket = 'test'
35
+
36
+ pipeline_response = transcoder.create_pipeline(
37
+ name: pipeline_name,
38
+ input_bucket: input_bucket,
39
+ output_bucket: output_bucket,
40
+ role: '...',
41
+ notifications: {
42
+ progressing: '',
43
+ completed: '',
44
+ warning: '',
45
+ error: ''
46
+ }
47
+ )
48
+ expect(last_response.ok?).to be true
49
+
50
+ pipeline = pipeline_response.pipeline
51
+ expect(pipeline.name).to eq pipeline_name
52
+ expect(pipeline.input_bucket).to eq input_bucket
53
+ expect(pipeline.output_bucket).to eq output_bucket
54
+
55
+ transcoder.create_job(
56
+ pipeline_id: pipeline.id,
57
+ input: { key: "#{guid}-video",
58
+ frame_rate: 'auto',
59
+ resolution: 'auto',
60
+ aspect_ratio: 'auto',
61
+ interlaced: 'auto',
62
+ container: 'auto' },
63
+ output: { key: "#{guid}-video-encoded",
64
+ thumbnail_pattern: '',
65
+ rotate: 'auto',
66
+ preset_id: 'fake-preset' }
67
+ )
68
+ expect(last_response.ok?).to be true
69
+
70
+ expect(bucket.objects["#{guid}-video-encoded"].exists?).to be true
71
+ expect(bucket.objects["#{guid}-video-encoded"].content_length).to be > 0
72
+ end
73
+
74
+ it 'v2: should post to transcoder okay' do
75
+ guid = SecureRandom.hex(10)
76
+ video_file = File.new("#{File.dirname(__FILE__)}" \
77
+ '/../public/images/stock_video.mp4')
78
+
79
+ s3 = Aws::S3::Client.new
80
+ s3.create_bucket(bucket: 'test')
81
+
82
+ bucket = Aws::S3::Resource.new.bucket('test')
83
+ expect(bucket.exists?).to be true
84
+
85
+ s3.put_object(bucket: 'test',
86
+ key: "#{guid}-video",
87
+ body: video_file)
88
+
89
+ expect(AWS_REDIS.exists("s3:bucket:#{bucket.name}:#{guid}-video"))\
90
+ .to be true
91
+ object = bucket.object("#{guid}-video")
92
+ expect(object.exists?).to be true
93
+ expect(object.content_length).to be > 0
94
+
95
+ transcoder = Aws::ElasticTranscoder::Client.new
96
+
97
+ pipeline_name = 'SCRUFF'
98
+ input_bucket = 'test'
99
+ output_bucket = 'test'
100
+
101
+ pipeline_response = transcoder.create_pipeline(
102
+ name: pipeline_name,
103
+ input_bucket: input_bucket,
104
+ output_bucket: output_bucket,
105
+ role: '...',
106
+ notifications: {
107
+ progressing: '',
108
+ completed: '',
109
+ warning: '',
110
+ error: ''
111
+ }
112
+ )
113
+ expect(last_response.ok?).to be true
114
+
115
+ pipeline = pipeline_response.pipeline
116
+ expect(pipeline.name).to eq pipeline_name
117
+ expect(pipeline.input_bucket).to eq input_bucket
118
+ expect(pipeline.output_bucket).to eq output_bucket
119
+
120
+ transcoder.create_job(
121
+ pipeline_id: pipeline.id,
122
+ input: { key: "#{guid}-video",
123
+ frame_rate: 'auto',
124
+ resolution: 'auto',
125
+ aspect_ratio: 'auto',
126
+ interlaced: 'auto',
127
+ container: 'auto' },
128
+ output: { key: "#{guid}-video-encoded",
129
+ thumbnail_pattern: '',
130
+ rotate: 'auto',
131
+ preset_id: 'fake-preset' }
132
+ )
133
+ expect(last_response.ok?).to be true
134
+
135
+ expect(bucket.object("#{guid}-video-encoded").exists?).to be true
136
+ expect(bucket.object("#{guid}-video-encoded").content_length).to be > 0
137
+ end
138
+ end
metadata ADDED
@@ -0,0 +1,241 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: clientside_aws
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.17
5
+ platform: ruby
6
+ authors:
7
+ - Perry Street Software, Inc.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 10.1.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 10.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack-test
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.5.7
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.5.7
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 2.14.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 2.14.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: aws-sdk-v1
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 1.59.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 1.59.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: aws-sdk
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: builder
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 3.1.4
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 3.1.4
111
+ - !ruby/object:Gem::Dependency
112
+ name: httparty
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 0.11.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 0.11.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: json
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.8'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.8'
139
+ - !ruby/object:Gem::Dependency
140
+ name: webmock
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '='
144
+ - !ruby/object:Gem::Version
145
+ version: 3.1.0
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '='
151
+ - !ruby/object:Gem::Version
152
+ version: 3.1.0
153
+ description: This code is meant to be used by developers who are attempting to build
154
+ web applications on AWS but wish to run client-side testing and validation.
155
+ email:
156
+ - noreply@scruff.com
157
+ executables:
158
+ - clientside_aws_build
159
+ - clientside_aws_run
160
+ extensions: []
161
+ extra_rdoc_files: []
162
+ files:
163
+ - ".gitignore"
164
+ - Dockerfile
165
+ - Gemfile
166
+ - Gemfile.lock
167
+ - README.md
168
+ - bin/clientside_aws_build
169
+ - bin/clientside_aws_run
170
+ - bin/clientside_aws_test
171
+ - clientside_aws.gemspec
172
+ - clientside_aws/dynamodb.rb
173
+ - clientside_aws/ec2.rb
174
+ - clientside_aws/elastic_transcoder.rb
175
+ - clientside_aws/firehose.rb
176
+ - clientside_aws/kinesis.rb
177
+ - clientside_aws/mock/core.rb
178
+ - clientside_aws/mock/firehose.rb
179
+ - clientside_aws/mock/kinesis.rb
180
+ - clientside_aws/mock/s3.rb
181
+ - clientside_aws/mock/ses.rb
182
+ - clientside_aws/mock/sns.rb
183
+ - clientside_aws/s3.rb
184
+ - clientside_aws/ses.rb
185
+ - clientside_aws/sns.rb
186
+ - clientside_aws/sqs.rb
187
+ - docker/clientside-aws-run
188
+ - docker/redis-server-run
189
+ - index.rb
190
+ - lib/clientside_aws.rb
191
+ - lib/clientside_aws/configuration.rb
192
+ - lib/clientside_aws/mock.rb
193
+ - lib/clientside_aws/version.rb
194
+ - public/images/jscruff.jpg
195
+ - public/images/spacer.gif
196
+ - public/images/stock_video.mp4
197
+ - spec/dynamodb_spec.rb
198
+ - spec/ec2_spec.rb
199
+ - spec/firehose_spec.rb
200
+ - spec/kinesis_spec.rb
201
+ - spec/s3_spec.rb
202
+ - spec/sns_spec.rb
203
+ - spec/spec_helper.rb
204
+ - spec/sqs_spec.rb
205
+ - spec/test_client/test.rb
206
+ - spec/transcoder_spec.rb
207
+ homepage: https://github.com/perrystreetsoftware/clientside_aws
208
+ licenses:
209
+ - MIT
210
+ metadata: {}
211
+ post_install_message:
212
+ rdoc_options: []
213
+ require_paths:
214
+ - lib
215
+ required_ruby_version: !ruby/object:Gem::Requirement
216
+ requirements:
217
+ - - ">="
218
+ - !ruby/object:Gem::Version
219
+ version: '0'
220
+ required_rubygems_version: !ruby/object:Gem::Requirement
221
+ requirements:
222
+ - - ">="
223
+ - !ruby/object:Gem::Version
224
+ version: '0'
225
+ requirements: []
226
+ rubyforge_project:
227
+ rubygems_version: 2.5.1
228
+ signing_key:
229
+ specification_version: 4
230
+ summary: Select AWS Services Replicated on Your Client
231
+ test_files:
232
+ - spec/dynamodb_spec.rb
233
+ - spec/ec2_spec.rb
234
+ - spec/firehose_spec.rb
235
+ - spec/kinesis_spec.rb
236
+ - spec/s3_spec.rb
237
+ - spec/sns_spec.rb
238
+ - spec/spec_helper.rb
239
+ - spec/sqs_spec.rb
240
+ - spec/test_client/test.rb
241
+ - spec/transcoder_spec.rb