ruby-sfn-local 0.1.8 → 0.1.11

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: 031c92b9bd2cca0fe86da9f393fd5c8881dbc04bee6c43b189585bdbbd9aa35a
4
- data.tar.gz: d6e51f7f87a2278c8f7f12781f1d795d3afb324265287744c0d030d53f70efd1
3
+ metadata.gz: 5f097b2ef985d1e4b6d146c9a094a2ae650dc2bbb13e7b36588a476308db867c
4
+ data.tar.gz: ee9fe4880d8244b63aecec10b02fafef4572af6ddae3aab3e2f2cf8f8fd70351
5
5
  SHA512:
6
- metadata.gz: 0dc87f86c63cd1fe745db17dab08afbd440b76b7d81a6f766b1cfae830acbaf7e475d480aff53a22dd8f015fc73c724951c9ee970ac76c09953970ab7bc768b3
7
- data.tar.gz: a31fbba0e5c16e68fd792f959ca88494f3abde0f9caea5a0ca7a1b38671b7ad9bcacb07d5eeeb580579f6f0d8e4626029f8095a4687214ded011b9692a87658a
6
+ metadata.gz: cffa8c52d646735bf6a4f396d0cbefb419f501e44ca936a531e47228fea6fc254d5239a0ec67d9606df99ce83d2aca768ef64439356f43061ed6d447a7fc944c
7
+ data.tar.gz: 4ed79cecd663ab17da02784f68478d15bf0544dda0cb7cc3fe275d3f262d69027367b5742f5b484b2aa44f245baa6c1a452ee6b5ebb8bfa2b0790b103d2ada84
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sfn
4
+ module MockMacros
5
+ module Sqs
6
+ def self.response(data)
7
+ data = [data] if data.is_a?(Hash)
8
+ data.map! do |val|
9
+ if val.key?(:error)
10
+ { Throw: { Error: val[:error], Cause: val[:cause] } }
11
+ else
12
+ val[:uuid] ||= SecureRandom.uuid
13
+ val[:sequence] ||= 10_000_000_000_000_003_000
14
+ { Return: { MessageId: val[:uuid], SequenceNumber: val[:sequence] } }
15
+ end
16
+ end
17
+ out = {}
18
+ data.each_with_index do |val, idx|
19
+ out[idx.to_s] = val
20
+ end
21
+ out
22
+ end
23
+ end
24
+ end
25
+ end
@@ -4,6 +4,7 @@ require 'sfn/mock_macros/lambda'
4
4
  require 'sfn/mock_macros/step_function'
5
5
  require 'sfn/mock_macros/api_gateway'
6
6
  require 'sfn/mock_macros/sns'
7
+ require 'sfn/mock_macros/sqs'
7
8
 
8
9
  module Sfn
9
10
  module MockMacros
@@ -11,6 +12,7 @@ module Sfn
11
12
  include StepFunction
12
13
  include ApiGateway
13
14
  include Sns
15
+ include Sqs
14
16
 
15
17
  def self.gateway_response(data)
16
18
  ApiGateway.response(data)
@@ -24,6 +26,10 @@ module Sfn
24
26
  Sns.response(data)
25
27
  end
26
28
 
29
+ def self.sqs_response(data)
30
+ Sqs.response(data)
31
+ end
32
+
27
33
  def self.step_function_response(data)
28
34
  StepFunction.response(data)
29
35
  end
@@ -9,7 +9,7 @@ module Sfn
9
9
  class StateMachine
10
10
  ROLE = 'arn:aws:iam::123456789012:role/DummyRole'
11
11
 
12
- attr_accessor :name, :definition, :arn, :executions, :execution_arn
12
+ attr_accessor :name, :path, :definition, :arn, :executions, :execution_arn
13
13
 
14
14
  def self.all
15
15
  Collection.instance.all.map { |sf| new(sf['name'], sf['stateMachineArn']) }
@@ -28,8 +28,9 @@ module Sfn
28
28
  end
29
29
 
30
30
  def initialize(name, arn = nil)
31
- self.name = name
32
- self.arn = arn || self.class.find_by_name(name)&.arn || create_state_machine
31
+ self.path = "#{Sfn.configuration.definition_path}/#{name}.json"
32
+ self.name = name.split("/").last
33
+ self.arn = arn || self.class.find_by_name(self.name)&.arn || create_state_machine
33
34
  self.executions = {}
34
35
  end
35
36
 
@@ -53,18 +54,17 @@ module Sfn
53
54
 
54
55
  def create_state_machine
55
56
  self.arn = AwsCli.run('stepfunctions', 'create-state-machine',
56
- { definition: load_definition(name), name: name, 'role-arn': ROLE }, 'stateMachineArn')
57
+ { definition: load_definition, name: name, 'role-arn': ROLE }, 'stateMachineArn')
57
58
  raise Sf::DefinitionError if arn.empty?
58
59
 
59
60
  Collection.instance.add(to_hash)
60
61
  arn
61
62
  end
62
63
 
63
- def load_definition(_name)
64
+ def load_definition
64
65
  local_definition_path = Tempfile.new(['name', '.json']).path
65
- remote_definition_path = "#{Sfn.configuration.definition_path}/#{name}.json"
66
-
67
- definition = File.read(remote_definition_path)
66
+
67
+ definition = File.read(self.path)
68
68
  local_definition = definition.gsub(/"MaxConcurrency": [0-9]+/, '"MaxConcurrency": 1')
69
69
 
70
70
  File.open(local_definition_path, 'w') { |file| file.puts local_definition }
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.8
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gianni Mazza
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-13 00:00:00.000000000 Z
11
+ date: 2022-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-release
@@ -69,6 +69,7 @@ files:
69
69
  - lib/sfn/mock_macros/api_gateway.rb
70
70
  - lib/sfn/mock_macros/lambda.rb
71
71
  - lib/sfn/mock_macros/sns.rb
72
+ - lib/sfn/mock_macros/sqs.rb
72
73
  - lib/sfn/mock_macros/step_function.rb
73
74
  - lib/sfn/state_machine.rb
74
75
  - lib/string.rb