Sha256: 44b40dfbe73aa838f1665595241ca31a5151ee715db6623c4e8d41169c3593d6

Contents?: true

Size: 1.12 KB

Versions: 8

Compression:

Stored size: 1.12 KB

Contents

module ForemanRhCloud
  module CloudAuth
    extend ActiveSupport::Concern

    include CloudRequest

    def rh_credentials
      @rh_credentials ||= query_refresh_token
    end

    def query_refresh_token
      token_response = RestClient::Request.execute(
        method: :post,
        url: ForemanRhCloud.authentication_url,
        verify_ssl: ForemanRhCloud.verify_ssl_method,
        proxy: ForemanRhCloud.transformed_http_proxy_string(logger: logger),
        payload: {
          grant_type: 'refresh_token',
          client_id: 'rhsm-api',
          refresh_token: Setting[:rh_cloud_token],
        }
      )

      JSON.parse(token_response)['access_token']
    rescue RestClient::ExceptionWithResponse => e
      Foreman::Logging.exception('Unable to authenticate using rh_cloud_token setting', e)
      raise ::Foreman::WrappedException.new(e, N_('Unable to authenticate using rh_cloud_token setting'))
    end

    def execute_cloud_request(params)
      final_params = {
        headers: {
          Authorization: "Bearer #{rh_credentials}",
        },
      }.deep_merge(params)

      super(final_params)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
foreman_rh_cloud-3.0.24.1 app/services/foreman_rh_cloud/cloud_auth.rb
foreman_rh_cloud-4.0.24.1 app/services/foreman_rh_cloud/cloud_auth.rb
foreman_rh_cloud-3.0.24 app/services/foreman_rh_cloud/cloud_auth.rb
foreman_rh_cloud-4.0.24 app/services/foreman_rh_cloud/cloud_auth.rb
foreman_rh_cloud-3.0.23 app/services/foreman_rh_cloud/cloud_auth.rb
foreman_rh_cloud-4.0.23 app/services/foreman_rh_cloud/cloud_auth.rb
foreman_rh_cloud-3.0.22 app/services/foreman_rh_cloud/cloud_auth.rb
foreman_rh_cloud-4.0.22 app/services/foreman_rh_cloud/cloud_auth.rb