cloud_powers 0.2.7 → 0.2.7.1
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/README.rdoc.mdown +180 -0
- data/Rakefile +5 -0
- data/cloud_powers.gemspec +1 -1
- data/lib/cloud_powers/auth.rb +24 -10
- data/lib/cloud_powers/aws_resources.rb +70 -114
- data/lib/cloud_powers/context.rb +66 -31
- data/lib/cloud_powers/helper.rb +36 -33
- data/lib/cloud_powers/node.rb +2 -2
- data/lib/cloud_powers/self_awareness.rb +18 -11
- data/lib/cloud_powers/synapse/broadcast/broadcast.rb +27 -9
- data/lib/cloud_powers/synapse/pipe/pipe.rb +77 -31
- data/lib/cloud_powers/synapse/queue/board.rb +78 -32
- data/lib/cloud_powers/synapse/queue/queue.rb +164 -38
- data/lib/cloud_powers/synapse/synapse.rb +7 -6
- data/lib/cloud_powers/version.rb +1 -1
- data/lib/cloud_powers/zenv.rb +11 -11
- data/lib/cloud_powers.rb +10 -0
- data/lib/stubs/aws_stubs.rb +132 -4
- metadata +4 -3
data/lib/cloud_powers/zenv.rb
CHANGED
@@ -10,8 +10,8 @@ module Smash
|
|
10
10
|
|
11
11
|
# Attempts to find a file by searching the current directory for the file
|
12
12
|
# then walking up the file tree and searching at each stop
|
13
|
-
#
|
14
|
-
#
|
13
|
+
# Parameters name <String>: name of the file or directory to find
|
14
|
+
# Returns Pathname: path to the file or directory given as the `name` param
|
15
15
|
def file_tree_search(name)
|
16
16
|
next_dir = Pathname.new(`pwd`.strip).parent
|
17
17
|
current_dir = Pathname.new(`pwd`.strip)
|
@@ -33,8 +33,8 @@ module Smash
|
|
33
33
|
|
34
34
|
# Search through the instance variables for a key or if no key is given,
|
35
35
|
# return all the i-vars and their values
|
36
|
-
#
|
37
|
-
#
|
36
|
+
# Parameters [key <String]: The key to search for
|
37
|
+
# Returns
|
38
38
|
def i_vars(key = '')
|
39
39
|
if key.empty?
|
40
40
|
return self.instance_variables.inject({}) do |r,v|
|
@@ -47,7 +47,7 @@ module Smash
|
|
47
47
|
# PROJECT_ROOT should be set as early as possible in this Node's initilize
|
48
48
|
# method. This method tries to search for it, using #zfind() and if a `nil`
|
49
49
|
# result is returned from that search, `pwd` is used as the PROJECT_ROOT.
|
50
|
-
#
|
50
|
+
# Returns Path to the project root or where ever `pwd` resolves to <Pathname>
|
51
51
|
# TODO: improve this...it needs to find the gem's method's caller's project
|
52
52
|
# root or at least the gem's method's caller's file's location.
|
53
53
|
def project_root
|
@@ -61,16 +61,16 @@ module Smash
|
|
61
61
|
end
|
62
62
|
|
63
63
|
# Manually set the `@project_root` i-var as a `Pathname` object.
|
64
|
-
#
|
65
|
-
#
|
64
|
+
# Parameters New path to the project root <String|Pathname>
|
65
|
+
# Returns @project_root <Pathname>
|
66
66
|
def project_root=(var)
|
67
67
|
@project_root = Pathname.new(var)
|
68
68
|
end
|
69
69
|
|
70
70
|
# Search through the system environment variables for a key or if no key
|
71
71
|
# is given, return all the system-env-vars and their values
|
72
|
-
#
|
73
|
-
#
|
72
|
+
# Parameters [key <String>]: The key to search for
|
73
|
+
# Returns Value <String> for the given key or if no key was given, a
|
74
74
|
# Hash with { key => value, ... } is returned for all keys with a value.
|
75
75
|
# Keys with no value are ommitted from the result.
|
76
76
|
def system_vars(key = '')
|
@@ -98,8 +98,8 @@ module Smash
|
|
98
98
|
# it's important
|
99
99
|
# * System Env[@] variables are up next. Hopefully by this time we've found
|
100
100
|
# our information but if not, it should "search" through the system env too.
|
101
|
-
#
|
102
|
-
#
|
101
|
+
# Parameters key <String>: The key to search for
|
102
|
+
# Returns <String>
|
103
103
|
# TODO: implement a search for all 3 that can find close matches
|
104
104
|
def zfind(key)
|
105
105
|
project_root if @project_root.nil?
|
data/lib/cloud_powers.rb
CHANGED
@@ -9,15 +9,25 @@ require 'cloud_powers/storage'
|
|
9
9
|
require 'cloud_powers/version'
|
10
10
|
require 'cloud_powers/workflow'
|
11
11
|
|
12
|
+
# The Smash module allows us to use CloudPowers under a shared name space with other projects.
|
12
13
|
module Smash
|
14
|
+
# The CloudPowers module contains all the other modules and classes that creates the <i>CloudPowers</i> gem.
|
13
15
|
module CloudPowers
|
16
|
+
# Authentication mixin
|
14
17
|
extend Smash::CloudPowers::Auth
|
18
|
+
# Dynamic Resource creation and delegation
|
15
19
|
extend Smash::CloudPowers::Delegator
|
20
|
+
# Aws clients, like EC2 and S3
|
16
21
|
include Smash::CloudPowers::AwsResources
|
22
|
+
# Various helper methods
|
17
23
|
include Smash::CloudPowers::Helper
|
24
|
+
# Gathers data about an instance, itself
|
18
25
|
include Smash::CloudPowers::SelfAwareness
|
26
|
+
# Store files
|
19
27
|
include Smash::CloudPowers::Storage
|
28
|
+
# Communication modules
|
20
29
|
include Smash::CloudPowers::Synapse
|
30
|
+
# CRUD on Nodes, which are individual instances
|
21
31
|
include Smash::CloudPowers::Node
|
22
32
|
end
|
23
33
|
end
|
data/lib/stubs/aws_stubs.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
1
|
module Smash
|
6
2
|
module CloudPowers
|
3
|
+
# Provides stubbing for development work in CloudPowers or in a project that uses is
|
7
4
|
module AwsStubs
|
8
5
|
|
6
|
+
# Stub metadata for EC2 instance
|
9
7
|
INSTANCE_METADATA_STUB = {
|
10
8
|
'ami-id' => 'ami-1234',
|
11
9
|
'ami-launch-index' => '1',
|
@@ -29,6 +27,35 @@ module Smash
|
|
29
27
|
'services/' => ''
|
30
28
|
}
|
31
29
|
|
30
|
+
# Get or create an EC2 client and cache that client so that a Context is more well tied together
|
31
|
+
#
|
32
|
+
# Parameters
|
33
|
+
# * opts +Hash+ (optional)
|
34
|
+
# * * stub_responses - defaulted to +false+ but it can be overriden with the desired responses for local testing
|
35
|
+
# * * region - defaulted to use the <tt>#region()</tt> method
|
36
|
+
# * * AWS::Credentials object, which will also scour the context and environment for your keys
|
37
|
+
#
|
38
|
+
# === Returns
|
39
|
+
# <tt>AWS::EC2::Client</tt>
|
40
|
+
# === Sample Usage
|
41
|
+
# config = stub_responses: {
|
42
|
+
# run_instances: {
|
43
|
+
# instances: [{ instance_id: 'asd-1234', launch_time: Time.now, state: { name: 'running' }]
|
44
|
+
# },
|
45
|
+
# describe_instances: {
|
46
|
+
# reservations: [
|
47
|
+
# { instances: [{ instance_id: 'asd-1234', state: { code: 200, name: 'running' } }] }
|
48
|
+
# ] },
|
49
|
+
# describe_images: {
|
50
|
+
# images: [{ image_id: 'asdf', state: 'available' }]
|
51
|
+
# }
|
52
|
+
# }
|
53
|
+
#
|
54
|
+
# ec2(config) # sets and gets an <tt>EC2::Client</tt> that is stubbed with the return data in the config <tt>Hash</tt>
|
55
|
+
#
|
56
|
+
# images = ec2.describe_images
|
57
|
+
# images.first[:image_id]
|
58
|
+
# # => 'asdf'
|
32
59
|
def self.node_stub(opts = {})
|
33
60
|
{
|
34
61
|
stub_responses: {
|
@@ -63,6 +90,31 @@ module Smash
|
|
63
90
|
}
|
64
91
|
end
|
65
92
|
|
93
|
+
# Stub data for a SNS client
|
94
|
+
# Parameters
|
95
|
+
# * opts +Hash+
|
96
|
+
# * * stub_responses: defaulted to false but it can be overriden with the desired responses for local testing
|
97
|
+
# * * region: defaulted to use the `#region()` method
|
98
|
+
# * * AWS::Credentials object, which will also scour the context and environment for your keys
|
99
|
+
#
|
100
|
+
# === Returns
|
101
|
+
# AWS::SNS client
|
102
|
+
#
|
103
|
+
# === Example
|
104
|
+
# config = {
|
105
|
+
# stub_responses: {
|
106
|
+
# create_topic: {},
|
107
|
+
# delete_topic: {},
|
108
|
+
# list_topics: [],
|
109
|
+
# publish: {},
|
110
|
+
# subscribe: {}
|
111
|
+
# }
|
112
|
+
# }
|
113
|
+
#
|
114
|
+
# sns(config) # sets and gets an Kinesis client
|
115
|
+
#
|
116
|
+
# create_channel!('testBroadcast')
|
117
|
+
# # => true
|
66
118
|
def self.broadcast_stub(opts = {})
|
67
119
|
arn = "arn:aws:sns:us-west-2:8123456789:#{opts[:name] || 'testChannel'}"
|
68
120
|
stub = {
|
@@ -77,6 +129,39 @@ module Smash
|
|
77
129
|
stub.merge(opts.select { |k,v| stub.key? k })
|
78
130
|
end
|
79
131
|
|
132
|
+
# Get or create an Kinesis client and cache that client so that a Context is more well tied together
|
133
|
+
# Parameters
|
134
|
+
# * opts <tt>Hash</tt>
|
135
|
+
# * * stub_responses: defaulted to false but it can be overriden with the desired responses for local testing
|
136
|
+
# * * region: defaulted to use the `#region()` method
|
137
|
+
# * * AWS::Credentials object, which will also scour the context and environment for your keys
|
138
|
+
#
|
139
|
+
# === Returns
|
140
|
+
# AWS::Kinesis client
|
141
|
+
#
|
142
|
+
# === Example
|
143
|
+
# config = {
|
144
|
+
# stub_responses: {
|
145
|
+
# create_stream: {},
|
146
|
+
# put_record: {
|
147
|
+
# shard_id: opts[:shard_id] || 'idididididididid',
|
148
|
+
# sequence_number: opts[:sequence_number] || Time.now.to_i.to_s
|
149
|
+
# },
|
150
|
+
# describe_stream: {
|
151
|
+
# stream_description: {
|
152
|
+
# stream_name: opts[:name] || 'somePipe',
|
153
|
+
# stream_arn: 'arnarnarnarnar',
|
154
|
+
# stream_status: 'ACTIVE',
|
155
|
+
# }
|
156
|
+
# }
|
157
|
+
# }
|
158
|
+
# }
|
159
|
+
# }
|
160
|
+
#
|
161
|
+
# kinesis(config) # sets and gets an Kinesis client
|
162
|
+
#
|
163
|
+
# pipe_to('somePipe') { update_body(status: 'waHoo') }
|
164
|
+
# # => sequence_number: '1676151970'
|
80
165
|
def self.pipe_stub(opts = {})
|
81
166
|
stub = {
|
82
167
|
stub_responses: {
|
@@ -112,6 +197,49 @@ module Smash
|
|
112
197
|
stub.merge(opts.select { |k| stub.key?(k) })
|
113
198
|
end
|
114
199
|
|
200
|
+
# Get or create an S3 client and cache that client so that a Context is more well tied together
|
201
|
+
#
|
202
|
+
# Parameters
|
203
|
+
# * opts <tt>Hash</tt>
|
204
|
+
# * * stub_responses: defaulted to false but it can be overriden with the desired responses for local testing
|
205
|
+
# * * region: defaulted to use the `#region()` method
|
206
|
+
# * * AWS::Credentials object, which will also scour the context and environment for your keys
|
207
|
+
#
|
208
|
+
# === Returns
|
209
|
+
# AWS::S3 client
|
210
|
+
#
|
211
|
+
# === Example
|
212
|
+
# config = {
|
213
|
+
# stub_responses: {
|
214
|
+
# head_bucket: {}
|
215
|
+
# }
|
216
|
+
# }
|
217
|
+
#
|
218
|
+
# s3(config)
|
219
|
+
# expect(s3.head_bucket).to be_empty
|
220
|
+
# # passing expectation
|
221
|
+
def self.storage_stub(opts = {})
|
222
|
+
{
|
223
|
+
stub_responses: {
|
224
|
+
head_bucket: {}
|
225
|
+
}
|
226
|
+
}
|
227
|
+
end
|
228
|
+
|
229
|
+
# Stub data for an SQS client
|
230
|
+
#
|
231
|
+
# Parameters
|
232
|
+
# * opts <tt>Hash</tt>
|
233
|
+
# * * stub_responses: defaulted to false but it can be overriden with the desired responses for local testing
|
234
|
+
# * * region: defaulted to use the `#region()` method
|
235
|
+
# * * AWS::Credentials object, which will also scour the context and environment for your keys
|
236
|
+
#
|
237
|
+
# === Returns
|
238
|
+
# AWS::SQS client
|
239
|
+
#
|
240
|
+
# === Example
|
241
|
+
# create_queue('someQueue') # uses AWS::SQS
|
242
|
+
# some_queue_url = queue_search('someQueue').first # uses AWS::SQS
|
115
243
|
def self.queue_stub(opts = {})
|
116
244
|
{
|
117
245
|
stub_responses: {
|
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.7
|
4
|
+
version: 0.2.7.1
|
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-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport-core-ext
|
@@ -184,7 +184,7 @@ description: |2
|
|
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.
|
187
|
+
Version 0.2.8 has a little EC2, S3, SQS, SNS, Kinesis, websockets and a few other
|
188
188
|
features you can find in the docs. There is also limitted support for stubbing
|
189
189
|
AWS RESTful API calls. That can come in handy for local testing and extra setup on
|
190
190
|
AWS resource clients.
|
@@ -212,6 +212,7 @@ files:
|
|
212
212
|
- Gemfile.lock_b
|
213
213
|
- LICENSE.txt
|
214
214
|
- README.md
|
215
|
+
- README.rdoc.mdown
|
215
216
|
- Rakefile
|
216
217
|
- bin/console
|
217
218
|
- bin/setup
|