sqs2cb 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -0
- data/Rakefile +2 -0
- data/bin/sqs2cb +9 -0
- data/lib/sqs2cb/version.rb +3 -0
- data/lib/sqs2cb.rb +74 -0
- data/sqs2cb.gemspec +24 -0
- data/test/lib/sqs2cb/version_test.rb +7 -0
- data/test/lib/sqs2cb_test.rb +25 -0
- data/test/test_helper.rb +5 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 08e3a72d74524959ba375f5f5709df5312600e72
|
4
|
+
data.tar.gz: c95ffe28d473b253a4b0b1e2e94ab2c7e6003a24
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e862672c006c4c161604e3af9b423c1585aacbad5707038809f38f61a30e661cba8c76ed510b571c1ec3a2bfa6d09ae9c78125be6c3de45aeb0319902f338054
|
7
|
+
data.tar.gz: f90f1f05754c8a57c948ec393a66ba1ad6b29e1d9c6fa3d99222c7b24e81a8a591c10c76dd961469ceeded3f2f3ad1f9d4ab440b6c207adb6bb05f19458c8775
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
*.swp
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 EmergeAdapt
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Ijonas Kisselbach
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Sqs2cb
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'sqs2cb'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install sqs2cb
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Ensure the following environment variables are set:
|
22
|
+
|
23
|
+
AWS_ACCESS_KEY=...
|
24
|
+
AWS_SECRET_ACCESS_KEY=...
|
25
|
+
CB_QUEUE=https://sqs.<region>.amazonaws.com/<account-id>/<caseblocks-queue>
|
26
|
+
CB_API_ENDPOINT=https://<subdomain>.caseblocks.com
|
27
|
+
CB_API_TOKEN=...
|
28
|
+
|
29
|
+
And run the daemon from the CLI
|
30
|
+
|
31
|
+
sqs2cb
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it ( https://github.com/[my-github-username]/sqs2cb/fork )
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/sqs2cb
ADDED
data/lib/sqs2cb.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require_relative "sqs2cb/version"
|
2
|
+
require 'aws-sdk-v1'
|
3
|
+
require 'json'
|
4
|
+
require 'rest_client'
|
5
|
+
require 'logger'
|
6
|
+
|
7
|
+
module Sqs2cb
|
8
|
+
class MessageHandler
|
9
|
+
def initialize
|
10
|
+
@awsAccessKeyId = ENV['AWS_ACCESS_KEY']
|
11
|
+
@awsSecretAccessKey = ENV['AWS_SECRET_ACCESS_KEY']
|
12
|
+
@caseBlocksAPIEndpoint = ENV['CB_API_ENDPOINT']
|
13
|
+
@caseBlocksAPIToken = ENV['CB_API_TOKEN']
|
14
|
+
@caseBlocksQueue = ENV['CB_QUEUE']
|
15
|
+
logfile = ENV['SQS2CB_LOGFILE_PATH'].nil? ? STDOUT : File.open(ENV['SQS2CB_LOGFILE_PATH'], 'a')
|
16
|
+
@logger = Logger.new logfile
|
17
|
+
@stop = false
|
18
|
+
|
19
|
+
raise RuntimeError, "Please ensure AWS_ACCESS_KEY is set." if @awsAccessKeyId.nil? or @awsAccessKeyId.empty?
|
20
|
+
raise RuntimeError, "Please ensure AWS_SECRET_ACCESS_KEY is set." if @awsSecretAccessKey.nil? or @awsSecretAccessKey.empty?
|
21
|
+
raise RuntimeError, "Please ensure CB_API_ENDPOINT is set." if @caseBlocksAPIEndpoint.nil? or @caseBlocksAPIEndpoint.empty?
|
22
|
+
raise RuntimeError, "Please ensure CB_API_TOKEN is set." if @caseBlocksAPIToken.nil? or @caseBlocksAPIToken.empty?
|
23
|
+
|
24
|
+
@logger.info "MessageHandler ready to transfer messages."
|
25
|
+
end
|
26
|
+
|
27
|
+
def stop
|
28
|
+
@stop = true
|
29
|
+
end
|
30
|
+
|
31
|
+
def transfer_messages
|
32
|
+
@logger.info "MessageHandler awaiting first message."
|
33
|
+
begin
|
34
|
+
sqs = AWS::SQS.new(region: 'us-east-1', access_key_id: @awsAccessKeyId, secret_access_key: @awsSecretAccessKey)
|
35
|
+
sqs.queues[@caseBlocksQueue].poll do |message|
|
36
|
+
handle_received_message(message)
|
37
|
+
return if @stop
|
38
|
+
end
|
39
|
+
rescue Exception => ex
|
40
|
+
@logger.error "Something cause an SQS failure."
|
41
|
+
@logger.error ex
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def handle_received_message(message)
|
46
|
+
@logger.info "Message received."
|
47
|
+
@logger.debug message.body
|
48
|
+
send_to_caseblocks(JSON.parse(message.body))
|
49
|
+
rescue JSON::ParserError => ex
|
50
|
+
# TODO needs some form of remote notification that an error occured.
|
51
|
+
@logger.error "Bad message format. Unable to deserialize message into JSON."
|
52
|
+
@logger.error ex
|
53
|
+
rescue Exception => ex
|
54
|
+
@logger.error "Something caused a message handling failure."
|
55
|
+
@logger.error ex
|
56
|
+
end
|
57
|
+
|
58
|
+
def send_to_caseblocks(msgHash)
|
59
|
+
@logger.info "Sending to CaseBlocks"
|
60
|
+
response = RestClient.post("#{@caseBlocksAPIEndpoint}/case_blocks/cases?auth_token=#{@caseBlocksAPIToken}", msgHash.to_json,
|
61
|
+
:content_type => :json,
|
62
|
+
:accept => :json,
|
63
|
+
"AUTH_TOKEN" => @caseBlocksAPIToken)
|
64
|
+
@logger.info "Received #{response.code} Location: #{response.headers[:location]}"
|
65
|
+
rescue RestClient::ExceptionWithResponse => ex
|
66
|
+
if ex.response.nil?
|
67
|
+
@logger.error "Received a bad response (null) from CaseBlocks. Re-raising."
|
68
|
+
raise ex
|
69
|
+
else
|
70
|
+
@logger.error "Received #{ex.response.code} bad response: #{ex.response.body}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/sqs2cb.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sqs2cb/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sqs2cb"
|
8
|
+
spec.version = Sqs2cb::VERSION
|
9
|
+
spec.authors = ["EmergeAdapt"]
|
10
|
+
spec.email = ["development@emergeadapt.com"]
|
11
|
+
spec.summary = %q{Grabs case-events from SQS and posts them to CaseBlocks.}
|
12
|
+
spec.description = %q{Basic WIP.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_dependency 'aws-sdk-v1', "~> 1.60.2"
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
class MessageHandlerTest < MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
ENV['CB_API_ENDPOINT'] = 'https://cb.local/'
|
6
|
+
ENV['CB_API_TOKEN'] = '1234'
|
7
|
+
end
|
8
|
+
def test_invalid_construction
|
9
|
+
ENV['AWS_ACCESS_KEY'] = nil
|
10
|
+
ENV['AWS_SECRET_ACCESS_KEY'] = nil
|
11
|
+
ENV['CB_API_ENDPOINT'] = nil
|
12
|
+
ENV['CB_API_TOKEN'] = nil
|
13
|
+
assert_raises(RuntimeError) { Sqs2cb::MessageHandler.new }
|
14
|
+
end
|
15
|
+
def test_valid_construction
|
16
|
+
ENV['AWS_ACCESS_KEY'] = 'access'
|
17
|
+
ENV['AWS_SECRET_ACCESS_KEY'] = 'secret'
|
18
|
+
refute_nil Sqs2cb::MessageHandler.new
|
19
|
+
end
|
20
|
+
def test_basic_sqs_connectivity
|
21
|
+
mh = Sqs2cb::MessageHandler.new
|
22
|
+
result = mh.transfer_messages
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sqs2cb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- EmergeAdapt
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: aws-sdk-v1
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.60.2
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.60.2
|
55
|
+
description: Basic WIP.
|
56
|
+
email:
|
57
|
+
- development@emergeadapt.com
|
58
|
+
executables:
|
59
|
+
- sqs2cb
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/sqs2cb
|
70
|
+
- lib/sqs2cb.rb
|
71
|
+
- lib/sqs2cb/version.rb
|
72
|
+
- sqs2cb.gemspec
|
73
|
+
- test/lib/sqs2cb/version_test.rb
|
74
|
+
- test/lib/sqs2cb_test.rb
|
75
|
+
- test/test_helper.rb
|
76
|
+
homepage: ''
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.2.2
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Grabs case-events from SQS and posts them to CaseBlocks.
|
100
|
+
test_files:
|
101
|
+
- test/lib/sqs2cb/version_test.rb
|
102
|
+
- test/lib/sqs2cb_test.rb
|
103
|
+
- test/test_helper.rb
|