module ForemanRhCloud

Constants

VERSION

Public Class Methods

authentication_url() click to toggle source
# File lib/foreman_rh_cloud.rb, line 19
def self.authentication_url
  # https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token
  @authentication_url ||= ENV['SATELLITE_RH_CLOUD_SSO_URL'] || 'https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token'
end
base_url() click to toggle source
# 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')) click to toggle source
# File lib/foreman_rh_cloud.rb, line 60
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_url() click to toggle source
# 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
fix_port(uri_string) click to toggle source
# File lib/foreman_rh_cloud.rb, line 51
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_host() click to toggle source

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

# File lib/foreman_rh_cloud.rb, line 100
def self.foreman_host
  @foreman_host ||= ::Host.unscoped.friendly.find(ENV['SATELLITE_RH_CLOUD_FOREMAN_HOST'] || ::SmartProxy.default_capsule.name)
end
global_foreman_proxy() click to toggle source
# File lib/foreman_rh_cloud.rb, line 79
def self.global_foreman_proxy
  Setting[:http_proxy]
end
http_proxy_string(logger: Foreman::Logging.logger('background')) click to toggle source
# File lib/foreman_rh_cloud.rb, line 32
def self.http_proxy_string(logger: Foreman::Logging.logger('background'))
  ForemanRhCloud.proxy_setting(logger: logger)
end
legacy_insights_url() click to toggle source
# 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
proxy_setting(logger: Foreman::Logging.logger('background')) click to toggle source
# File lib/foreman_rh_cloud.rb, line 40
def self.proxy_setting(logger: Foreman::Logging.logger('background'))
  fix_port(proxy_string(logger: logger))
end
proxy_string(logger: Foreman::Logging.logger('background')) click to toggle source
# File lib/foreman_rh_cloud.rb, line 44
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_limit() click to toggle source
# File lib/foreman_rh_cloud.rb, line 28
def self.query_limit
  @query_limit ||= ENV['SATELLITE_RH_CLOUD_QUERY_LIMIT'] ? ENV['SATELLITE_RH_CLOUD_QUERY_LIMIT'].to_i : 100
end
transform_scheme(uri_string) click to toggle source

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

# File lib/foreman_rh_cloud.rb, line 85
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')) click to toggle source
# File lib/foreman_rh_cloud.rb, line 36
def self.transformed_http_proxy_string(logger: Foreman::Logging.logger('background'))
  ForemanRhCloud.transform_scheme(ForemanRhCloud.proxy_setting(logger: logger))
end
verify_ssl_method() click to toggle source
# File lib/foreman_rh_cloud.rb, line 24
def self.verify_ssl_method
  @verify_ssl_method ||= ENV['SATELLITE_RH_CLOUD_URL'] ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
end