cloudutil 0.0.1 → 0.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1409a2b9cdb13ae5236b4d4f70fb4eec0b16f47d
4
- data.tar.gz: 6ae2a2a2554cc5af1f2ea34e394a89deea8112f3
3
+ metadata.gz: 68096f9d1dc06c6bc5e8d1c200ca5aaaf13a4455
4
+ data.tar.gz: fee3debc208932511be30e01a5585afd299ec5d1
5
5
  SHA512:
6
- metadata.gz: f087f0aa8a8ff7202e2bbf8016d6f653e21b617210b72abdfeb8bc2fdbc3f10346f4a2393136c1ee9a091317904e0f1236c8bbab117cc570f0e1b29c245262ad
7
- data.tar.gz: 5f83cf1c8de01886765863a7ca87693ccd644d0c4ed9962a03093a85f066fc149386795994ba156a4cb8d7bd8b27bf96c7edcf94b1e0775e39b2ff893dfb974a
6
+ metadata.gz: a4461406ff58f5507d10947850f292107ba3f264a5d68a61961308cd4b8fe100bf31d6432968a39d6837e4f1a34c308028e5b7bae88ddae4fc894a550ec5fb5b
7
+ data.tar.gz: b5731e321ea25f227d239b9f84214dc40902c7debad9903b700c54e9e257c1972ca335995a18f1e436116468042cde6dbdaed113295c1ea10fd99a1d618e3037
data/Rakefile CHANGED
@@ -16,7 +16,7 @@ end
16
16
  desc 'Run rspec'
17
17
  RSpec::Core::RakeTask.new(:spec, [:format, :tags]) do |t, args|
18
18
  format = args[:format] || 'documentation'
19
- tags = args[:tags] || []
19
+ tags = Array(args[:tags]) || []
20
20
  t.verbose = false
21
21
  t.fail_on_error = true
22
22
  t.rspec_opts = "--format=#{format}"
@@ -26,4 +26,5 @@ RSpec::Core::RakeTask.new(:spec, [:format, :tags]) do |t, args|
26
26
  end
27
27
 
28
28
  t.ruby_opts = '-W0'
29
+ # rake spec\[documentation,~slow\] on cmdline to exclude only slow tests
29
30
  end
@@ -0,0 +1,40 @@
1
+ require_relative './core.rb'
2
+
3
+ module Cloudutil
4
+ module AWS
5
+ # A class of utility methods for the AWS SNS service
6
+ class SNS < Cloudutil::AWS::Core
7
+ def resolve_topic_arn(topic, ignore_case = true, nap = 2, retries = 5)
8
+ sns = ::AWS::SNS.new
9
+ arn = nil
10
+
11
+ begin
12
+ if aws_topic_arn? topic
13
+ arn = topic
14
+ else
15
+ arn = ::AWS.memoize do
16
+ if ignore_case
17
+ t_obj = sns.topics.find { |t| t.name.casecmp(topic) == 0 }
18
+ else
19
+ t_obj = sns.topics.find { |t| t.name.eql? topic }
20
+ end
21
+
22
+ t_obj.arn unless t_obj.nil?
23
+ end
24
+ end
25
+ rescue ::AWS::EC2::Errors::RequestLimitExceeded, ::AWS::Errors::ServerError
26
+ raise if retries < 1
27
+ sleep nap
28
+ resolve_topic_arn(topic, ignore_case, (nap * 2), (retries - 1))
29
+ end
30
+
31
+ arn
32
+ end
33
+
34
+ def aws_topic_arn?(topic)
35
+ return true if topic.strip.downcase.start_with? 'arn:aws:sns:'
36
+ false
37
+ end
38
+ end
39
+ end
40
+ end
data/lib/cloudutil/aws.rb CHANGED
@@ -1 +1,2 @@
1
1
  require_relative './aws/ec2'
2
+ require_relative './aws/sns'
@@ -1,4 +1,4 @@
1
1
  # Module to hold the version number for this library
2
2
  module Cloudutil
3
- VERSION = '0.0.1'
3
+ VERSION = '0.1.0'
4
4
  end
