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 +4 -4
- data/lib/conrad/emitters/sqs.rb +65 -11
- data/lib/conrad/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e96b6146bf06c4a7e186558757e061af57b5dc1b8ac7d2129a78cf6ca9ccae14
|
4
|
+
data.tar.gz: e1f8ded64e5f68c115722e266615e3cd13c0c430cdfcd75ba59c6ffa2f70ecba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7278ae58a8a6616d3a81b86be52c544214dfec99673a6af824e6265db0ce6a49e202b88068905c4982f6fb3e5c563d87609c66f5c9772d4404ef236d5f8638eb
|
7
|
+
data.tar.gz: 820d004eec75ca4870c80fda14137fb670fb6549aa543f545459404b17ae3e40d4ebf5be4aae6a570971b06c10bf262a8d3dfa578a4374d1e32310b8a7d21583
|
data/lib/conrad/emitters/sqs.rb
CHANGED
@@ -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
|
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
|
-
|
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
|
-
#
|
9
|
-
|
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
|
-
|
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
|
-
|
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
|
data/lib/conrad/version.rb
CHANGED
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.
|
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-
|
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
|