conrad 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dca0b05c54f60645fece80d8226d43d6130afb47aac653d8bb92090b619c7812
4
- data.tar.gz: 26a24ce8ec5288ab2847fda11442c13dbba14addd883dd2931d32ef1da240222
3
+ metadata.gz: e96b6146bf06c4a7e186558757e061af57b5dc1b8ac7d2129a78cf6ca9ccae14
4
+ data.tar.gz: e1f8ded64e5f68c115722e266615e3cd13c0c430cdfcd75ba59c6ffa2f70ecba
5
5
  SHA512:
6
- metadata.gz: 3f9023ef66bb257ad4d9ceaa25b4ce63e646128c67e11de7fda8a765622235eefebfc83019a6ff4f0349ce0134b19793c689c0319f07e9e4e2af9e3f5982442d
7
- data.tar.gz: fa8f34c73693be7666ee7ccadd9ba54f69d716c197ced407d5788a2a0205dea7755771fd4d359e2362befff766caae9173e89fb183fb757ec0e230c0b335a7c2
6
+ metadata.gz: 7278ae58a8a6616d3a81b86be52c544214dfec99673a6af824e6265db0ce6a49e202b88068905c4982f6fb3e5c563d87609c66f5c9772d4404ef236d5f8638eb
7
+ data.tar.gz: 820d004eec75ca4870c80fda14137fb670fb6549aa543f545459404b17ae3e40d4ebf5be4aae6a570971b06c10bf262a8d3dfa578a4374d1e32310b8a7d21583
@@ -1,27 +1,81 @@
1
+ require 'conrad/errors'
2
+
1
3
  module Conrad
2
- # A module containing all of conrad's built in event emitters for outputting events
4
+ # A module containing all of conrad's built in event emitters for outputting
5
+ # events
3
6
  module Emitters
4
- # Basic emitter for sending events to AWS's sqs.
7
+ # Basic emitter for sending events to AWS's sqs. If all access information
8
+ # is given, the given credentials will be used. Otherwise, the emitter will
9
+ # attempt to use values configured in the running environment according to
10
+ # the AWS SDK documentation (such as from ~/.aws/credentials).
5
11
  class Sqs
6
- attr_reader :queue_url, :region, :access_key_id, :secret_access_key
12
+ # Error for responding with issues around SQS credential creation
13
+ class InvalidAwsCredentials < ::Conrad::Error
14
+ # :nodoc:
15
+ def to_s
16
+ 'Must provide secret_access_key, access_key_id, and region OR rely ' \
17
+ 'on configured values in the running environment.'
18
+ end
19
+ end
20
+
21
+ # @return [String] the configured SQS queue URL
22
+ attr_reader :queue_url
23
+
24
+ # @deprecated Will be removed in 3.0.0, no migration path
25
+ # @return [String, nil] the configured region
26
+ attr_reader :region
27
+
28
+ # @deprecated Will be removed in 3.0.0, no migration path
29
+ # @return [String, nil] the configured AWS Access key ID
30
+ attr_reader :access_key_id
31
+
32
+ # @deprecated Will be removed in 3.0.0, no migration path
33
+ # @return [String, nil] the configured AWS secret access key
34
+ attr_reader :secret_access_key
35
+
36
+ # @return [Aws::SQS::Client] the created client
37
+ attr_reader :client
7
38
 
8
- # Takes in and stores SQS region, url and creds for accessing a queue.
9
- def initialize(queue_url:, region:, access_key_id:, secret_access_key:)
39
+ # @param queue_url [String] the queue to send messages to
40
+ # @param region [String] region the queue lives in
41
+ # @param access_key_id [String] AWS Acesss Key ID
42
+ # @param secret_access_key [String] AWS Secret Access Key
43
+ #
44
+ # @raise [InvalidAwsCredentials] if any of region, access_key_id, or
45
+ # secret_access_key are not provided AND the running environment does
46
+ # not have valid AWS credentials
47
+ def initialize(queue_url:, region: nil, access_key_id: nil, secret_access_key: nil)
10
48
  @queue_url = queue_url
11
49
  @region = region
12
50
  @access_key_id = access_key_id
13
51
  @secret_access_key = secret_access_key
14
52
 
15
- @client ||= Aws::SQS::Client.new(
16
- region: region,
17
- access_key_id: access_key_id,
18
- secret_access_key: secret_access_key
19
- )
53
+ create_client(region: region, access_key_id: access_key_id, secret_access_key: secret_access_key)
20
54
  end
21
55
 
22
56
  # Sends an event up to SQS
23
57
  def call(event)
24
- @client.send_message(queue_url: queue_url, message_body: event)
58
+ client.send_message(queue_url: queue_url, message_body: event)
59
+ end
60
+
61
+ private
62
+
63
+ def create_client(region:, access_key_id:, secret_access_key:)
64
+ if secret_access_key.nil? || access_key_id.nil? || region.nil?
65
+ validate_implicit_credentials
66
+
67
+ @client = Aws::SQS::Client.new
68
+ else
69
+ @client = Aws::SQS::Client.new(
70
+ region: region,
71
+ access_key_id: access_key_id,
72
+ secret_access_key: secret_access_key
73
+ )
74
+ end
75
+ end
76
+
77
+ def validate_implicit_credentials
78
+ raise InvalidAwsCredentials unless Aws::CredentialProviderChain.new.resolve.set?
25
79
  end
26
80
  end
27
81
  end
@@ -1,5 +1,5 @@
1
1
  # :nodoc:
2
2
  module Conrad
3
3
  # :nodoc:
4
- VERSION = '2.2.0'.freeze
4
+ VERSION = '2.3.0'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conrad
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathon Anderson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-16 00:00:00.000000000 Z
11
+ date: 2019-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest-stub-const
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement