architect-functions 0.2.0 → 0.3.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 +4 -4
- data/lib/architect/events.rb +18 -9
- data/lib/architect/http.rb +2 -0
- data/lib/architect/queues.rb +20 -13
- data/lib/architect/tables.rb +12 -3
- data/lib/architect/ws.rb +19 -12
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d67b7204ebb63764681b926a6deb538500ba3dc7f01403d3f472a007ef4f5d3
|
4
|
+
data.tar.gz: 7c54f6b0f1ce9abd083bb246dc7725b10c8e1aaa19c87478e9d63a4cf3cff828
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d302e7bc5785489422098ff7066c6aeeb77b146b74b8a18a985ecdd94367d244764c503dd1ec71647a75d88637a1c6ba93a126275ed68a5a74c527eac95b713b
|
7
|
+
data.tar.gz: 1b193694eb3ff53b532af908f832fc597d4e73fbfff94824048106def52e3616174955246778a1d649046f888963d219652a3f9f8547a11d58a4eae9b3bb1700
|
data/lib/architect/events.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'aws-sdk-sns'
|
2
|
+
require 'net/http'
|
2
3
|
require 'json'
|
4
|
+
|
3
5
|
require_relative 'reflect'
|
4
6
|
|
5
7
|
module Arc
|
@@ -7,15 +9,22 @@ module Arc
|
|
7
9
|
##
|
8
10
|
# publish a message to an SNS Topic
|
9
11
|
#
|
10
|
-
def self.publish(
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
def self.publish(name:, payload:)
|
13
|
+
if ENV['NODE_ENV'] == 'testing'
|
14
|
+
headers = {'content-type':'application/json'}
|
15
|
+
uri = URI('https://localhost:3334/events')
|
16
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
17
|
+
req = Net::HTTP::Post.new(uri.path, headers)
|
18
|
+
req.body = {'name': name, 'payload': payload}.to_json
|
19
|
+
http.request(req).read_body
|
20
|
+
else
|
21
|
+
arc = Arc.reflect
|
22
|
+
arn = arc['events'][name]
|
23
|
+
sns = Aws::SNS::Client.new
|
24
|
+
sns.publish({topic_arn: arn, message: JSON.generate(payload)})
|
25
|
+
end
|
26
|
+
rescue => e
|
27
|
+
"arc.events.publish failed #{e}"
|
19
28
|
end
|
20
29
|
end
|
21
30
|
end
|
data/lib/architect/http.rb
CHANGED
data/lib/architect/queues.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'aws-sdk-sqs'
|
2
|
+
require 'net/http'
|
2
3
|
require 'json'
|
4
|
+
|
3
5
|
require_relative 'reflect'
|
4
6
|
|
5
7
|
module Arc
|
@@ -7,19 +9,24 @@ module Arc
|
|
7
9
|
##
|
8
10
|
# publish a message to an SQS Queue
|
9
11
|
#
|
10
|
-
def self.publish(
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
12
|
+
def self.publish(name:, payload:)
|
13
|
+
if ENV['NODE_ENV'] == 'testing'
|
14
|
+
headers = {'content-type':'application/json'}
|
15
|
+
uri = URI('https://localhost:3334/queues')
|
16
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
17
|
+
req = Net::HTTP::Post.new(uri.path, headers)
|
18
|
+
req.body = {'name': name, 'payload': payload}.to_json
|
19
|
+
http.request(req).read_body
|
20
|
+
else
|
21
|
+
arc = Arc.reflect
|
22
|
+
url = arc['queues'][name]
|
23
|
+
sqs = Aws::SQS::Client.new
|
24
|
+
sqs.send_message({
|
25
|
+
queue_url: url,
|
26
|
+
delay_seconds: 0,
|
27
|
+
message_body: JSON.generate(payload)
|
28
|
+
})
|
29
|
+
end
|
23
30
|
end
|
24
31
|
end
|
25
32
|
end
|
data/lib/architect/tables.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'aws-sdk-dynamodb'
|
2
|
+
|
1
3
|
require_relative 'reflect'
|
2
4
|
|
3
5
|
module Arc
|
@@ -5,9 +7,16 @@ module Arc
|
|
5
7
|
##
|
6
8
|
# returns the physicalID for the given table name
|
7
9
|
#
|
8
|
-
def self.name(
|
9
|
-
|
10
|
-
|
10
|
+
def self.name(tablename)
|
11
|
+
if ENV['NODE_ENV'] == 'testing'
|
12
|
+
tmp = "staging-#{tablename}"
|
13
|
+
db = Aws::DynamoDB::Resource.new :endpoint=> 'http://localhost:5000'
|
14
|
+
tbl = db.tables().detect {|e| e.name.include?(tmp)}
|
15
|
+
tbl.name
|
16
|
+
else
|
17
|
+
arc = Arc.reflect
|
18
|
+
arc['tables'][tablename]
|
19
|
+
end
|
11
20
|
end
|
12
21
|
end
|
13
22
|
end
|
data/lib/architect/ws.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'aws-sdk-apigateway'
|
2
|
+
require 'net/http'
|
2
3
|
require 'json'
|
4
|
+
|
3
5
|
require_relative 'reflect'
|
4
6
|
|
5
7
|
module Arc
|
@@ -7,18 +9,23 @@ module Arc
|
|
7
9
|
##
|
8
10
|
# send a message to a web socket
|
9
11
|
#
|
10
|
-
def self.send(
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
12
|
+
def self.send(id:, payload:)
|
13
|
+
if ENV['NODE_ENV'] == 'testing'
|
14
|
+
headers = {'content-type':'application/json'}
|
15
|
+
uri = URI('https://localhost:3333/__arc')
|
16
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
17
|
+
req = Net::HTTP::Post.new(uri.path, headers)
|
18
|
+
req.body = payload.to_json
|
19
|
+
http.request(req).read_body
|
20
|
+
else
|
21
|
+
arc = Arc.reflect
|
22
|
+
url = arc['ws']['https']
|
23
|
+
api = Aws::ApiGatewayManagementApi::Client.new({endpoint: url})
|
24
|
+
api.postToConnection({
|
25
|
+
connection_id: id,
|
26
|
+
data: JSON.stringify(payload)
|
27
|
+
})
|
28
|
+
end
|
22
29
|
end
|
23
30
|
end
|
24
31
|
end
|