module ForemanRhCloud

Constants

VERSION

Public Class Methods

authentication_url() click to toggle source
# File lib/foreman_rh_cloud.rb, line 11
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 35
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
global_foreman_proxy() click to toggle source
# File lib/foreman_rh_cloud.rb, line 54
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 20
def self.http_proxy_string(logger: Foreman::Logging.logger('background'))
  ForemanRhCloud.proxy_setting(logger: logger)
end
proxy_setting(logger: Foreman::Logging.logger('background')) click to toggle source
# File lib/foreman_rh_cloud.rb, line 28
def self.proxy_setting(logger: Foreman::Logging.logger('background'))
  HttpProxy.default_global_content_proxy&.full_url ||
  ForemanRhCloud.cdn_proxy(logger: logger) ||
  ForemanRhCloud.global_foreman_proxy ||
  ''
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 60
def self.transform_scheme(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 24
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 16
def self.verify_ssl_method
  @verify_ssl_method ||= ENV['SATELLITE_RH_CLOUD_URL'] ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
end