module HammerCLIKatello::ContentImport::ContentImportCommon
Public Class Methods
included(base)
click to toggle source
# File lib/hammer_cli_katello/content_import.rb, line 8 def self.included(base) base.option "--metadata-file", "METADATA_FILE", _("Location of the metadata.json file. "\ "This is not required if the metadata.json file"\ " is already in the archive directory."), :attribute_name => :option_metadata_file, :required => false base.build_options do |o| o.expand(:all).including(:organizations).except(:metadata) end base.validate_options do option(:option_path).required metadata_file = option(:option_metadata_file).value || File.join(option(:option_path).value, "metadata.json") begin URI.open(metadata_file) rescue Errno::ENOENT msg = _("Unable to find '#{metadata_file}'. "\ "If the metadata.json file is at a different location "\ "provide it to the --metadata-file option ") raise HammerCLI::Options::Validators::ValidationError, msg end end base.success_message _("Archive is being imported in task %{id}.") base.failure_message _("Could not import the archive.") end
Public Instance Methods
fetch_metadata_from_url(metadata_file:, url:)
click to toggle source
# File lib/hammer_cli_katello/content_import.rb, line 37 def fetch_metadata_from_url(metadata_file:, url:) if metadata_file.nil? metadata_file = "/tmp/metadata.json" IO.copy_stream(URI.open(url), metadata_file) end metadata_file end
request_params()
click to toggle source
Calls superclass method
# File lib/hammer_cli_katello/content_import.rb, line 45 def request_params super.tap do |opts| metadata_file = option_metadata_file || File.join(option_path, "metadata.json") opts["metadata"] = JSON.parse(URI.open(metadata_file).read) end end