Module: ForemanRhCloud

Defined in:
lib/foreman_rh_cloud.rb,
lib/foreman_rh_cloud/engine.rb,
lib/foreman_rh_cloud/version.rb,
app/services/foreman_rh_cloud/cert_auth.rb,
app/services/foreman_rh_cloud/branch_info.rb,
app/services/foreman_rh_cloud/cloud_request.rb,
app/services/foreman_rh_cloud/cloud_presence.rb,
app/services/foreman_rh_cloud/cloud_connector.rb,
lib/foreman_rh_cloud/async/exponential_backoff.rb,
app/services/foreman_rh_cloud/cloud_ping_service.rb,
app/services/foreman_rh_cloud/remediations_retriever.rb,
app/services/foreman_rh_cloud/cloud_request_forwarder.rb,
app/services/foreman_rh_cloud/insights_status_cleaner.rb,
app/services/foreman_rh_cloud/template_renderer_helper.rb,
app/services/foreman_rh_cloud/hit_remediations_retriever.rb,
app/services/foreman_rh_cloud/url_remediations_retriever.rb

Defined Under Namespace

Modules: Async, CertAuth, CloudRequest, TemplateRendererHelper Classes: BranchInfo, CloudConnector, CloudPingService, CloudPresence, CloudRequestForwarder, Engine, HitRemediationsRetriever, InsightsStatusCleaner, RemediationsRetriever, UrlRemediationsRetriever

Constant Summary collapse

VERSION =
'9.0.56'.freeze

Class Method Summary collapse

Class Method Details

.base_urlObject



6
7
8
9
# File 'lib/foreman_rh_cloud.rb', line 6

def self.base_url
  # for testing set ENV to 'https://ci.cloud.redhat.com'
  @base_url ||= ENV['SATELLITE_RH_CLOUD_URL'] || 'https://cloud.redhat.com'
end

.cdn_proxy(logger: Foreman::Logging.logger('app')) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/foreman_rh_cloud.rb', line 55

def self.cdn_proxy(logger: Foreman::Logging.logger('app'))
  proxy_config = SETTINGS[:katello][:cdn_proxy]
  return nil unless proxy_config

  uri = URI('')
  uri.host = proxy_config[:host]
  uri.port = proxy_config[:port]
  uri.scheme = proxy_config[:scheme] || 'http'

  if proxy_config[:user]
    uri.user = CGI.escape(proxy_config[:user])
    uri.password = CGI.escape(proxy_config[:password])
  end
  uri.to_s
rescue URI::Error => e
  logger.warn("cdn_proxy parsing failed: #{e}")
  nil
end

.cert_base_urlObject



11
12
13
# File 'lib/foreman_rh_cloud.rb', line 11

def self.cert_base_url
  @cert_base_url ||= ENV['SATELLITE_CERT_RH_CLOUD_URL'] || 'https://cert.cloud.redhat.com'
end

.cloud_url_validatorObject



120
121
122
# File 'lib/foreman_rh_cloud.rb', line 120

def self.cloud_url_validator
  @cloud_url_validator ||= Regexp.new(ENV['SATELLITE_RH_CLOUD_VALIDATOR'] || 'redhat.com$')
end

.fix_port(uri_string) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/foreman_rh_cloud.rb', line 46

def self.fix_port(uri_string)
  return '' if uri_string.empty?

  uri = URI(uri_string)
  uri.send(:define_singleton_method, :default_port, -> { nil })

  uri.to_s
end

.foreman_hostObject

For testing purposes we can override the default hostname with an environment variable SATELLITE_RH_CLOUD_FOREMAN_HOST



95
96
97
98
99
100
101
102
103
104
# File 'lib/foreman_rh_cloud.rb', line 95

def self.foreman_host
  @foreman_host ||= begin
                      fullname = foreman_host_name
                      ::Host.unscoped.friendly.find(fullname)
                    rescue ActiveRecord::RecordNotFound
                      # fullname didn't work. Let's try shortname
                      shortname = /(?<shortname>[^\.]*)\.?.*/.match(fullname)[:shortname]
                      ::Host.unscoped.friendly.find(shortname)
                    end
