class HammerCLIForemanVirtWhoConfigure::VirtWhoConfig::FetchCommand

Public Instance Methods

execute() click to toggle source
# File lib/hammer_cli_foreman_virt_who_configure/config.rb, line 137
def execute
  data = send_request
  if option_output
    path = File.expand_path(option_output)
    if File.exist?(path)
      # this could be a security issue, the file should be readable only by the user
      output.print_error(
        _('Could not save the script'),
        _("File at %{path} already exists, please specify a different path.") % { :path => path }
      )
      return HammerCLI::EX_USAGE
    else
      File.write(path, data, perm: 0700, mode: File::RDWR|File::CREAT|File::EXCL)
      return HammerCLI::EX_OK
    end
  else
    puts data
    return HammerCLI::EX_OK
  end
end
transform_format(data) click to toggle source
# File lib/hammer_cli_foreman_virt_who_configure/config.rb, line 158
def transform_format(data)
  data['virt_who_config_script']
end