simplerubysteps 0.0.9 → 0.0.10
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/function.rb +25 -1
- data/lib/simplerubysteps/cloudformation.rb +41 -2
- data/lib/simplerubysteps/dsl.rb +21 -0
- data/lib/simplerubysteps/model.rb +14 -1
- data/lib/simplerubysteps/tool.rb +37 -0
- data/lib/simplerubysteps/version.rb +1 -1
- 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: cbf93121e4c57f68c9353ad4eda79f37ad26b5208828ac25ba4d2ea59ff30cf3
|
4
|
+
data.tar.gz: bfc81ca54385937d13a69cd6a6e38aa303dd146fc28c98791357b62e80577def
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5bb0d06cefb48b94ea846f24838f8cc90a915abe1ca7f8806b2f0d8f4ec4a60edc5a25c33f65d90eb81603dd70a3390f38d27e8a036ccbd70bf0a94dcc47006
|
7
|
+
data.tar.gz: cc120cf28d4ba8c4f8e8bb85c0a26245c9f1027e113d2a42aa232dafa0ffc0f903ce2ae8f17f3d22f7fd0aa7aa79581bd30dac596dfb7c060cbbec0ecf6d2275
|
data/lib/function.rb
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
require "simplerubysteps"
|
2
2
|
|
3
|
+
if ENV["QUEUE"]
|
4
|
+
require "aws-sdk-sqs"
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
class QueueClient
|
8
|
+
def initialize(sqs_client, queue)
|
9
|
+
@sqs_client = sqs_client
|
10
|
+
@queue = queue
|
11
|
+
end
|
12
|
+
|
13
|
+
def send(data)
|
14
|
+
@sqs_client.send_message(queue_url: @queue, message_body: data.to_json)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
$queue_client = QueueClient.new(Aws::SQS::Client.new, ENV["QUEUE"])
|
19
|
+
else
|
20
|
+
$queue_client = nil
|
21
|
+
end
|
22
|
+
|
3
23
|
require "./workflow.rb"
|
4
24
|
|
5
25
|
include Simplerubysteps
|
@@ -10,7 +30,11 @@ def handler(event:, context:)
|
|
10
30
|
puts context.inspect if ENV["DEBUG"]
|
11
31
|
|
12
32
|
if event["Token"]
|
13
|
-
$
|
33
|
+
unless $queue_client
|
34
|
+
$sm.states[ENV["task"].to_sym].perform_action event["Input"], event["Token"]
|
35
|
+
else
|
36
|
+
$sm.states[ENV["task"].to_sym].perform_queue_action event["Input"], event["Token"], $queue_client
|
37
|
+
end
|
14
38
|
else
|
15
39
|
$sm.states[ENV["task"].to_sym].perform_action event["Input"]
|
16
40
|
end
|
@@ -38,8 +38,11 @@ Resources:
|
|
38
38
|
Runtime: ruby2.7
|
39
39
|
Environment:
|
40
40
|
Variables:
|
41
|
-
<% resource
|
42
|
-
|
41
|
+
<% if resource["queue"] %>
|
42
|
+
QUEUE: !Ref MyQueue<%= index %>
|
43
|
+
<% end %>
|
44
|
+
<% resource["env"].each do |k, v| %>
|
45
|
+
<%= k %>: <%= v.inspect %>
|
43
46
|
<% end %>
|
44
47
|
LogGroup<%= index %>:
|
45
48
|
Type: AWS::Logs::LogGroup
|
@@ -68,6 +71,32 @@ Resources:
|
|
68
71
|
- logs:CreateLogStream
|
69
72
|
- logs:PutLogEvents
|
70
73
|
Resource: arn:aws:logs:*:*:*
|
74
|
+
<% if resource["iam_permissions"] %>
|
75
|
+
MyCustomPolicy<%= index %>:
|
76
|
+
Type: AWS::IAM::Policy
|
77
|
+
Properties:
|
78
|
+
PolicyName: custom
|
79
|
+
Roles:
|
80
|
+
- !Ref MyLambdaRole<%= index %>
|
81
|
+
PolicyDocument: <%= resource["iam_permissions"].inspect %>
|
82
|
+
<% end %>
|
83
|
+
<% if resource["queue"] %>
|
84
|
+
MyQueue<%= index %>:
|
85
|
+
Type: AWS::SQS::Queue
|
86
|
+
MyQueuePolicy<%= index %>:
|
87
|
+
Type: AWS::IAM::Policy
|
88
|
+
Properties:
|
89
|
+
PolicyName: queue
|
90
|
+
Roles:
|
91
|
+
- !Ref MyLambdaRole<%= index %>
|
92
|
+
PolicyDocument:
|
93
|
+
Version: '2012-10-17'
|
94
|
+
Statement:
|
95
|
+
- Effect: Allow
|
96
|
+
Action:
|
97
|
+
- 'sqs:SendMessage'
|
98
|
+
Resource: !GetAtt MyQueue<%= index %>.Arn
|
99
|
+
<% end %>
|
71
100
|
<% end %>
|
72
101
|
<% end %>
|
73
102
|
|
@@ -135,6 +164,16 @@ Outputs:
|
|
135
164
|
StepFunctionsRoleARN:
|
136
165
|
Value: !GetAtt StepFunctionsRole.Arn
|
137
166
|
<% end %>
|
167
|
+
|
168
|
+
<% if resources[:functions] %>
|
169
|
+
<% resources[:functions].each_with_index do |resource, index| %>
|
170
|
+
<% if resource["queue"] %>
|
171
|
+
<%= resource["env"]["task"] %>Queue:
|
172
|
+
Value: !Ref MyQueue<%= index %>
|
173
|
+
<% end %>
|
174
|
+
<% end %>
|
175
|
+
<% end %>
|
176
|
+
|
138
177
|
YAML
|
139
178
|
|
140
179
|
def self.cloudformation_yaml(resources)
|
data/lib/simplerubysteps/dsl.rb
CHANGED
@@ -28,6 +28,23 @@ module Simplerubysteps
|
|
28
28
|
$tasks.pop
|
29
29
|
end
|
30
30
|
|
31
|
+
def sqs_callback(name)
|
32
|
+
t = $sm.add Callback.new(name)
|
33
|
+
t.queue = true
|
34
|
+
|
35
|
+
$tasks.last.next = t if $tasks.last
|
36
|
+
|
37
|
+
$tasks.push t
|
38
|
+
action do |input, token, queue_client|
|
39
|
+
queue_client.send({
|
40
|
+
input: input,
|
41
|
+
token: token,
|
42
|
+
})
|
43
|
+
end
|
44
|
+
yield if block_given?
|
45
|
+
$tasks.pop
|
46
|
+
end
|
47
|
+
|
31
48
|
def action(&action_block)
|
32
49
|
$tasks.last.action &action_block
|
33
50
|
end
|
@@ -55,6 +72,10 @@ module Simplerubysteps
|
|
55
72
|
choice.default = state
|
56
73
|
end
|
57
74
|
|
75
|
+
def iam_permissions(permissions)
|
76
|
+
$tasks.last.iam_permissions = permissions
|
77
|
+
end
|
78
|
+
|
58
79
|
def choice(name)
|
59
80
|
t = $sm.add Choice.new(name)
|
60
81
|
|
@@ -37,7 +37,11 @@ module Simplerubysteps
|
|
37
37
|
states.each do |name, state|
|
38
38
|
if state.is_a? Task or state.is_a? Callback
|
39
39
|
data.push({
|
40
|
-
|
40
|
+
env: {
|
41
|
+
task: name,
|
42
|
+
},
|
43
|
+
iam_permissions: state.iam_permissions,
|
44
|
+
queue: ((state.is_a? Callback) ? state.queue : nil),
|
41
45
|
})
|
42
46
|
end
|
43
47
|
end
|
@@ -77,6 +81,8 @@ module Simplerubysteps
|
|
77
81
|
end
|
78
82
|
|
79
83
|
class Task < State
|
84
|
+
attr_accessor :iam_permissions
|
85
|
+
|
80
86
|
def initialize(name)
|
81
87
|
super
|
82
88
|
@dict[:Type] = "Task"
|
@@ -115,6 +121,9 @@ module Simplerubysteps
|
|
115
121
|
end
|
116
122
|
|
117
123
|
class Callback < State
|
124
|
+
attr_accessor :iam_permissions
|
125
|
+
attr_accessor :queue
|
126
|
+
|
118
127
|
def initialize(name)
|
119
128
|
super
|
120
129
|
@dict[:Type] = "Task"
|
@@ -136,6 +145,10 @@ module Simplerubysteps
|
|
136
145
|
def perform_action(input, token)
|
137
146
|
@action_block.call(input, token) if @action_block
|
138
147
|
end
|
148
|
+
|
149
|
+
def perform_queue_action(input, token, queue_client)
|
150
|
+
@action_block.call(input, token, queue_client) if @action_block
|
151
|
+
end
|
139
152
|
end
|
140
153
|
|
141
154
|
class ChoiceItem
|
data/lib/simplerubysteps/tool.rb
CHANGED
@@ -402,6 +402,25 @@ module Simplerubysteps
|
|
402
402
|
response
|
403
403
|
end
|
404
404
|
|
405
|
+
def stack_output(version, optional_output)
|
406
|
+
stack = nil
|
407
|
+
if version
|
408
|
+
stack = versioned_stack_name_from_current_dir(version)
|
409
|
+
else
|
410
|
+
stack = most_recent_stack_with_prefix unversioned_stack_name_from_current_dir
|
411
|
+
end
|
412
|
+
raise "State Machine is not deployed" unless stack
|
413
|
+
|
414
|
+
current_stack_outputs = stack_outputs(stack)
|
415
|
+
raise "State Machine is not deployed" unless current_stack_outputs
|
416
|
+
|
417
|
+
if optional_output
|
418
|
+
puts current_stack_outputs[optional_output]
|
419
|
+
else
|
420
|
+
puts current_stack_outputs.to_json
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|
405
424
|
def start(wait, input, version)
|
406
425
|
stack = nil
|
407
426
|
if version
|
@@ -539,6 +558,22 @@ module Simplerubysteps
|
|
539
558
|
options[:token] = value
|
540
559
|
end
|
541
560
|
|
561
|
+
opts.on("-h", "--help", "Display this help message") do
|
562
|
+
puts opts
|
563
|
+
exit
|
564
|
+
end
|
565
|
+
end,
|
566
|
+
"stack" => OptionParser.new do |opts|
|
567
|
+
opts.banner = "Usage: #{$0} stack [options]"
|
568
|
+
|
569
|
+
opts.on("--output VALUE", "Stack output") do |value|
|
570
|
+
options[:output] = value
|
571
|
+
end
|
572
|
+
|
573
|
+
opts.on("--version VALUE", "fix version (\"latest\" per default)") do |value|
|
574
|
+
options[:version] = value
|
575
|
+
end
|
576
|
+
|
542
577
|
opts.on("-h", "--help", "Display this help message") do
|
543
578
|
puts opts
|
544
579
|
exit
|
@@ -587,6 +622,8 @@ module Simplerubysteps
|
|
587
622
|
log options[:extract_pattern], options[:version]
|
588
623
|
elsif options[:command] == "task-success"
|
589
624
|
send_task_success options[:token], options[:input]
|
625
|
+
elsif options[:command] == "stack"
|
626
|
+
stack_output options[:version], options[:output]
|
590
627
|
elsif options[:command] == "destroy"
|
591
628
|
if options[:destroy_all]
|
592
629
|
destroy(nil)
|