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
data/spec/ec2_spec.rb ADDED
@@ -0,0 +1,138 @@
1
+ $LOAD_PATH << "#{File.dirname(__FILE__)}/../"
2
+
3
+ require 'spec/spec_helper'
4
+
5
+ describe 'EC2 Spec' do
6
+ include Rack::Test::Methods
7
+ def app
8
+ Sinatra::Application
9
+ end
10
+
11
+ def build_ec2_args(security_group:, remote_addr:, mask:, port:)
12
+ args = { group_id: security_group }
13
+ if remote_addr =~ /\:/ && remote_addr.length >= 16
14
+ args[:ip_permissions] = [{
15
+ from_port: port,
16
+ to_port: port,
17
+ ip_protocol: 'tcp',
18
+ ipv_6_ranges: [{ cidr_ipv_6: "#{remote_addr}/#{mask}" }]
19
+ }]
20
+ else
21
+ args[:ip_permissions] = [{
22
+ from_port: port,
23
+ to_port: port,
24
+ ip_protocol: 'tcp',
25
+ ip_ranges: [{ cidr_ip: "#{remote_addr}/#{mask}" }]
26
+ }]
27
+ end
28
+
29
+ args
30
+ end
31
+
32
+ it 'should create ingress groups' do
33
+ ec2 = Aws::EC2::Client.new
34
+
35
+ args = build_ec2_args(
36
+ security_group: 'sg-foo',
37
+ remote_addr: '192.168.99.100',
38
+ mask: 24,
39
+ port: 443
40
+ )
41
+ ec2.authorize_security_group_ingress(args)
42
+
43
+ desc = ec2.describe_security_groups(
44
+ group_ids: ['sg-foo']
45
+ )
46
+ expect(desc.security_groups.length).to eq 1
47
+ count_of_ip_ranges = \
48
+ desc&.security_groups&.first&.ip_permissions&.first&.ip_ranges&.length
49
+ expect(count_of_ip_ranges).to eq 1
50
+
51
+ first_ip_range = \
52
+ desc&.security_groups&.first&.ip_permissions&.first&.ip_ranges&.first
53
+ expect(first_ip_range.cidr_ip).to eq '192.168.99.0/24'
54
+
55
+ args = build_ec2_args(
56
+ security_group: 'sg-foo',
57
+ remote_addr: '192.168.99.0',
58
+ mask: 24,
59
+ port: 443
60
+ )
61
+
62
+ ec2.revoke_security_group_ingress(args)
63
+
64
+ desc = ec2.describe_security_groups(
65
+ group_ids: ['sg-foo']
66
+ )
67
+
68
+ expect(desc.security_groups.first.ip_permissions.first).to be nil
69
+ end
70
+
71
+ it 'should create ingress groups on different ports' do
72
+ ec2 = Aws::EC2::Client.new
73
+
74
+ args = build_ec2_args(
75
+ security_group: 'sg-foo2',
76
+ remote_addr: '192.168.99.101',
77
+ mask: 16,
78
+ port: 22
79
+ )
80
+
81
+ ec2.authorize_security_group_ingress(args)
82
+
83
+ args = build_ec2_args(
84
+ security_group: 'sg-foo2',
85
+ remote_addr: '10.0.0.1',
86
+ mask: 32,
87
+ port: 22
88
+ )
89
+
90
+ ec2.authorize_security_group_ingress(args)
91
+
92
+ desc = ec2.describe_security_groups(
93
+ group_ids: ['sg-foo2']
94
+ )
95
+
96
+ ip_ranges = \
97
+ desc.security_groups.first.ip_permissions.first.ip_ranges.map(&:cidr_ip)
98
+
99
+ expect(ip_ranges.include?('10.0.0.1/32')).to be true
100
+ expect(ip_ranges.include?('192.168.0.0/16')).to be true
101
+
102
+ args = build_ec2_args(
103
+ security_group: 'sg-foo2',
104
+ remote_addr: '10.0.0.1',
105
+ mask: 32,
106
+ port: 22
107
+ )
108
+
109
+ ec2.revoke_security_group_ingress(args)
110
+
111
+ desc = ec2.describe_security_groups(
112
+ group_ids: ['sg-foo2']
113
+ )
114
+
115
+ ip_ranges = \
116
+ desc.security_groups.first.ip_permissions.first.ip_ranges.map(&:cidr_ip)
117
+
118
+ expect(ip_ranges.include?('10.0.0.1/32')).to be false
119
+ expect(ip_ranges.include?('192.168.0.0/16')).to be true
120
+
121
+ args = build_ec2_args(
122
+ security_group: 'sg-foo2',
123
+ remote_addr: '192.168.0.0',
124
+ mask: 16,
125
+ port: 22
126
+ )
127
+
128
+ ec2.revoke_security_group_ingress(args)
129
+
130
+ desc = ec2.describe_security_groups(
131
+ group_ids: ['sg-foo2']
132
+ )
133
+
134
+ ip_ranges = \
135
+ desc.security_groups.first.ip_permissions
136
+ expect(ip_ranges.length.zero?).to be true
137
+ end
138
+ end
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH << "#{File.dirname(__FILE__)}/../"
2
+
3
+ require 'spec/spec_helper'
4
+
5
+ describe 'Profiles Spec' do
6
+ include Rack::Test::Methods
7
+ def app
8
+ Sinatra::Application
9
+ end
10
+
11
+ it 'should post to Firehose okay' do
12
+ firehose = Aws::Firehose::Client.new
13
+ firehose.put_record_batch(delivery_stream_name: 'test',
14
+ records: [{ data: 'foo' }, { data: 'bar' }])
15
+ end
16
+ end
@@ -0,0 +1,22 @@
1
+ $LOAD_PATH << "#{File.dirname(__FILE__)}/../"
2
+
3
+ require 'spec/spec_helper'
4
+
5
+ describe 'Profiles Spec' do
6
+ include Rack::Test::Methods
7
+ def app
8
+ Sinatra::Application
9
+ end
10
+
11
+ it 'v1: should post to Kinesis okay' do
12
+ AWS::Kinesis::Client.new.put_record(stream_name: 'foo',
13
+ data: { bar: 1 }.to_json,
14
+ partition_key: 1.to_s)
15
+ end
16
+
17
+ it 'v2: should post to Kinesis okay' do
18
+ Aws::Kinesis::Client.new.put_record(stream_name: 'foo',
19
+ data: { bar: 1 }.to_json,
20
+ partition_key: 1.to_s)
21
+ end
22
+ end
data/spec/s3_spec.rb ADDED
@@ -0,0 +1,219 @@
1
+ $LOAD_PATH << "#{File.dirname(__FILE__)}/../"
2
+
3
+ require 'spec/spec_helper'
4
+
5
+ describe 'Profiles Spec' do
6
+ include Rack::Test::Methods
7
+ def app
8
+ Sinatra::Application
9
+ end
10
+ # adding in for ability to access via other 'examples'
11
+
12
+ it 'says hello' do
13
+ get '/'
14
+ expect(last_response.ok?).to be true
15
+ end
16
+
17
+ it 'v1: should post to S3 okay' do
18
+ s3 = AWS::S3.new
19
+ s3.buckets.create('test')
20
+ bucket = s3.buckets['test']
21
+ expect(bucket.exists?).to be true
22
+ object = bucket.objects['test.file']
23
+
24
+ initial_hash = \
25
+ Digest::MD5.hexdigest(File.read("#{File.dirname(__FILE__)}" \
26
+ '/../public/images/spacer.gif'))
27
+
28
+ object.write(file: "#{File.dirname(__FILE__)}/../public/images/spacer.gif")
29
+ expect(Digest::MD5.hexdigest(object.read)).to eq initial_hash
30
+ expect(object.exists?).to be true
31
+
32
+ expect(bucket.objects['asdfdsfasdf'].exists?).to be false
33
+
34
+ object.delete
35
+ expect(object.exists?).to be false
36
+
37
+ json_value = { foo: 'bar' }.to_json
38
+ object = bucket.objects['test.json']
39
+ object.write(json_value, content_type: 'application/json')
40
+ expect(object.read).to eq json_value
41
+ expect(object.content_type).to eq 'application/json'
42
+ expect(object.etag).to eq Digest::MD5.hexdigest(json_value)
43
+ end
44
+
45
+ it 'v2: should post to S3 okay' do
46
+ s3 = Aws::S3::Client.new
47
+ s3.create_bucket(bucket: 'test')
48
+
49
+ bucket = Aws::S3::Resource.new.bucket('test')
50
+ expect(bucket.exists?).to be true
51
+
52
+ s3.put_object(bucket: 'test',
53
+ key: 'test.file',
54
+ body: File.new("#{File.dirname(__FILE__)}" \
55
+ '/../public/images/spacer.gif'))
56
+ initial_hash = \
57
+ Digest::MD5.hexdigest(File.read("#{File.dirname(__FILE__)}" \
58
+ '/../public/images/spacer.gif'))
59
+
60
+ bucket = Aws::S3::Resource.new.bucket('test')
61
+ object = bucket.object('test.file')
62
+ expect(Digest::MD5.hexdigest(object.get.body.read)).to eq initial_hash
63
+
64
+ expect(object.exists?).to be true
65
+
66
+ # expect(bucket.objects['asdfdsfasdf'].exists?).to be false
67
+
68
+ object.delete
69
+ object = bucket.object('test.file')
70
+
71
+ expect(object.exists?).to be false
72
+ end
73
+
74
+ it 'v2: stores JSON document' do
75
+ s3 = Aws::S3::Client.new
76
+ s3.create_bucket(bucket: 'test')
77
+
78
+ bucket = Aws::S3::Resource.new.bucket('test')
79
+ expect(bucket.exists?).to be true
80
+
81
+ # Now, store a JSON document
82
+ json_value = { foo: 'bar' }.to_json
83
+ object = bucket.object('test.json')
84
+ object.put(body: json_value, content_type: 'application/json')
85
+
86
+ object = bucket.object('test.json')
87
+ expect(object.get.body.read).to eq json_value
88
+ expect(object.content_type).to eq 'application/json'
89
+ expect(object.etag).to eq Digest::MD5.hexdigest(json_value)
90
+ end
91
+
92
+ it 'v1: should support subpaths' do
93
+ s3 = AWS::S3.new
94
+ s3.buckets.create('test')
95
+ bucket = s3.buckets[:test]
96
+ expect(bucket.exists?).to be true
97
+ object = bucket.objects['foo/bar/test.file']
98
+
99
+ object.write(file: "#{File.dirname(__FILE__)}/../public/images/spacer.gif")
100
+ expect(object.exists?).to be true
101
+
102
+ s3_object = object.read
103
+ expect(s3_object.length).to eq 43
104
+ end
105
+
106
+ it 'v2: should support subpaths' do
107
+ s3 = Aws::S3::Client.new
108
+
109
+ s3.create_bucket(bucket: 'test')
110
+ bucket = Aws::S3::Resource.new.bucket('test')
111
+ expect(bucket.exists?).to be true
112
+ object = bucket.object('foo/bar/test.file')
113
+
114
+ object.put(body: File.new("#{File.dirname(__FILE__)}" \
115
+ '/../public/images/spacer.gif'))
116
+ expect(object.exists?).to be true
117
+
118
+ gif_content = object.get.body.read
119
+ expect(gif_content.length).to eq 43
120
+ end
121
+
122
+ it 'v1: should support rename_to' do
123
+ s3 = AWS::S3.new
124
+ s3.buckets.create('test1')
125
+ bucket = s3.buckets[:test]
126
+ expect(bucket.exists?).to be true
127
+ object = bucket.objects['test1_v1.file']
128
+
129
+ initial_hash = Digest::MD5.hexdigest(File.read("#{File.dirname(__FILE__)}/../public/images/spacer.gif"))
130
+ object.write(file: "#{File.dirname(__FILE__)}/../public/images/spacer.gif")
131
+ expect(Digest::MD5.hexdigest(object.read)).to eq initial_hash
132
+ expect(object.exists?).to be true
133
+
134
+ object.rename_to('test2_v1.file')
135
+
136
+ renamed_object = bucket.objects['test2_v1.file']
137
+ expect(renamed_object.exists?).to be true
138
+ expect(renamed_object.read.nil?).to be false
139
+ end
140
+
141
+ it 'v2: should support rename_to' do
142
+ s3 = Aws::S3::Client.new
143
+
144
+ s3.create_bucket(bucket: 'test')
145
+ bucket = Aws::S3::Resource.new.bucket('test')
146
+ expect(bucket.exists?).to be true
147
+
148
+ object = bucket.object('test_v2.file')
149
+ object.put(body: File.new("#{File.dirname(__FILE__)}" \
150
+ '/../public/images/spacer.gif'))
151
+
152
+ object2 = bucket.object('test2_v2.file')
153
+ expect(object2.exists?).to be false
154
+ object.move_to(object2)
155
+ expect(object2.exists?).to be true
156
+ expect(object.exists?).to be false
157
+ end
158
+
159
+ it 'v1: should list' do
160
+ s3 = AWS::S3.new
161
+ bucket_name = SecureRandom.hex(10)
162
+ s3.buckets.create(bucket_name)
163
+ bucket = s3.buckets[bucket_name]
164
+ expect(bucket.exists?).to be true
165
+ object = bucket.objects['test.file']
166
+ object.write(file: "#{File.dirname(__FILE__)}/../public/images/spacer.gif")
167
+
168
+ expect(bucket.objects.count).to eq 1
169
+ end
170
+
171
+ it 'v2: should list' do
172
+ s3 = Aws::S3::Client.new
173
+
174
+ bucket_name = SecureRandom.hex(10)
175
+ s3.create_bucket(bucket: bucket_name)
176
+ bucket = Aws::S3::Resource.new.bucket(bucket_name)
177
+ expect(bucket.exists?).to be true
178
+
179
+ object = bucket.object('test.file')
180
+ object.put(body: File.new("#{File.dirname(__FILE__)}" \
181
+ '/../public/images/spacer.gif'))
182
+
183
+ expect(bucket.objects.count).to eq 1
184
+ end
185
+
186
+ it 'v1: should respect prefix' do
187
+ s3 = AWS::S3.new
188
+ bucket_name = SecureRandom.hex(10)
189
+ s3.buckets.create(bucket_name)
190
+ bucket = s3.buckets[bucket_name]
191
+ expect(bucket.exists?).to be true
192
+ object = bucket.objects['apple.gif']
193
+ object.write(file: "#{File.dirname(__FILE__)}/../public/images/spacer.gif")
194
+
195
+ object = bucket.objects['banana.gif']
196
+ object.write(file: "#{File.dirname(__FILE__)}/../public/images/spacer.gif")
197
+
198
+ expect(bucket.objects.with_prefix('apple').count).to eq 1
199
+ end
200
+
201
+ it 'v2: should respect prefix' do
202
+ s3 = Aws::S3::Client.new
203
+
204
+ bucket_name = SecureRandom.hex(10)
205
+ s3.create_bucket(bucket: bucket_name)
206
+ bucket = Aws::S3::Resource.new.bucket(bucket_name)
207
+ expect(bucket.exists?).to be true
208
+
209
+ object = bucket.object('apple.gif')
210
+ object.put(body: File.new("#{File.dirname(__FILE__)}" \
211
+ '/../public/images/spacer.gif'))
212
+
213
+ object = bucket.object('banana.gif')
214
+ object.put(body: File.new("#{File.dirname(__FILE__)}" \
215
+ '/../public/images/spacer.gif'))
216
+
217
+ expect(bucket.objects(prefix: 'apple').count).to eq 1
218
+ end
219
+ end
data/spec/sns_spec.rb ADDED
@@ -0,0 +1,72 @@
1
+ $LOAD_PATH << "#{File.dirname(__FILE__)}/../"
2
+
3
+ require 'spec/spec_helper'
4
+
5
+ describe 'Profiles Spec' do
6
+ include Rack::Test::Methods
7
+ def app
8
+ Sinatra::Application
9
+ end
10
+ # adding in for ability to access via other 'examples'
11
+
12
+ it 'says hello' do
13
+ get '/'
14
+ expect(last_response).to be_ok
15
+ end
16
+
17
+ it 'v1: should post to SNS okay' do
18
+ sns = AWS::SNS.new
19
+
20
+ response = sns.client.create_platform_endpoint(
21
+ platform_application_arn: \
22
+ 'arn:aws:sns:us-east-1:999999999999:app/APNS/MYAPP',
23
+ token: 'token'
24
+ )
25
+ expect(response.data[:endpoint_arn]).not_to be_nil
26
+ expect(response.data[:endpoint_arn] =~ %r{endpoint/APNS}).not_to be nil
27
+
28
+ response = sns.client.create_platform_endpoint(
29
+ platform_application_arn: \
30
+ 'arn:aws:sns:us-east-1:999999999999:app/WNS/MYAPP',
31
+ token: 'token'
32
+ )
33
+ expect(response.data[:endpoint_arn]).not_to be_nil
34
+ expect(response.data[:endpoint_arn] =~ %r{endpoint/WNS}).not_to be nil
35
+
36
+ response = sns.client.create_platform_endpoint(
37
+ platform_application_arn: \
38
+ 'arn:aws:sns:us-east-1:999999999999:app/GCM/MYAPP',
39
+ token: 'token'
40
+ )
41
+ expect(response.data[:endpoint_arn]).not_to be_nil
42
+ expect(response.data[:endpoint_arn] =~ %r{endpoint/GCM}).not_to be nil
43
+ end
44
+
45
+ it 'v2: should post to SNS okay' do
46
+ sns_client = Aws::SNS::Client.new
47
+
48
+ response = sns_client.create_platform_endpoint(
49
+ platform_application_arn: \
50
+ 'arn:aws:sns:us-east-1:999999999999:app/APNS/MYAPP',
51
+ token: 'token'
52
+ )
53
+ expect(response.data[:endpoint_arn]).not_to be_nil
54
+ expect(response.data[:endpoint_arn] =~ %r{endpoint/APNS}).not_to be nil
55
+
56
+ response = sns_client.create_platform_endpoint(
57
+ platform_application_arn: \
58
+ 'arn:aws:sns:us-east-1:999999999999:app/WNS/MYAPP',
59
+ token: 'token'
60
+ )
61
+ expect(response.data[:endpoint_arn]).not_to be_nil
62
+ expect(response.data[:endpoint_arn] =~ %r{endpoint/WNS}).not_to be nil
63
+
64
+ response = sns_client.create_platform_endpoint(
65
+ platform_application_arn: \
66
+ 'arn:aws:sns:us-east-1:999999999999:app/GCM/MYAPP',
67
+ token: 'token'
68
+ )
69
+ expect(response.data[:endpoint_arn]).not_to be_nil
70
+ expect(response.data[:endpoint_arn] =~ %r{endpoint/GCM}).not_to be nil
71
+ end
72
+ end