ruby-sfn-local 0.1.26 → 0.1.27

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff99b4bae62c62426875ba1648587694c067f1a6d75e93141f3db3cd190d7d77
4
- data.tar.gz: eba01eca2c917702c83d9d41f76059895cda06e748789f0612f30ee84463f6a3
3
+ metadata.gz: 1d6385a2c314fd825107942b944d72db015669637a51880c03eac7238dcb4abd
4
+ data.tar.gz: 83058e9ce9ad7d6b2ec6e7c59b753b886c1686da9c4a451c886d44574b27d467
5
5
  SHA512:
6
- metadata.gz: 4c4aaa0b42443f7635d5bbd799fe53170f0ca1aea60025966242a5dfefdc7bbadde4d1e28367344b1c344975e3ec7fad1e2dde8aab14ea22270e4d29e0d090b1
7
- data.tar.gz: f3486082711ed0e33608fecd9072c3cee367ccd8ec6eac75ddfcaffeae0d17cdd4bf08d4dc70de944c8880e6ccd8e410cca822671a5815d84c399ec8414fa401
6
+ metadata.gz: fedfb55e9bdc340b3f26f9ed56dd721a3631d33ee869722077a7cc28fdce0ee5def60a7537be7c02fd3deb071f0f48a077944aa40a5c422f90a2051b606c9cd3
7
+ data.tar.gz: f31002ca1116c87a48f9ab8c429d217c52c33929c7a5e046e1c45e468321d9f59357da11c8a1026c9a248aafe15709ff857cde0f06e292629c034887c41b4f80
data/lib/sfn/execution.rb CHANGED
@@ -11,20 +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("stateMachine","execution")}:#{self.uuid}"
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
20
  out = AwsCli.run('stepfunctions', 'start-execution',
21
- { name: uuid,
22
- 'state-machine': "#{state_machine.arn}##{test_case}",
23
- input: "'#{input.to_json}'"
24
- })
21
+ { name: uuid,
22
+ 'state-machine': "#{state_machine.arn}##{test_case}",
23
+ input: "'#{input.to_json}'" })
25
24
  decoded = JSON.parse(out)
26
- self.arn = decoded["executionArn"]
27
- self.start_date = decoded["startDate"].gsub("000+00:00", "Z")
25
+ self.arn = decoded['executionArn']
26
+ self.start_date = decoded['startDate'].gsub('000+00:00', 'Z')
28
27
  self.output, self.profile = ExecutionLog.parse(arn, dry_run)
29
28
  self
30
29
  end
@@ -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
- raise ExecutionError.new(event['executionFailedEventDetails']['cause'],
64
- event['executionFailedEventDetails']['error'],
65
- events_json) unless dry_run
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
 
@@ -33,7 +33,7 @@ module Sfn
33
33
  Sqs.response(data)
34
34
  end
35
35
 
36
- def self.step_function_response(data, optimised = false)
36
+ def self.step_function_response(data, _optimised = false)
37
37
  StepFunction.response(data)
38
38
  end
39
39
 
@@ -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("ItemProcessor", "Iterator")
79
- local_definition = local_definition.gsub("ItemSelector", "Parameters")
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.26
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-28 00:00:00.000000000 Z
11
+ date: 2023-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-release