opswalrus 1.0.75 → 1.0.77
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/opswalrus/interaction_handlers.rb +14 -7
- data/lib/opswalrus/patches.rb +11 -0
- data/lib/opswalrus/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: c19f0877541baca3fa57340c300382e8819e56d9bfc2225ca1f4a888c0df9fb6
|
4
|
+
data.tar.gz: 279d36f24ff0861115ca06e4201d907c84082b764f308faceee9c9c4420a2ef2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54b958066621d691e460702e41388b76c34c3a9cc379f1fe431e52f70509c581a81f8d1a9d7c11ea15f5d5406c5862659534b5c7b18aa086494e0ac3a2b5c564
|
7
|
+
data.tar.gz: 0771e13131d4db57fdc9f730ed80a286aaaf80409b35cdbdfe2091c0e80b35d321ccba1fbad6c89a6ce28438207330bbd944833618aef762ab42fb6ab7b98641
|
data/Gemfile.lock
CHANGED
@@ -6,7 +6,7 @@ module OpsWalrus
|
|
6
6
|
STANDARD_SUDO_PASSWORD_PROMPT = /\[sudo\] password for .*?:\s*/
|
7
7
|
STANDARD_SSH_PASSWORD_PROMPT = /.*?@.*?'s password:\s*/
|
8
8
|
|
9
|
-
attr_accessor :input_mappings # Hash[ String | Regex => String ]
|
9
|
+
attr_accessor :input_mappings # Hash[ String | Regex => (String | Proc) ]
|
10
10
|
|
11
11
|
def initialize(mapping)
|
12
12
|
@input_mappings = mapping
|
@@ -39,7 +39,7 @@ module OpsWalrus
|
|
39
39
|
# temporarily adds the specified input mapping to the interaction handler while the given block is being evaluated
|
40
40
|
# when the given block returns, then the temporary mapping is removed from the interaction handler
|
41
41
|
#
|
42
|
-
# mapping : Hash[ String | Regex => String ] | Nil
|
42
|
+
# mapping : Hash[ String | Regex => (String | Proc) ] | Nil
|
43
43
|
def with_mapping(mapping = nil, sudo_password: nil, ops_sudo_password: nil, inherit_existing_mappings: true)
|
44
44
|
new_mapping = inherit_existing_mappings ? @input_mappings : {}
|
45
45
|
|
@@ -67,7 +67,7 @@ module OpsWalrus
|
|
67
67
|
|
68
68
|
# adds the specified input mapping to the interaction handler
|
69
69
|
#
|
70
|
-
# mapping : Hash[ String | Regex => String ]
|
70
|
+
# mapping : Hash[ String | Regex => (String | Proc) ]
|
71
71
|
def add_mapping(mapping)
|
72
72
|
@input_mappings.merge!(mapping)
|
73
73
|
end
|
@@ -84,13 +84,20 @@ module OpsWalrus
|
|
84
84
|
# This method returns the data that is emitted to the response channel as a result of having processed the output
|
85
85
|
# from a command that the interaction handler was expecting.
|
86
86
|
def on_data(_command, stream_name, data, response_channel)
|
87
|
-
response_data =
|
88
|
-
|
89
|
-
|
87
|
+
response_data = @input_mappings.find_map do |pattern, mapped_output_value|
|
88
|
+
pattern = pattern.is_a?(String) ? Regexp.new(Regexp.escape(pattern)) : pattern
|
89
|
+
if pattern_match = data.match(pattern) # pattern_match : MatchData | Nil
|
90
|
+
case mapped_output_value
|
91
|
+
when Proc, Method
|
92
|
+
mapped_output_value.call(pattern_match)
|
93
|
+
when String
|
94
|
+
mapped_output_value
|
95
|
+
end
|
96
|
+
end
|
90
97
|
end
|
91
98
|
|
92
99
|
if response_data.nil?
|
93
|
-
trace(Style.red("No interaction handler mapping for #{stream_name}:
|
100
|
+
trace(Style.red("No interaction handler mapping for #{stream_name}: `#{data}` so no response was sent"))
|
94
101
|
else
|
95
102
|
debug(Style.cyan("Handling #{stream_name} message #{data}"))
|
96
103
|
debug(Style.cyan("Sending response #{response_data}"))
|
data/lib/opswalrus/patches.rb
CHANGED
@@ -42,6 +42,17 @@ class Hash
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
module Enumerable
|
46
|
+
# calls the block with successive elements; returns the first truthy object returned by the block
|
47
|
+
def find_map(&block)
|
48
|
+
each do |element|
|
49
|
+
mapped_value = block.call(element)
|
50
|
+
return mapped_value if mapped_value
|
51
|
+
end
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
45
56
|
class Array
|
46
57
|
def has_key?(key)
|
47
58
|
key.is_a?(Integer) && key < size
|
data/lib/opswalrus/version.rb
CHANGED