Skip to content

Commit

Permalink
Refs #35606 - Can syncably import from webserver
Browse files Browse the repository at this point in the history
  • Loading branch information
parthaa committed Oct 8, 2022
1 parent 8fb71dd commit d0a3c04
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions 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"
Expand All @@ -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 ")
Expand All @@ -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
Expand Down

0 comments on commit d0a3c04

Please sign in to comment.