Class: HammerCLIForemanVirtWhoConfigure::VirtWhoConfig::FetchCommand

Inherits:
HammerCLIForeman::Command
  • Object
show all
Defined in:
lib/hammer_cli_foreman_virt_who_configure/config.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/hammer_cli_foreman_virt_who_configure/config.rb', line 122

def execute
  data = send_request
  if option_output
    path = File.expand_path(option_output)
    if File.exists?(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) ⇒ Object



143
144
145
# File 'lib/hammer_cli_foreman_virt_who_configure/config.rb', line 143

def transform_format(data)
  data['virt_who_config_script']
end