ruby-sfn-local 0.1.24 → 0.1.27
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sfn/execution.rb +9 -8
- data/lib/sfn/execution_log.rb +6 -4
- data/lib/sfn/mock_macros.rb +1 -1
- data/lib/sfn/state_machine.rb +14 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d6385a2c314fd825107942b944d72db015669637a51880c03eac7238dcb4abd
|
4
|
+
data.tar.gz: 83058e9ce9ad7d6b2ec6e7c59b753b886c1686da9c4a451c886d44574b27d467
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fedfb55e9bdc340b3f26f9ed56dd721a3631d33ee869722077a7cc28fdce0ee5def60a7537be7c02fd3deb071f0f48a077944aa40a5c422f90a2051b606c9cd3
|
7
|
+
data.tar.gz: f31002ca1116c87a48f9ab8c429d217c52c33929c7a5e046e1c45e468321d9f59357da11c8a1026c9a248aafe15709ff857cde0f06e292629c034887c41b4f80
|
data/lib/sfn/execution.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Sfn
|
4
4
|
class Execution
|
5
|
-
attr_accessor :id, :uuid, :state_machine, :test_case, :arn, :output, :profile
|
5
|
+
attr_accessor :id, :start_date, :uuid, :state_machine, :test_case, :arn, :output, :profile
|
6
6
|
|
7
7
|
def self.call(state_machine, test_case, mock_data, input, dry_run = false)
|
8
8
|
new(state_machine, test_case).exec(mock_data, input, dry_run)
|
@@ -11,18 +11,19 @@ module Sfn
|
|
11
11
|
def initialize(state_machine, test_case)
|
12
12
|
self.uuid = SecureRandom.uuid
|
13
13
|
self.state_machine = state_machine
|
14
|
-
self.id = "#{self.state_machine.arn.gsub(
|
14
|
+
self.id = "#{self.state_machine.arn.gsub('stateMachine', 'execution')}:#{uuid}"
|
15
15
|
self.test_case = test_case.camelize
|
16
16
|
end
|
17
17
|
|
18
18
|
def exec(mock_data, input, dry_run = false)
|
19
19
|
MockData.write_context(state_machine.name, test_case, mock_data)
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
out = AwsCli.run('stepfunctions', 'start-execution',
|
21
|
+
{ name: uuid,
|
22
|
+
'state-machine': "#{state_machine.arn}##{test_case}",
|
23
|
+
input: "'#{input.to_json}'" })
|
24
|
+
decoded = JSON.parse(out)
|
25
|
+
self.arn = decoded['executionArn']
|
26
|
+
self.start_date = decoded['startDate'].gsub('000+00:00', 'Z')
|
26
27
|
self.output, self.profile = ExecutionLog.parse(arn, dry_run)
|
27
28
|
self
|
28
29
|
end
|
data/lib/sfn/execution_log.rb
CHANGED
@@ -60,10 +60,12 @@ module Sfn
|
|
60
60
|
def error(events_json = '{}', dry_run = false)
|
61
61
|
return if event['executionFailedEventDetails'].nil?
|
62
62
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
63
|
+
unless dry_run
|
64
|
+
raise ExecutionError.new(event['executionFailedEventDetails']['cause'],
|
65
|
+
event['executionFailedEventDetails']['error'],
|
66
|
+
events_json)
|
67
|
+
end
|
68
|
+
|
67
69
|
event['executionFailedEventDetails']
|
68
70
|
end
|
69
71
|
|
data/lib/sfn/mock_macros.rb
CHANGED
data/lib/sfn/state_machine.rb
CHANGED
@@ -9,10 +9,10 @@ module Sfn
|
|
9
9
|
class StateMachine
|
10
10
|
ROLE = 'arn:aws:iam::123456789012:role/DummyRole'
|
11
11
|
|
12
|
-
attr_accessor :name, :path, :definition, :arn, :executions, :execution_arn
|
12
|
+
attr_accessor :name, :path, :definition, :arn, :variables, :executions, :execution_arn
|
13
13
|
|
14
14
|
def self.all
|
15
|
-
Collection.instance.all.map { |sf| new(sf['name'], sf['stateMachineArn']) }
|
15
|
+
Collection.instance.all.map { |sf| new(sf['name'], nil, sf['stateMachineArn']) }
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.destroy_all
|
@@ -27,9 +27,10 @@ module Sfn
|
|
27
27
|
all.find { |sf| sf.arn == arn }
|
28
28
|
end
|
29
29
|
|
30
|
-
def initialize(name, arn = nil)
|
30
|
+
def initialize(name, variables = {}, arn = nil)
|
31
31
|
self.path = "#{Sfn.configuration.definition_path}/#{name}.json"
|
32
32
|
self.name = name.split('/').last
|
33
|
+
self.variables = variables
|
33
34
|
self.arn = arn || self.class.find_by_name(self.name)&.arn || create_state_machine
|
34
35
|
self.executions = {}
|
35
36
|
end
|
@@ -43,7 +44,7 @@ module Sfn
|
|
43
44
|
def dry_run(mock_data = {}, input = {}, test_name = nil)
|
44
45
|
execution = run(mock_data, input, test_name, true)
|
45
46
|
end
|
46
|
-
|
47
|
+
|
47
48
|
def run(mock_data = {}, input = {}, test_name = nil, dry_run = false)
|
48
49
|
test_name ||= OpenSSL::Digest::SHA512.digest(mock_data.merge({ input: input }).to_json)
|
49
50
|
executions[test_name] ||= Execution.call(self, test_name, mock_data, input, dry_run)
|
@@ -74,13 +75,16 @@ module Sfn
|
|
74
75
|
local_definition = local_definition.gsub(/"Type": "Wait"/, '"Type": "Pass"')
|
75
76
|
local_definition = local_definition.gsub(/"Seconds": [0-9]+,*/, '')
|
76
77
|
local_definition = local_definition.gsub(/"Timestamp": "[0-9\-T:+]+",*/, '')
|
77
|
-
local_definition = local_definition.gsub(/"TimestampPath": "[
|
78
|
-
local_definition = local_definition.gsub(
|
79
|
-
local_definition = local_definition.gsub(
|
80
|
-
local_definition = local_definition.gsub(/"ProcessorConfig":\s*{[\s"[A-Za-z:,]]+},*/,
|
81
|
-
local_definition = local_definition.gsub(/"Label": "[A-Za-z]+",*/,
|
78
|
+
local_definition = local_definition.gsub(/"TimestampPath": "[^"]+",*/, '')
|
79
|
+
local_definition = local_definition.gsub('ItemProcessor', 'Iterator')
|
80
|
+
local_definition = local_definition.gsub('ItemSelector', 'Parameters')
|
81
|
+
local_definition = local_definition.gsub(/"ProcessorConfig":\s*{[\s"[A-Za-z:,]]+},*/, '')
|
82
|
+
local_definition = local_definition.gsub(/"Label": "[A-Za-z]+",*/, '')
|
82
83
|
local_definition = local_definition.gsub(/,[\s\n]+\}/, "\n}")
|
83
|
-
|
84
|
+
local_definition = local_definition.gsub(/(\${[a-z_]+})/) do |variable|
|
85
|
+
key = variable.gsub(/[${}]/, '')
|
86
|
+
variables[key]
|
87
|
+
end
|
84
88
|
File.open(local_definition_path, 'w') { |file| file.puts local_definition }
|
85
89
|
"file://#{local_definition_path}"
|
86
90
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-sfn-local
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.27
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gianni Mazza
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02
|
11
|
+
date: 2023-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-release
|