Module: Katello::Concerns::HttpProxyExtensions

Extended by:
ActiveSupport::Concern
Defined in:
app/models/katello/concerns/http_proxy_extensions.rb

Instance Method Summary collapse

Instance Method Details

#name_and_urlObject



81
82
83
84
85
86
# File 'app/models/katello/concerns/http_proxy_extensions.rb', line 81

def name_and_url
  uri = URI(url)
  uri.password = nil
  uri.user = nil
  "#{name} (#{uri})"
end

#remove_references_to_proxyObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/models/katello/concerns/http_proxy_extensions.rb', line 33

def remove_references_to_proxy
  root_repos = repositories_with_proxy(nil).uniq.sort

  setting = Setting.find_by(name: 'content_default_http_proxy')
  if setting&.value && setting.value == self.name
    setting.update_attribute(:value, '')
  end

  unless root_repos.empty?
    ForemanTasks.async_task(
      ::Actions::BulkAction,
      ::Actions::Katello::Repository::Update,
      root_repos,
      http_proxy_policy: Katello::RootRepository::GLOBAL_DEFAULT_HTTP_PROXY,
      http_proxy_id: nil)
  end

  unless smart_proxies.empty?
    smart_proxies.each do |smart_proxy|
      smart_proxy.update(http_proxy_id: nil)
    end
  end
end

#repositories_with_proxy(proxy_id) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'app/models/katello/concerns/http_proxy_extensions.rb', line 23

def repositories_with_proxy(proxy_id)
  root_repos = RootRepository.with_selected_proxy(proxy_id)

  if self == HttpProxy.default_global_content_proxy
    root_repos += RootRepository.with_global_proxy
  end

  root_repos
end

#update_default_proxy_settingObject



57
58
59
60
61
62
63
64
65
# File 'app/models/katello/concerns/http_proxy_extensions.rb', line 57

def update_default_proxy_setting
  changes = self.previous_changes
  if changes.key?(:name)
    previous_name = changes[:name].first
    if !previous_name.blank? && Setting['content_default_http_proxy'] == previous_name
      Setting['content_default_http_proxy'] = self.name
    end
  end
end

#update_repository_proxy_detailsObject



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/models/katello/concerns/http_proxy_extensions.rb', line 67

def update_repository_proxy_details
  changes = self.previous_changes
  if changes.key?(:url) || changes.key?(:username) || changes.key?(:password)
    repos = ::Katello::Repository.where(root_id: repositories_with_proxy(id).pluck(:id)).where.not(remote_href: nil).where(library_instance_id: nil)

    unless repos.empty?
      ForemanTasks.async_task(
        ::Actions::BulkAction,
        ::Actions::Katello::Repository::UpdateHttpProxyDetails,
        repos.sort_by(&:pulp_id))
    end
  end
end