Class: InsightsCloud::Async::VmaasReposcanSync

Inherits:
Actions::EntryAction
  • Object
show all
Includes:
ForemanRhCloud::CertAuth
Defined in:
lib/insights_cloud/async/vmaas_reposcan_sync.rb

Overview

Triggers VMaaS reposcan sync via IoP gateway when repositories are synced

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ForemanRhCloud::CertAuth

#cert_auth_available?, #execute_cloud_request, #foreman_certificate

Methods included from CandlepinCache

#candlepin_id_cert, #cp_owner_id, #upstream_owner

Methods included from ForemanRhCloud::CloudRequest

#execute_cloud_request

Class Method Details

.subscribeObject

Subscribe to Katello repository sync hook action, if available



10
11
12
13
14
15
# File 'lib/insights_cloud/async/vmaas_reposcan_sync.rb', line 10

def self.subscribe
  'Actions::Katello::Repository::SyncHook'.constantize
rescue NameError
  Rails.logger.debug('VMaaS reposcan sync: Repository::SyncHook action not found')
  nil
end

Instance Method Details

#organizationObject



67
68
69
# File 'lib/insights_cloud/async/vmaas_reposcan_sync.rb', line 67

def organization
  @organization ||= Organization.find(input[:organization_id])
end

#plan(repo, *_args) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/insights_cloud/async/vmaas_reposcan_sync.rb', line 17

def plan(repo, *_args)
  return unless ::ForemanRhCloud.with_iop_smart_proxy?

  repo_id = repo.is_a?(Hash) ? (repo[:id] || repo['id']) : nil
  unless repo_id
    logger.error("VMaaS reposcan sync: missing repository id in SyncHook plan parameters: #{repo.inspect}")
    return
  end

  organization_id = Katello::Repository.find(repo_id).organization_id

  plan_self(organization_id: organization_id)
end

#rescue_strategy_for_selfObject



63
64
65
# File 'lib/insights_cloud/async/vmaas_reposcan_sync.rb', line 63

def rescue_strategy_for_self
  Dynflow::Action::Rescue::Skip
end

#runObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/insights_cloud/async/vmaas_reposcan_sync.rb', line 31

def run
  url = ::InsightsCloud.vmaas_reposcan_sync_url

  response = execute_cloud_request(
    organization: organization,
    method: :put,
    url: url,
    headers: { 'Content-Type' => 'application/json' }
  )

  if response.code >= 200 && response.code < 300
    message = "VMaaS reposcan sync triggered successfully: #{response.code}"
    logger.info(message)
  else
    message = "VMaaS reposcan sync failed with status: #{response.code}, body: #{response.body}"
    logger.error(message)
  end
  output[:message] = message

  response
rescue RestClient::ExceptionWithResponse => e
  message = "VMaaS reposcan sync failed: #{e.response&.code} - #{e.response&.body}"
  logger.error(message)
  output[:message] = message
  raise
rescue StandardError => e
  message = "Error triggering VMaaS reposcan sync: #{e.message}, response: #{e.respond_to?(:response) ? e.response : nil}"
  logger.error(message)
  output[:message] = message
  raise
end