class Dopi::Command::Winrm::FileContains

Public Instance Methods

command_string() click to toggle source
# 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() click to toggle source
# File lib/dopi/command/winrm/file_contains.rb, line 32
def file
  @file ||= file_valid? ?
    hash[:file] : nil
end
file_valid?() click to toggle source
# 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() click to toggle source
# File lib/dopi/command/winrm/file_contains.rb, line 37
def pattern
  @pattern ||= pattern_valid? ?
    hash[:pattern] : nil
end
pattern_valid?() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/dopi/command/winrm/file_contains.rb, line 24
def run_noop
  log(:info, "(NOOP) Executing '#{command_string}' for command #{name}")
end
validate() click to toggle source
# 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