Sha256: ff5f2a5ebe88727be9ca770963b9bc7bcaae9ffdd933cdc611dbb440b9cbf86e

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

module Katello
  class UpstreamConnectionChecker
    POSSIBLE_EXCEPTIONS = [
      Katello::Errors::SubscriptionConnectionNotEnabled,
      Katello::Errors::ManifestExpired,
      Katello::Errors::UpstreamConsumerGone,
      Katello::Errors::UpstreamConsumerNotFound,
      Katello::Errors::NoManifestImported,
    ].freeze

    def initialize(organization)
      @organization = organization
    end

    def can_connect?
      assert_connection
    rescue StandardError => e
      if POSSIBLE_EXCEPTIONS.include?(e.class)
        false
      else
        raise e
      end
    end

    def assert_connection
      assert_connected
      assert_unexpired_manifest
      assert_can_upstream_ping

      true
    end

    private

    def assert_connected
      fail Katello::Errors::SubscriptionConnectionNotEnabled unless Setting[:subscription_connection_enabled]
    end

    def assert_can_upstream_ping
      ::Organization.as_org(@organization) do
        Katello::Resources::Candlepin::UpstreamConsumer.ping
      end
    end

    def assert_unexpired_manifest
      fail Katello::Errors::ManifestExpired if @organization.manifest_expired?
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
katello-4.15.0 app/services/katello/upstream_connection_checker.rb
katello-4.15.0.rc2 app/services/katello/upstream_connection_checker.rb
katello-4.15.0.rc1 app/services/katello/upstream_connection_checker.rb