From 3b4052ec1c5b0e2729ed1a58edefde711f11f771 Mon Sep 17 00:00:00 2001 From: Partha Aji Date: Thu, 13 Oct 2022 17:41:56 -0400 Subject: [PATCH] Refs #35606 - Can syncably import from webserver (#867) --- lib/hammer_cli_katello/content_import.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/hammer_cli_katello/content_import.rb b/lib/hammer_cli_katello/content_import.rb index 91606b65..e2fd5364 100644 --- a/lib/hammer_cli_katello/content_import.rb +++ b/lib/hammer_cli_katello/content_import.rb @@ -1,3 +1,4 @@ +require 'open-uri' module HammerCLIKatello class ContentImport < HammerCLIKatello::Command desc "Import content from a content archive" @@ -18,10 +19,11 @@ def self.included(base) base.validate_options do option(:option_path).required - metadata_file = option(:option_metadata_file).value || File.join(option(:option_path).value, "metadata.json") - unless File.exist?(metadata_file) + 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 ") @@ -32,10 +34,18 @@ def self.included(base) base.failure_message _("Could not import the archive.") end + 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 + def request_params super.tap do |opts| metadata_file = option_metadata_file || File.join(option_path, "metadata.json") - opts["metadata"] = JSON.parse(File.read(metadata_file)) + opts["metadata"] = JSON.parse(URI.open(metadata_file).read) end end end