@@ -0,0 +1,67 @@
1
+ require_relative '../lib/cloudutil/aws.rb'
2
+
3
+ describe Cloudutil::AWS::SNS do
4
+ context 'object initialization' do
5
+ it 'creates an object using primary env vars' do
6
+ ENV.clear
7
+ ENV['AWS_ACCESS_KEY_ID'] = 'my_primary_access_key'
8
+ ENV['AWS_SECRET_ACCESS_KEY'] = 'my_primary_secret_key'
9
+
10
+ aws = Cloudutil::AWS::SNS.new
11
+
12
+ expect(aws.region).to eq 'us-east-1'
13
+ expect(aws.access_key).to eq 'my_primary_access_key'
14
+ expect(aws.secret_key).to eq 'my_primary_secret_key'
15
+ end
16
+
17
+ it 'creates an object using implicit hash args' do
18
+ reg = 'us-west-1'
19
+ ak = 'my_access_key1'
20
+ sk = 'my_secret_key1'
21
+
22
+ aws = Cloudutil::AWS::SNS.new(region: reg, access_key: ak, secret_key: sk)
23
+
24
+ expect(aws.region).to eq reg
25
+ expect(aws.access_key).to eq ak
26
+ expect(aws.secret_key).to eq sk
27
+ end
28
+ end
29
+
30
+ context 'resolving SNS topic ARNs' do
31
+ # Need to do this to read AWS creds from env
32
+ my_env = ENV.to_h
33
+ before(:each) do
34
+ @aws = Cloudutil::AWS::SNS.new(access_key: my_env['AWS_ACCESS_KEY_ID'], secret_key: my_env['AWS_SECRET_ACCESS_KEY'])
35
+ end
36
+
37
+ it 'returns the given value if it looks like a topic ARN' do
38
+ data = 'arn:aws:sns:us-east-1:my-topic'
39
+ arn = @aws.resolve_topic_arn(data)
40
+ expect(arn).to eq data
41
+ end
42
+
43
+ it 'returns a known topic ARN, case-sensitive', account_specific: true do
44
+ arn = @aws.resolve_topic_arn('storagegateway', false)
45
+
46
+ expect(arn).to_not be_nil
47
+ expect(arn).to match(/^arn:aws:sns:.*:storagegateway$/)
48
+ end
49
+
50
+ it 'returns a known topic ARN, case-insensitive', account_specific: true do
51
+ arn = @aws.resolve_topic_arn('sTOraGEgaTEwaY')
52
+
53
+ expect(arn).to_not be_nil
54
+ expect(arn).to match(/^arn:aws:sns:.*:storagegateway$/)
55
+ end
56
+
57
+ it 'returns nil for no case-sensitive match', account_specific: true do
58
+ arn = @aws.resolve_topic_arn('sTOraGEgaTEwaY', false)
59
+ expect(arn).to be_nil
60
+ end
61
+
62
+ it 'returns nil for a bogus topic', account_specific: true do
63
+ arn = @aws.resolve_topic_arn('bogus-topic')
64
+ expect(arn).to be_nil
65
+ end
66
+ end
67
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudutil
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Morris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-19 00:00:00.000000000 Z
11
+ date: 2015-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -136,9 +136,11 @@ files:
136
136
  - lib/cloudutil/aws.rb
137
137
  - lib/cloudutil/aws/core.rb
138
138
  - lib/cloudutil/aws/ec2.rb
139
+ - lib/cloudutil/aws/sns.rb
139
140
  - lib/cloudutil/version.rb
140
141
  - spec/aws_core_spec.rb
141
142
  - spec/aws_ec2_spec.rb
143
+ - spec/aws_sns_spec.rb
142
144
  homepage: ''
143
145
  licenses:
144
146
  - MIT
@@ -167,3 +169,4 @@ summary: A utility library for performing helpful tasks with various cloud platf
167
169
  test_files:
168
170
  - spec/aws_core_spec.rb
169
171
  - spec/aws_ec2_spec.rb
172
+ - spec/aws_sns_spec.rb