cloud_powers 0.2.6 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/cloud_powers.gemspec +4 -1
- data/lib/cloud_powers.rb +0 -1
- data/lib/cloud_powers/aws_resources.rb +132 -1
- data/lib/cloud_powers/helper.rb +1 -0
- data/lib/cloud_powers/node.rb +2 -0
- data/lib/cloud_powers/self_awareness.rb +1 -1
- data/lib/cloud_powers/synapse/broadcast/broadcast.rb +6 -6
- data/lib/cloud_powers/synapse/pipe/pipe.rb +14 -13
- data/lib/cloud_powers/synapse/synapse.rb +1 -1
- data/lib/cloud_powers/version.rb +1 -1
- data/lib/stubs/aws_stubs.rb +169 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87b0d2d0b422a079bb6f136b7629e583ebaeb88e
|
4
|
+
data.tar.gz: 5f4313c4ca1aab96ef5550e1f5048a43900f6b4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa4816ebb01b5457e2dea8ea60914c08eb34cb0be5b88df46c301b6c146e6ef2954f676746d19600f05558e439a97f6cb00509fc31072e031b522017cf2d6fd5
|
7
|
+
data.tar.gz: fee80d3368a5dcc9acacb7ebf2924e1be611c07daa6204b0984208c480e4881ca32b6fc71998c150032807bd9fab39e96b0e05c7982ad8fb2377fcb0f36b0d2f
|
data/Gemfile.lock
CHANGED
data/cloud_powers.gemspec
CHANGED
@@ -14,11 +14,14 @@ Gem::Specification.new do |spec|
|
|
14
14
|
CloudPowers is a wrapper around AWS and in the future, other cloud service Providers.
|
15
15
|
It was developed specifically for the Brain project but hopefully can be used
|
16
16
|
in any other ruby project that needs to use cloud service providers' resources.
|
17
|
-
|
17
|
+
|
18
|
+
Version 0.2.7 has a little EC2, S3, SQS, SNS, Kinesis, websockets and a few other
|
18
19
|
features you can find in the docs. There is also limitted support for stubbing
|
19
20
|
AWS RESTful API calls. That can come in handy for local testing and extra setup on
|
20
21
|
AWS resource clients.
|
22
|
+
|
21
23
|
The next versions will have more Kinesis, Workflow integration and IoT.
|
24
|
+
|
22
25
|
This project is actively being developed, so more additions, specs and docs
|
23
26
|
will be added and updated frequently with new funcionality but the gem will
|
24
27
|
follow good practices for versioning. Input is always welcome.
|
data/lib/cloud_powers.rb
CHANGED
@@ -9,10 +9,42 @@ module Smash
|
|
9
9
|
include Smash::CloudPowers::Helper
|
10
10
|
include Smash::CloudPowers::Zenv
|
11
11
|
|
12
|
+
# Get the region from the environment/context or use a default region for AWS API calls.
|
13
|
+
# === @returns String
|
12
14
|
def region
|
13
15
|
zfind(:aws_region) || 'us-west-2'
|
14
16
|
end
|
15
17
|
|
18
|
+
# Get or create an EC2 client and cache that client so that a Context is more well tied together
|
19
|
+
# === @params: opts [Hash]
|
20
|
+
# * stub_responses: defaulted to false but it can be overriden with the desired responses for local testing
|
21
|
+
# * region: defaulted to use the `#region()` method
|
22
|
+
# * AWS::Credentials object, which will also scour the context and environment for your keys
|
23
|
+
# === @returns: AWS::EC2 client
|
24
|
+
# === Sample Usage
|
25
|
+
# ```
|
26
|
+
# config = stub_responses: {
|
27
|
+
# run_instances: {
|
28
|
+
# instances: [
|
29
|
+
# { instance_id: 'asd-1234', launch_time: Time.now, state: { name: 'running' }
|
30
|
+
# ] }
|
31
|
+
# describe_instances: {
|
32
|
+
# reservations: [
|
33
|
+
# { instances: [
|
34
|
+
# { instance_id: 'asd-1234', state: { code: 200, name: 'running' } },
|
35
|
+
# ] }] },
|
36
|
+
# describe_images: {
|
37
|
+
# images: [
|
38
|
+
# { image_id: 'asdf', state: 'available' }
|
39
|
+
# ] }
|
40
|
+
# }
|
41
|
+
#
|
42
|
+
# ec2(config) # sets and gets an EC2 client
|
43
|
+
#
|
44
|
+
# images = ec2.describe_images
|
45
|
+
# images.first[:image_id]
|
46
|
+
# # => 'asdf'
|
47
|
+
# ```
|
16
48
|
def ec2(opts = {})
|
17
49
|
config = {
|
18
50
|
stub_responses: false,
|
@@ -24,6 +56,14 @@ module Smash
|
|
24
56
|
@ec2 ||= Aws::EC2::Client.new(config)
|
25
57
|
end
|
26
58
|
|
59
|
+
# Get an image using a name and filters functionality from EC2. The name is required but the filter defaults
|
60
|
+
# to search for the tag with the key `aminame` because this is the key that most Nodes will search for, when
|
61
|
+
# they gather an AMI to start with.
|
62
|
+
# === @params: opts [Hash]
|
63
|
+
# * stub_responses: defaulted to false but it can be overriden with the desired responses for local testing
|
64
|
+
# * region: defaulted to use the `#region()` method
|
65
|
+
# * AWS::Credentials object, which will also scour the context and environment for your keys
|
66
|
+
# === @returns: AMI
|
27
67
|
def image(name, opts = {})
|
28
68
|
config = {
|
29
69
|
filters: [{ name: 'tag:aminame', values: [name.to_s] }]
|
@@ -33,6 +73,37 @@ module Smash
|
|
33
73
|
ec2(opts).describe_images(config).images.first
|
34
74
|
end
|
35
75
|
|
76
|
+
# Get or create an Kinesis client and cache that client so that a Context is more well tied together
|
77
|
+
# === @params: opts [Hash]
|
78
|
+
# * stub_responses: defaulted to false but it can be overriden with the desired responses for local testing
|
79
|
+
# * region: defaulted to use the `#region()` method
|
80
|
+
# * AWS::Credentials object, which will also scour the context and environment for your keys
|
81
|
+
# === @returns: AWS::Kinesis client
|
82
|
+
# === Sample Usage
|
83
|
+
# ```
|
84
|
+
# config = {
|
85
|
+
# stub_responses: {
|
86
|
+
# create_stream: {},
|
87
|
+
# put_record: {
|
88
|
+
# shard_id: opts[:shard_id] || 'idididididididid',
|
89
|
+
# sequence_number: opts[:sequence_number] || Time.now.to_i.to_s
|
90
|
+
# },
|
91
|
+
# describe_stream: {
|
92
|
+
# stream_description: {
|
93
|
+
# stream_name: opts[:name] || 'somePipe',
|
94
|
+
# stream_arn: 'arnarnarnarnar',
|
95
|
+
# stream_status: 'ACTIVE',
|
96
|
+
# }
|
97
|
+
# }
|
98
|
+
# }
|
99
|
+
# }
|
100
|
+
# }
|
101
|
+
#
|
102
|
+
# kinesis(config) # sets and gets an Kinesis client
|
103
|
+
#
|
104
|
+
# pipe_to('somePipe') { update_body(status: 'waHoo') }
|
105
|
+
# # => sequence_number: '1676151970'
|
106
|
+
# ```
|
36
107
|
def kinesis(opts = {})
|
37
108
|
config = {
|
38
109
|
stub_responses: false,
|
@@ -44,6 +115,22 @@ module Smash
|
|
44
115
|
@kinesis ||= Aws::Kinesis::Client.new(config)
|
45
116
|
end
|
46
117
|
|
118
|
+
# Get or create an S3 client and cache that client so that a Context is more well tied together
|
119
|
+
# === @params: opts [Hash]
|
120
|
+
# * stub_responses: defaulted to false but it can be overriden with the desired responses for local testing
|
121
|
+
# * region: defaulted to use the `#region()` method
|
122
|
+
# * AWS::Credentials object, which will also scour the context and environment for your keys
|
123
|
+
# === @returns: AWS::S3 client
|
124
|
+
# === Sample Usage
|
125
|
+
# ```
|
126
|
+
# config = {
|
127
|
+
# stub_responses: {
|
128
|
+
#
|
129
|
+
# }
|
130
|
+
# }
|
131
|
+
#
|
132
|
+
# ```
|
133
|
+
|
47
134
|
def s3(opts = {})
|
48
135
|
config = {
|
49
136
|
stub_responses: false,
|
@@ -55,6 +142,29 @@ module Smash
|
|
55
142
|
@s3 ||= Aws::S3::Client.new(config)
|
56
143
|
end
|
57
144
|
|
145
|
+
# Get or create an SNS client and cache that client so that a Context is more well tied together
|
146
|
+
# === @params: opts [Hash]
|
147
|
+
# * stub_responses: defaulted to false but it can be overriden with the desired responses for local testing
|
148
|
+
# * region: defaulted to use the `#region()` method
|
149
|
+
# * AWS::Credentials object, which will also scour the context and environment for your keys
|
150
|
+
# === @returns: AWS::SNS client
|
151
|
+
# === Sample Usage
|
152
|
+
# ```
|
153
|
+
# config = {
|
154
|
+
# stub_responses: {
|
155
|
+
# create_topic: {},
|
156
|
+
# delete_topic: {},
|
157
|
+
# list_topics: [],
|
158
|
+
# publish: {},
|
159
|
+
# subscribe: {}
|
160
|
+
# }
|
161
|
+
# }
|
162
|
+
#
|
163
|
+
# sns(config) # sets and gets an Kinesis client
|
164
|
+
#
|
165
|
+
# create_channel!('testBroadcast')
|
166
|
+
# # => true
|
167
|
+
# ```
|
58
168
|
def sns(opts = {})
|
59
169
|
config = {
|
60
170
|
stub_responses: false,
|
@@ -66,10 +176,31 @@ module Smash
|
|
66
176
|
@sns ||= Aws::SNS::Client.new(config)
|
67
177
|
end
|
68
178
|
|
179
|
+
# Get or create an SQS client and cache that client so that a Context is more well tied together
|
180
|
+
# === @params: opts [Hash]
|
181
|
+
# * stub_responses: defaulted to false but it can be overriden with the desired responses for local testing
|
182
|
+
# * region: defaulted to use the `#region()` method
|
183
|
+
# * AWS::Credentials object, which will also scour the context and environment for your keys
|
184
|
+
# === @returns: AWS::SQS client
|
185
|
+
# === Sample Usage
|
186
|
+
# ```
|
187
|
+
# config = stub_responses: {
|
188
|
+
# create_queue: {
|
189
|
+
# queue_url: "https://sqs.us-west-2.amazonaws.com/12345678/#{opts[:name] || 'testQueue'}"
|
190
|
+
# }
|
191
|
+
# }
|
192
|
+
#
|
193
|
+
# sqs(config) # sets and gets an Kinesis client
|
194
|
+
#
|
195
|
+
# create_queue('someQueue')
|
196
|
+
# ```
|
69
197
|
def sqs(opts = {})
|
70
198
|
config = {
|
199
|
+
stub_responses: false,
|
71
200
|
credentials: Auth.creds
|
72
|
-
}
|
201
|
+
}
|
202
|
+
config = config.merge(opts.select { |k| config.key?(k) })
|
203
|
+
|
73
204
|
@sqs ||= Aws::SQS::Client.new(config)
|
74
205
|
end
|
75
206
|
end
|
data/lib/cloud_powers/helper.rb
CHANGED
@@ -282,6 +282,7 @@ module Smash
|
|
282
282
|
# TODO: Better implementation of merging message bodies and config needed
|
283
283
|
unless opts.kind_of? Hash
|
284
284
|
update = opts.to_s
|
285
|
+
opts = {}
|
285
286
|
opts[:extraInfo] = { message: update }
|
286
287
|
end
|
287
288
|
updated_extra_info = opts.delete(:extraInfo) || {}
|
data/lib/cloud_powers/node.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require_relative 'auth'
|
2
2
|
require_relative 'helper'
|
3
|
+
require_relative 'self_awareness'
|
3
4
|
require_relative 'zenv'
|
4
5
|
|
5
6
|
module Smash
|
@@ -7,6 +8,7 @@ module Smash
|
|
7
8
|
module Node
|
8
9
|
include Smash::CloudPowers::Auth
|
9
10
|
include Smash::CloudPowers::Helper
|
11
|
+
include Smash::CloudPowers::SelfAwareness
|
10
12
|
include Smash::CloudPowers::Zenv
|
11
13
|
# These are sensible defaults that can be overriden by providing a Hash as a param.
|
12
14
|
# @params [opts <Hash>]
|
@@ -99,7 +99,7 @@ module Smash
|
|
99
99
|
metadata_uri = "http://169.254.169.254/latest/meta-data/#{key}"
|
100
100
|
HTTParty.get(metadata_uri).parsed_response.split("\n")
|
101
101
|
else
|
102
|
-
require_relative
|
102
|
+
require_relative '../stubs/aws_stubs'
|
103
103
|
stubbed_metadata = Smash::CloudPowers::AwsStubs::INSTANCE_METADATA_STUB
|
104
104
|
|
105
105
|
key.empty? ? stubbed_metadata.keys : stubbed_metadata[to_hyph(key)]
|
@@ -28,21 +28,21 @@ module Smash
|
|
28
28
|
# end
|
29
29
|
|
30
30
|
# Creates a point to connect to for information about a given topic
|
31
|
-
# @params: name
|
32
|
-
# @returns: Broadcast::Channel representing the created channel
|
31
|
+
# === @params: name String: the name of the Channel/Topic to be created
|
32
|
+
# === @returns: Broadcast::Channel representing the created channel
|
33
33
|
def create_channel!(name)
|
34
34
|
resp = sns.create_topic(name: name)
|
35
35
|
Channel.new(nil, resp.topic_arn)
|
36
36
|
end
|
37
37
|
|
38
38
|
# Deletes a topic from SNS-land
|
39
|
-
# @params: channel <Broadcast::Channel>
|
39
|
+
# === @params: channel <Broadcast::Channel>
|
40
40
|
def delete_channel!(channel)
|
41
41
|
sns.delete_topic(topic_arn: channel.arn)
|
42
42
|
end
|
43
43
|
|
44
44
|
# Creates a connection to the Broadcast so that new messages will be picked up
|
45
|
-
# @params: channel <Broadcast::Channel>
|
45
|
+
# === @params: channel <Broadcast::Channel>
|
46
46
|
def listen_on(channel)
|
47
47
|
sns.subscribe(
|
48
48
|
topic_arn: channel.arn,
|
@@ -52,7 +52,7 @@ module Smash
|
|
52
52
|
end
|
53
53
|
|
54
54
|
# Lists the created topics in SNS.
|
55
|
-
# @returns results <Array
|
55
|
+
# === @returns results <Array
|
56
56
|
def real_channels
|
57
57
|
results = []
|
58
58
|
next_token = ''
|
@@ -66,7 +66,7 @@ module Smash
|
|
66
66
|
end
|
67
67
|
|
68
68
|
# Send a message to a Channel using SNS#publish
|
69
|
-
# @params: [opts <Hash>]:
|
69
|
+
# === @params: [opts <Hash>]:
|
70
70
|
# this includes all the keys AWS uses but for now it only has defaults
|
71
71
|
# for topic_arn and the message
|
72
72
|
def send_broadcast(opts = {})
|
@@ -1,20 +1,21 @@
|
|
1
|
-
require_relative '../../helper'
|
2
|
-
|
3
1
|
module Smash
|
4
2
|
module CloudPowers
|
5
3
|
module Synapse
|
6
|
-
include Smash::CloudPowers::Helper
|
7
|
-
|
8
4
|
module Pipe
|
5
|
+
include Smash::CloudPowers::AwsResources
|
6
|
+
include Smash::CloudPowers::Helper
|
7
|
+
include Smash::CloudPowers::Zenv
|
8
|
+
|
9
9
|
# Create a Kinesis stream or wait until the stream with the given name is
|
10
10
|
# through being created.
|
11
11
|
# === @params: name String
|
12
12
|
# === @returns: Boolean or nil
|
13
|
-
# * returns true or false if the request was successful
|
14
|
-
# * returns
|
13
|
+
# * returns true or false if the request was successful or not
|
14
|
+
# * returns true if the stream has already been created
|
15
|
+
# * returns false if the stream was not created
|
15
16
|
def create_stream(name)
|
16
17
|
begin
|
17
|
-
config = stream_config(stream_name:
|
18
|
+
config = stream_config(stream_name: name)
|
18
19
|
resp = kinesis.create_stream(config)
|
19
20
|
kinesis.wait_until(:stream_exists, stream_name: config[:stream_name])
|
20
21
|
resp.successful? # (http request successful && stream created)?
|
@@ -24,7 +25,7 @@ module Smash
|
|
24
25
|
return if stream_status(name) == 'ACTIVE'
|
25
26
|
logger.info "Not ready for traffic. Wait for 30 seconds..."
|
26
27
|
sleep 1
|
27
|
-
|
28
|
+
true # acts like it would if it had to create the stream
|
28
29
|
else
|
29
30
|
error_message = format_error_message(e)
|
30
31
|
logger.error error_message
|
@@ -73,9 +74,9 @@ module Smash
|
|
73
74
|
# See #instance_id()
|
74
75
|
def pipe_message_body(opts = {})
|
75
76
|
{
|
76
|
-
stream_name:
|
77
|
+
stream_name: zfind(opts[:stream_name]) || zfind('status_stream'),
|
77
78
|
data: opts[:data] || update_message_body(opts),
|
78
|
-
partition_key: opts[:partition_key] || @instance_id
|
79
|
+
partition_key: opts[:partition_key] || @instance_id || 'unk'
|
79
80
|
}
|
80
81
|
end
|
81
82
|
|
@@ -106,7 +107,7 @@ module Smash
|
|
106
107
|
# * stream_name:
|
107
108
|
def stream_config(opts = {})
|
108
109
|
config = {
|
109
|
-
stream_name: opts[:stream_name] ||
|
110
|
+
stream_name: opts[:stream_name] || zfind(:status_stream),
|
110
111
|
shard_count: opts[:shard_count] || 1
|
111
112
|
}
|
112
113
|
end
|
@@ -116,7 +117,7 @@ module Smash
|
|
116
117
|
# === @returns: Boolean
|
117
118
|
def stream_exists?(name)
|
118
119
|
begin
|
119
|
-
kinesis.describe_stream(stream_name:
|
120
|
+
kinesis.describe_stream(stream_name: name)
|
120
121
|
true
|
121
122
|
rescue Aws::Kinesis::Errors::ResourceNotFoundException => e
|
122
123
|
false
|
@@ -128,7 +129,7 @@ module Smash
|
|
128
129
|
# === @returns: stream status, one of:
|
129
130
|
# CREATING, DELETING, ACTIVE, UPDATING
|
130
131
|
def stream_status(name)
|
131
|
-
kinesis.describe_stream(name).stream_description.stream_status
|
132
|
+
kinesis.describe_stream(stream_name: name).stream_description.stream_status
|
132
133
|
end
|
133
134
|
end
|
134
135
|
end
|
@@ -13,7 +13,7 @@ module Smash
|
|
13
13
|
# or loaded, logging info and any other high-throughput/data-centric application with
|
14
14
|
# - Queue is a module that is primarily used for asynchronous communications between a sender
|
15
15
|
# and any number of users or apps that _might_ need to use it
|
16
|
-
# - WebSocServer
|
16
|
+
# - WebSocServer ..._Faisal's turn_...
|
17
17
|
module Synapse
|
18
18
|
include Smash::CloudPowers::Synapse::Broadcast
|
19
19
|
include Smash::CloudPowers::Synapse::Pipe
|
data/lib/cloud_powers/version.rb
CHANGED
@@ -0,0 +1,169 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module Smash
|
6
|
+
module CloudPowers
|
7
|
+
module AwsStubs
|
8
|
+
|
9
|
+
INSTANCE_METADATA_STUB = {
|
10
|
+
'ami-id' => 'ami-1234',
|
11
|
+
'ami-launch-index' => '1',
|
12
|
+
'ami-manifest-path' => '',
|
13
|
+
'block-device-mapping/' => '',
|
14
|
+
'hostname' => '',
|
15
|
+
'instance-action' => '',
|
16
|
+
'instance-id' => 'asd-1234',
|
17
|
+
'instance-type' => 't2.nano',
|
18
|
+
'kernel-id' => '',
|
19
|
+
'local-hostname' => 'ip-10-251-50-12.ec2.internal',
|
20
|
+
'local-ipv4' => '',
|
21
|
+
'mac network/' => '',
|
22
|
+
'placement/' => 'boogers',
|
23
|
+
'public-hostname' => 'ec2-203-0-113-25.compute-1.amazonaws.com',
|
24
|
+
'public-ipv4' => 'adsfasdfasfd',
|
25
|
+
'public-keys/' => 'jfakdsjfkdlsajfkldsajflkasjdfklajsdflkajsldkfjalsdfjaklsdjflasjfklasjdfkals',
|
26
|
+
'public-keys/0' => 'asdjfkasdjfkasdjflasjdfklsajdlkfjaldkgfjalkdfgjklsdfjgklsdjfklsjlkdfjakdlfjalskdfjlas',
|
27
|
+
'reservation-id' => 'r-fea54097',
|
28
|
+
'security-groups' => 'groupidygroupgroupgroup',
|
29
|
+
'services/' => ''
|
30
|
+
}
|
31
|
+
|
32
|
+
def self.node_stub(opts = {})
|
33
|
+
{
|
34
|
+
stub_responses: {
|
35
|
+
create_tags: {},
|
36
|
+
run_instances: {
|
37
|
+
instances: [
|
38
|
+
{ instance_id: 'asd-1234', launch_time: Time.now, state: { name: 'running' } },
|
39
|
+
{ instance_id: 'qwe-4323', launch_time: Time.now, state: { name: 'running' } },
|
40
|
+
{ instance_id: 'tee-4322', launch_time: Time.now, state: { name: 'running' } },
|
41
|
+
{ instance_id: 'bbf-6969', launch_time: Time.now, state: { name: 'running' } },
|
42
|
+
{ instance_id: 'lkj-0987', launch_time: Time.now, state: { name: 'running' } },
|
43
|
+
]},
|
44
|
+
describe_instances: {
|
45
|
+
reservations: [
|
46
|
+
{ instances: [
|
47
|
+
{ instance_id: 'asd-1234', state: { code: 200, name: 'running' } },
|
48
|
+
{ instance_id: 'qwe-4323', state: { code: 200, name: 'running' } },
|
49
|
+
{ instance_id: 'tee-4322', state: { code: 200, name: 'running' } },
|
50
|
+
{ instance_id: 'bbf-6969', state: { code: 200, name: 'running' } },
|
51
|
+
{ instance_id: 'lkj-0987', state: { code: 200, name: 'running' } }
|
52
|
+
] }] },
|
53
|
+
describe_images: {
|
54
|
+
images: [
|
55
|
+
{ image_id: 'asdf', state: 'available' },
|
56
|
+
{ image_id: 'fdas', state: 'available' },
|
57
|
+
{ image_id: 'fdadg', state: 'available' },
|
58
|
+
{ image_id: 'aswre', state: 'available' },
|
59
|
+
{ image_id: 'fsnkv', state: 'available' },
|
60
|
+
]
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.broadcast_stub(opts = {})
|
67
|
+
arn = "arn:aws:sns:us-west-2:8123456789:#{opts[:name] || 'testChannel'}"
|
68
|
+
stub = {
|
69
|
+
stub_responses: {
|
70
|
+
create_topic: { topic_arn: arn },
|
71
|
+
delete_topic: {},
|
72
|
+
list_topics: { topics: [{ topic_arn: arn }], next_token: '1234asdf' },
|
73
|
+
publish: { message_id: 'msgidmsgidmsgidmsgid' },
|
74
|
+
subscribe: { subscription_arn: 'subarnsubarnsubarn' }
|
75
|
+
}
|
76
|
+
}
|
77
|
+
stub.merge(opts.select { |k,v| stub.key? k })
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.pipe_stub(opts = {})
|
81
|
+
stub = {
|
82
|
+
stub_responses: {
|
83
|
+
create_stream: {},
|
84
|
+
put_record: {
|
85
|
+
shard_id: opts[:shard_id] || 'idididididididid',
|
86
|
+
sequence_number: opts[:sequence_number] || '1234'
|
87
|
+
},
|
88
|
+
describe_stream: {
|
89
|
+
stream_description: {
|
90
|
+
stream_name: opts[:name] || 'testPipe',
|
91
|
+
stream_arn: 'arnarnarnarnar',
|
92
|
+
stream_status: 'ACTIVE',
|
93
|
+
shards: [
|
94
|
+
{ shard_id: '1',
|
95
|
+
parent_shard_id: 'wowza',
|
96
|
+
hash_key_range: {
|
97
|
+
starting_hash_key: 'starting',
|
98
|
+
ending_hash_key: 'ending'
|
99
|
+
},
|
100
|
+
sequence_number_range: {
|
101
|
+
starting_sequence_number: '1'
|
102
|
+
}
|
103
|
+
}
|
104
|
+
],
|
105
|
+
has_more_shards: true,
|
106
|
+
retention_period_hours: 1,
|
107
|
+
enhanced_monitoring: []
|
108
|
+
}
|
109
|
+
}
|
110
|
+
}
|
111
|
+
}
|
112
|
+
stub.merge(opts.select { |k| stub.key?(k) })
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.queue_stub(opts = {})
|
116
|
+
{
|
117
|
+
stub_responses: {
|
118
|
+
create_queue: {
|
119
|
+
queue_url: "https://sqs.us-west-2.amazonaws.com/12345678/#{opts[:name] || 'testQueue'}"
|
120
|
+
},
|
121
|
+
delete_message: {}, # #delete_message() returns nothing
|
122
|
+
delete_queue: {}, # #delete_queue() returns nothing
|
123
|
+
get_queue_attributes: {
|
124
|
+
attributes: { 'ApproximateNumberOfMessages' => rand(1..10).to_s }
|
125
|
+
},
|
126
|
+
get_queue_url: {
|
127
|
+
queue_url: "https://sqs.us-west-2.amazonaws.com/12345678/#{opts[:name] || 'testQueue'}"
|
128
|
+
},
|
129
|
+
list_queues: {
|
130
|
+
queue_urls: ["https://sqs.us-west-2.amazonaws.com/12345678/#{opts[:name] || 'testQueue'}"]
|
131
|
+
},
|
132
|
+
receive_message: {
|
133
|
+
messages: [
|
134
|
+
{
|
135
|
+
attributes: {
|
136
|
+
"ApproximateFirstReceiveTimestamp" => "1442428276921",
|
137
|
+
"ApproximateReceiveCount" => "5",
|
138
|
+
"SenderId" => "AIDAIAZKMSNQ7TEXAMPLE",
|
139
|
+
"SentTimestamp" => "1442428276921"
|
140
|
+
},
|
141
|
+
body: "{\"foo\":\"bar\"}",
|
142
|
+
md5_of_body: "51b0a325...39163aa0",
|
143
|
+
md5_of_message_attributes: "00484c68...59e48f06",
|
144
|
+
message_attributes: {
|
145
|
+
"City" => {
|
146
|
+
data_type: "String",
|
147
|
+
string_value: "Any City"
|
148
|
+
},
|
149
|
+
"PostalCode" => {
|
150
|
+
data_type: "String",
|
151
|
+
string_value: "ABC123"
|
152
|
+
}
|
153
|
+
},
|
154
|
+
message_id: "da68f62c-0c07-4bee-bf5f-7e856EXAMPLE",
|
155
|
+
receipt_handle: "AQEBzbVv...fqNzFw=="
|
156
|
+
}
|
157
|
+
]
|
158
|
+
},
|
159
|
+
send_message: {
|
160
|
+
md5_of_message_attributes: "00484c68...59e48f06",
|
161
|
+
md5_of_message_body: "51b0a325...39163aa0",
|
162
|
+
message_id: "da68f62c-0c07-4bee-bf5f-7e856EXAMPLE"
|
163
|
+
}
|
164
|
+
}
|
165
|
+
}.merge(opts)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloud_powers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Phillipps
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-10-
|
12
|
+
date: 2016-10-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport-core-ext
|
@@ -183,11 +183,14 @@ description: |2
|
|
183
183
|
CloudPowers is a wrapper around AWS and in the future, other cloud service Providers.
|
184
184
|
It was developed specifically for the Brain project but hopefully can be used
|
185
185
|
in any other ruby project that needs to use cloud service providers' resources.
|
186
|
-
|
186
|
+
|
187
|
+
Version 0.2.7 has a little EC2, S3, SQS, SNS, Kinesis, websockets and a few other
|
187
188
|
features you can find in the docs. There is also limitted support for stubbing
|
188
189
|
AWS RESTful API calls. That can come in handy for local testing and extra setup on
|
189
190
|
AWS resource clients.
|
191
|
+
|
190
192
|
The next versions will have more Kinesis, Workflow integration and IoT.
|
193
|
+
|
191
194
|
This project is actively being developed, so more additions, specs and docs
|
192
195
|
will be added and updated frequently with new funcionality but the gem will
|
193
196
|
follow good practices for versioning. Input is always welcome.
|
@@ -233,6 +236,7 @@ files:
|
|
233
236
|
- lib/cloud_powers/version.rb
|
234
237
|
- lib/cloud_powers/workflow.rb
|
235
238
|
- lib/cloud_powers/zenv.rb
|
239
|
+
- lib/stubs/aws_stubs.rb
|
236
240
|
homepage: https://github.com/adam-phillipps/cloud_powers
|
237
241
|
licenses:
|
238
242
|
- MIT
|