Class: Katello::Host::ProfilesUploader

Inherits:
Object
  • Object
show all
Defined in:
app/services/katello/host/profiles_uploader.rb

Instance Method Summary collapse

Constructor Details

#initialize(profile_string:, host: nil) ⇒ ProfilesUploader

Returns a new instance of ProfilesUploader.



4
5
6
7
# File 'app/services/katello/host/profiles_uploader.rb', line 4

def initialize(profile_string:, host: nil)
  @profile_string = profile_string
  @host = host
end

Instance Method Details

#trigger_applicability_generationObject



44
45
46
47
48
49
50
# File 'app/services/katello/host/profiles_uploader.rb', line 44

def trigger_applicability_generation
  if @host.nil?
    Rails.logger.warn "Host was not specified; can't trigger applicability generation"
    return
  end
  ::Katello::Host::ContentFacet.trigger_applicability_generation(@host.id)
end

#uploadObject



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
36
37
38
39
40
41
42
# File 'app/services/katello/host/profiles_uploader.rb', line 9

def upload
  profiles = JSON.parse(@profile_string)
  #free the huge string from the memory
  @profile_string = 'TRIMMED'.freeze
  if @host.nil?
    Rails.logger.warn("Host was not specified; continuing")
  elsif @host.content_facet.nil? || @host.content_facet.uuid.nil?
    Rails.logger.warn("Host with ID %s has no content facet; continuing" % @host.id)
  elsif profiles.try(:has_key?, "deb_package_profile")
    # remove this when deb_package_profile API is removed
    payload = profiles.dig("deb_package_profile", "deb_packages") || []
    import_deb_package_profile(payload)
  else
    module_streams = []
    profiles.each do |profile|
      payload = profile["profile"]
      case profile["content_type"]
      when "rpm"
        PackageProfileUploader.import_package_profile_for_host(@host.id, payload)
      when "deb"
        import_deb_package_profile(payload)
      when "enabled_repos"
        @host.import_enabled_repositories(payload)
      else
        module_streams << payload
      end
    end

    module_streams.each do |module_stream_payload|
      import_module_streams(module_stream_payload)
    end

  end
end