Sha256: f206eb85668f6065aed2d1b6f9a38ee294a8bcf9a2276e67c30d1d225cc7fb4a

Contents?: true

Size: 1.46 KB

Versions: 31

Compression:

Stored size: 1.46 KB

Contents

require 'rest-client'

module ForemanRhCloud
  class CloudPingService
    class CertPing
      include ForemanRhCloud::CloudRequest
      include InsightsCloud::CandlepinCache

      attr_accessor :logger

      def initialize(org, logger)
        @org = org
        @logger = logger
      end

      def ping
        certs = candlepin_id_cert(@org)
        return StandardError.new('certificate missing') unless certs

        cert_checker = Katello::UpstreamConnectionChecker.new(@org)
        cert_checker.assert_connection

        execute_cloud_request(
          method: :get,
          url: ForemanRhCloud.cert_base_url + "/api/apicast-tests/ping",
          headers: {
            content_type: :json,
          },
          ssl_client_cert: OpenSSL::X509::Certificate.new(certs[:cert]),
          ssl_client_key: OpenSSL::PKey.read(certs[:key])
        )
      rescue StandardError => ex
        ex
      end
    end

    def initialize(organizations, logger)
      @organizations = organizations
      @logger = logger
    end

    def ping
      {
        cert_auth: Hash[
          @organizations.map do |org|
            cert_response = CertPing.new(org, @logger).ping
            [
              org,
              {
                success: cert_response.is_a?(RestClient::Response),
                error: (cert_response.is_a?(Exception) ? cert_response&.message || cert_response.inspect : nil),
              },
            ]
          end
        ],
      }
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
foreman_rh_cloud-9.0.59 app/services/foreman_rh_cloud/cloud_ping_service.rb
foreman_rh_cloud-11.0.2 app/services/foreman_rh_cloud/cloud_ping_service.rb
foreman_rh_cloud-11.0.1 app/services/foreman_rh_cloud/cloud_ping_service.rb
foreman_rh_cloud-11.0.0 app/services/foreman_rh_cloud/cloud_ping_service.rb
foreman_rh_cloud-9.0.58 app/services/foreman_rh_cloud/cloud_ping_service.rb
foreman_rh_cloud-10.0.2 app/services/foreman_rh_cloud/cloud_ping_service.rb
foreman_rh_cloud-9.0.57 app/services/foreman_rh_cloud/cloud_ping_service.rb
foreman_rh_cloud-10.0.1 app/services/foreman_rh_cloud/cloud_ping_service.rb
foreman_rh_cloud-9.0.56 app/services/foreman_rh_cloud/cloud_ping_service.rb
foreman_rh_cloud-9.0.55 app/services/foreman_rh_cloud/cloud_ping_service.rb
foreman_rh_cloud-9.0.54 app/services/foreman_rh_cloud/cloud_ping_service.rb
foreman_rh_cloud-9.0.53 app/services/foreman_rh_cloud/cloud_ping_service.rb
foreman_rh_cloud-9.0.52 app/services/foreman_rh_cloud/cloud_ping_service.rb
foreman_rh_cloud-8.0.52 app/services/foreman_rh_cloud/cloud_ping_service.rb
foreman_rh_cloud-9.0.51 app/services/foreman_rh_cloud/cloud_ping_service.rb
foreman_rh_cloud-8.0.51 app/services/foreman_rh_cloud/cloud_ping_service.rb
foreman_rh_cloud-7.0.48 app/services/foreman_rh_cloud/cloud_ping_service.rb
foreman_rh_cloud-7.0.47 app/services/foreman_rh_cloud/cloud_ping_service.rb
foreman_rh_cloud-8.0.50 app/services/foreman_rh_cloud/cloud_ping_service.rb
foreman_rh_cloud-8.0.49 app/services/foreman_rh_cloud/cloud_ping_service.rb