Module: HammerCLIKatello::ContentImport::ContentImportCommon

Included in:
LibraryCommand, RepositoryCommand, VersionCommand
Defined in:
lib/hammer_cli_katello/content_import.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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
     = option(:option_metadata_file).value ||
                    File.join(option(:option_path).value, "metadata.json")
    begin
      URI.open()
    rescue Errno::ENOENT
      msg = _("Unable to find '#{}'. "\
               "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

Instance Method Details

#fetch_metadata_from_url(metadata_file:, url:) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/hammer_cli_katello/content_import.rb', line 37

def (metadata_file:, url:)
  if .nil?
     = "/tmp/metadata.json"
    IO.copy_stream(URI.open(url), )
  end
  
end

#request_paramsObject



45
46
47
48
49
50
# File 'lib/hammer_cli_katello/content_import.rb', line 45

def request_params
  super.tap do |opts|
     =  || File.join(option_path, "metadata.json")
    opts["metadata"] = JSON.parse(URI.open().read)
  end
end