Class: Dopi::Command::Winrm::FileContains
Instance Attribute Summary
#hash, #is_verify_command, #node
Instance Method Summary
collapse
#check_exit_code, #expect_exit_codes, #validate_exit_code
#basic_auth_only, #ca_trust_path, #disable_sspi, #endpoint, #operation_timeout, #port, #ssl, #supported_credential_types, #validate_winrm, #winrm, #winrm_command, #winrm_powershell_command
#credentials, #validate_credentials
create_plugin_instance, delete_plugin_default, delete_plugin_defaults, inherited, #initialize, #load_state, #merged_hash, #meta_run, #meta_valid?, plugin_defaults, set_plugin_defaults, #state_hash, wipe_plugin_defaults
Methods included from State
#delete_on_signal, #on_signal, #reset_signals, #send_signal, #signal_procs, #signals, #state, #state_add_child, #state_auto_evaluate_children, #state_auto_evaluate_children=, #state_changed, #state_children, #state_children_done?, #state_children_failed?, #state_children_partial?, #state_children_ready?, #state_children_running?, #state_children_running_noop?, #state_children_starting?, #state_done?, #state_fail, #state_failed?, #state_finish, #state_partial?, #state_ready, #state_ready?, #state_reset, #state_reset_with_children, #state_run, #state_run_noop, #state_running?, #state_running_noop?, #state_start, #state_starting?, #to_yaml_properties, #update, #update_mutex
Constructor Details
This class inherits a constructor from Dopi::Command
Instance Method Details
#command_string ⇒ Object
28
29
30
|
# File 'lib/dopi/command/winrm/file_contains.rb', line 28
def command_string
"if(-not(Select-String -Pattern #{pattern} -Path '#{file}' -Quiet)) { exit 1 }"
end
|
#file ⇒ Object
32
33
34
35
|
# File 'lib/dopi/command/winrm/file_contains.rb', line 32
def file
@file ||= file_valid? ?
hash[:file] : nil
end
|
#file_valid? ⇒ Boolean
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/dopi/command/winrm/file_contains.rb', line 42
def file_valid?
hash[:file] or
raise CommandParsingError, "Plugin #{name}: The key 'file' needs to be specified"
begin
hash[:file][/[a-zA-Z]+:\\/] or hash[:file][/\\\\\w+/] or
raise CommandParsingError, "Plugin #{name}: The path for 'file' has to be absolute"
rescue ArgumentError => e
raise CommandParsingError, "Plugin #{name}: The value in 'file' is not a valid file path: #{e.message}"
end
end
|
#pattern ⇒ Object
37
38
39
40
|
# File 'lib/dopi/command/winrm/file_contains.rb', line 37
def pattern
@pattern ||= pattern_valid? ?
hash[:pattern] : nil
end
|
#pattern_valid? ⇒ Boolean
53
54
55
56
57
58
59
60
61
|
# File 'lib/dopi/command/winrm/file_contains.rb', line 53
def pattern_valid?
hash[:pattern] or
raise CommandParsingError, "Plugin #{name}: The key 'pattern' needs to be specified"
begin
Regexp.new(hash[:pattern])
rescue
raise CommandParsingError, "Plugin #{name}: The value in 'pattern' is not a valid regexp: #{e.message}"
end
end
|
#run ⇒ Object
19
20
21
22
|
# File 'lib/dopi/command/winrm/file_contains.rb', line 19
def run
cmd_stdout, cmd_stderr, cmd_exit_code = winrm_powershell_command(command_string)
check_exit_code(cmd_exit_code)
end
|
#run_noop ⇒ Object
24
25
26
|
# File 'lib/dopi/command/winrm/file_contains.rb', line 24
def run_noop
log(:info, "(NOOP) Executing '#{command_string}' for command #{name}")
end
|
#validate ⇒ Object
12
13
14
15
16
17
|
# File 'lib/dopi/command/winrm/file_contains.rb', line 12
def validate
validate_winrm
validate_exit_code
log_validation_method('file_valid?', CommandParsingError)
log_validation_method('pattern_valid?', CommandParsingError)
end
|