Module: ForemanRhCloud

Defined in:
lib/foreman_rh_cloud.rb,
lib/foreman_rh_cloud/engine.rb,
lib/foreman_rh_cloud/plugin.rb,
lib/foreman_rh_cloud/version.rb,
app/models/foreman_rh_cloud/ping.rb,
app/services/foreman_rh_cloud/cert_auth.rb,
app/services/foreman_rh_cloud/tags_auth.rb,
app/services/foreman_rh_cloud/branch_info.rb,
app/services/foreman_rh_cloud/cloud_request.rb,
app/services/foreman_rh_cloud/hits_uploader.rb,
app/services/foreman_rh_cloud/cloud_presence.rb,
app/services/foreman_rh_cloud/rules_ingester.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/insights_api_forwarder.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,
app/controllers/foreman_rh_cloud/foreman_rh_cloud_controller.rb,
app/controllers/concerns/foreman_rh_cloud/iop_smart_proxy_access.rb

Defined Under Namespace

Modules: Async, CertAuth, CloudRequest, IopSmartProxyAccess, Plugin, TemplateRendererHelper Classes: BranchInfo, CloudConnector, CloudPingService, CloudPresence, CloudRequestForwarder, Engine, ForemanRhCloudController, HitRemediationsRetriever, HitsUploader, InsightsApiForwarder, InsightsStatusCleaner, Ping, RemediationsRetriever, RulesIngester, TagsAuth, URLRemediationsRetriever

Constant Summary collapse

VERSION =
'13.0.7'.freeze

Class Method Summary collapse

Class Method Details

.base_urlObject



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

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

.ca_certObject



129
130
131
132
133
134
135
136
137
138
# File 'lib/foreman_rh_cloud/engine.rb', line 129

def self.ca_cert
  # The reference to candlepin ca_cert_file can be removed
  # once the setting is dropped. Foreman 3.15 introduces
  # a single CA file that bundles all CAs.
  if ::SETTINGS.dig(:katello, :candlepin, :ca_cert_file)
    ::SETTINGS[:katello][:candlepin][:ca_cert_file]
  else
    ::SETTINGS[:ssl_ca_file]
  end
end

.cert_base_urlObject



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

def self.cert_base_url
  @cert_base_url ||= env_or_on_premise_url('SATELLITE_CERT_RH_CLOUD_URL') || 'https://cert.cloud.redhat.com'
end

.cloud_url_validatorObject



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

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

.env_or_on_premise_url(env_var_name) ⇒ Object



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

def self.env_or_on_premise_url(env_var_name)
  on_premise_url || ENV[env_var_name]
end

.fix_port(uri_string) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/foreman_rh_cloud.rb', line 56

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



86
87
88
89
90
91
92
93
94
95
# File 'lib/foreman_rh_cloud.rb', line 86

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



97
98
99
# File 'lib/foreman_rh_cloud.rb', line 97

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

.global_foreman_proxyObject



65
66
67
# File 'lib/foreman_rh_cloud.rb', line 65

def self.global_foreman_proxy
  Setting[:http_proxy]
end

.http_proxy_stringObject



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

def self.http_proxy_string
  ForemanRhCloud.proxy_setting
end

.iop_smart_proxyObject



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

def self.iop_smart_proxy
  SmartProxy.unscoped.with_features('iop').first
end

.legacy_insights_caObject



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

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

.legacy_insights_urlObject



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

def self.legacy_insights_url
  @legacy_insights_url ||= env_or_on_premise_url('SATELLITE_LEGACY_INSIGHTS_URL') || 'https://cert-api.access.redhat.com'
end

.marked_foreman_hostObject



101
102
103
104
105
# File 'lib/foreman_rh_cloud.rb', line 101

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

.on_prem_smart_proxy_featuresObject



140
141
142
# File 'lib/foreman_rh_cloud/engine.rb', line 140

def self.on_prem_smart_proxy_features
  ['iop']
end

.on_premise_urlObject



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

def self.on_premise_url
  return unless ForemanRhCloud.with_iop_smart_proxy?
  ForemanRhCloud.iop_smart_proxy&.url
end

.proxy_settingObject



44
45
46
# File 'lib/foreman_rh_cloud.rb', line 44

def self.proxy_setting
  fix_port(proxy_string)
end

.proxy_stringObject



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

def self.proxy_string
  return '' if ForemanRhCloud.with_iop_smart_proxy?

  HttpProxy.default_global_content_proxy&.full_url ||
  ForemanRhCloud.global_foreman_proxy ||
  ''
end

.query_limitObject



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

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

.requests_delayObject



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

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



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/foreman_rh_cloud.rb', line 71

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_stringObject



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

def self.transformed_http_proxy_string
  ForemanRhCloud.transform_scheme(ForemanRhCloud.proxy_setting)
end

.verify_ssl_methodObject



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

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

.with_iop_smart_proxy?Boolean

Returns:

  • (Boolean)


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

def self.with_iop_smart_proxy?
  SmartProxy.unscoped.with_features('iop').exists?
end