end

.foreman_host_nameObject



106
107
108
# File 'lib/foreman_rh_cloud.rb', line 106

def self.foreman_host_name
  ENV['SATELLITE_RH_CLOUD_FOREMAN_HOST'] || marked_foreman_host&.name || ::SmartProxy.default_capsule.name
end

.global_foreman_proxyObject



74
75
76
# File 'lib/foreman_rh_cloud.rb', line 74

def self.global_foreman_proxy
  Setting[:http_proxy]
end

.http_proxy_string(logger: Foreman::Logging.logger('background')) ⇒ Object



27
28
29
# File 'lib/foreman_rh_cloud.rb', line 27

def self.http_proxy_string(logger: Foreman::Logging.logger('background'))
  ForemanRhCloud.proxy_setting(logger: logger)
end

.legacy_insights_caObject



116
117
118
# File 'lib/foreman_rh_cloud.rb', line 116

def self.legacy_insights_ca
  "#{ForemanRhCloud::Engine.root}/config/rh_cert-api_chain.pem"
end

.legacy_insights_urlObject



15
16
17
# File 'lib/foreman_rh_cloud.rb', line 15

def self.legacy_insights_url
  @legacy_insights_url ||= ENV['SATELLITE_LEGACY_INSIGHTS_URL'] || 'https://cert-api.access.redhat.com'
end

.marked_foreman_hostObject



110
111
112
113
114
# File 'lib/foreman_rh_cloud.rb', line 110

def self.marked_foreman_host
  ::Host.unscoped.search_for('infrastructure_facet.foreman = true').first
rescue ScopedSearch::QueryNotSupported
  nil
end

.proxy_setting(logger: Foreman::Logging.logger('background')) ⇒ Object



35
36
37
# File 'lib/foreman_rh_cloud.rb', line 35

def self.proxy_setting(logger: Foreman::Logging.logger('background'))
  fix_port(proxy_string(logger: logger))
end

.proxy_string(logger: Foreman::Logging.logger('background')) ⇒ Object



39
40
41
42
43
44
# File 'lib/foreman_rh_cloud.rb', line 39

def self.proxy_string(logger: Foreman::Logging.logger('background'))
  HttpProxy.default_global_content_proxy&.full_url ||
  ForemanRhCloud.cdn_proxy(logger: logger) ||
  ForemanRhCloud.global_foreman_proxy ||
  ''
end

.query_limitObject



23
24
25
# File 'lib/foreman_rh_cloud.rb', line 23

def self.query_limit
  @query_limit ||= ENV['SATELLITE_RH_CLOUD_QUERY_LIMIT'] ? ENV['SATELLITE_RH_CLOUD_QUERY_LIMIT'].to_i : 100
end

.requests_delayObject



124
125
126
# File 'lib/foreman_rh_cloud.rb', line 124

def self.requests_delay
  @requests_delay ||= ENV['SATELLITE_RH_CLOUD_REQUESTS_DELAY']
end

.transform_scheme(uri_string) ⇒ Object

This method assumes uri_string contains uri-encoded username and p@$$word: user:p%40%24%24word@localhost:8888



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/foreman_rh_cloud.rb', line 80

def self.transform_scheme(uri_string)
  return unless uri_string
  transformed_uri = URI.parse(uri_string)

  case transformed_uri.scheme
  when "http"
    transformed_uri.scheme = 'proxy'
  when "https"
    transformed_uri.scheme = 'proxys'
  end

  transformed_uri.to_s
end

.transformed_http_proxy_string(logger: Foreman::Logging.logger('background')) ⇒ Object



31
32
33
# File 'lib/foreman_rh_cloud.rb', line 31

def self.transformed_http_proxy_string(logger: Foreman::Logging.logger('background'))
  ForemanRhCloud.transform_scheme(ForemanRhCloud.proxy_setting(logger: logger))
end

.verify_ssl_methodObject



19
20
21
# File 'lib/foreman_rh_cloud.rb', line 19

def self.verify_ssl_method
  @verify_ssl_method ||= ENV['SATELLITE_RH_CLOUD_URL'] ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
end