Class: Katello::UINotifications::Subscriptions::ManifestExpiredWarning

Inherits:
UINotifications::Base
  • Object
show all
Defined in:
app/services/katello/ui_notifications/subscriptions/manifest_expired_warning.rb

Constant Summary collapse

CONTENT_LABEL =
'rhel-7-server-rpms'.freeze
CDN_HOSTNAME =
'cdn.redhat.com'.freeze
CDN_PATH =
'/content/dist/rhel/server/7/listing'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cdn_inaccessible?(org) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
53
# File 'app/services/katello/ui_notifications/subscriptions/manifest_expired_warning.rb', line 47

def self.cdn_inaccessible?(org)
  content = org.contents.find_by(:label => )
  product = content&.products&.find { |p| p.key }
  if content && product && product.pools.any?
    return got_403? { product.cdn_resource.get(CDN_PATH) }
  end
end

.deliver!(orgs = ::Organization.all) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/services/katello/ui_notifications/subscriptions/manifest_expired_warning.rb', line 9

def self.deliver!(orgs = ::Organization.all)
  return unless Setting[:subscription_connection_enabled]

  orgs.each do |org|
    if cdn_inaccessible?(org) || upstream_inaccessible?(org)
      new(org).deliver!
    end
  end
rescue StandardError => e
  # Do not break actions using notifications even if there is a failure.
  logger.warn("Failed to handle notifications - this is most likely a bug: #{e}")
  logger.debug(e.backtrace.join("\n"))
  false
end

.got_403?Boolean

Returns:

  • (Boolean)


55
56
57
58
59
60
# File 'app/services/katello/ui_notifications/subscriptions/manifest_expired_warning.rb', line 55

def self.got_403?
  yield
  false
rescue Katello::Errors::SecurityViolation
  true
end

.redhat_connected?(org) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
# File 'app/services/katello/ui_notifications/subscriptions/manifest_expired_warning.rb', line 69

def self.redhat_connected?(org)
  org.cdn_configuration.url.include?(CDN_HOSTNAME)
end

.upstream_inaccessible?(org) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
65
66
67
# File 'app/services/katello/ui_notifications/subscriptions/manifest_expired_warning.rb', line 62

def self.upstream_inaccessible?(org)
  return unless org.manifest_imported?

  checker = Katello::UpstreamConnectionChecker.new(org)
  !checker.can_connect?
end

Instance Method Details

#add_notificationObject



34
35
36
37
38
39
40
41
# File 'app/services/katello/ui_notifications/subscriptions/manifest_expired_warning.rb', line 34

def add_notification
  Notification.create!(
      initiator:  User.anonymous_admin,
      audience: ::Notification::AUDIENCE_ADMIN,
      subject: subject,
      notification_blueprint: blueprint
  )
end

#blueprintObject



43
44
45
# File 'app/services/katello/ui_notifications/subscriptions/manifest_expired_warning.rb', line 43

def blueprint
  @blueprint ||= NotificationBlueprint.find_by(name: 'manifest_expired_warning')
end

#createObject



24
25
26
# File 'app/services/katello/ui_notifications/subscriptions/manifest_expired_warning.rb', line 24

def create
  add_notification if update_notifications.zero?
end

#update_notificationsObject



28
29
30
31
32
# File 'app/services/katello/ui_notifications/subscriptions/manifest_expired_warning.rb', line 28

def update_notifications
  blueprint.notifications.
      where(subject: subject).
      update_all(expired_at: blueprint.expired_at)
end