Module: Katello::Glue::Provider::InstanceMethods
- Defined in:
- app/models/katello/glue/provider.rb
Constant Summary collapse
- API_BASE_URL =
'https://subscription.rhsm.redhat.com'.freeze
- SUBSCRIPTION_PATH =
'/subscription'.freeze
- CONSUMERS_PATH =
'/consumers/'.freeze
- API_URL =
API_BASE_URL + SUBSCRIPTION_PATH + CONSUMERS_PATH
Instance Method Summary collapse
- #api_url(upstream = {}) ⇒ Object
- #import_logger ⇒ Object
- #import_product(product_json) ⇒ Object
- #import_products_from_cp ⇒ Object
- #index_subscriptions ⇒ Object
- #last_sync ⇒ Object
- #normalize_api_url(api_url) ⇒ Object
- #owner_upstream_regenerate_identity_cert(upstream) ⇒ Object
- #owner_upstream_update(upstream, _options) ⇒ Object
- #retrieve_owner_upstream_export(upstream, zip_file_path, export_id) ⇒ Object
- #rules_source ⇒ Object
- #rules_version ⇒ Object
- #start_owner_upstream_export(upstream) ⇒ Object
- #sync ⇒ Object
- #synced? ⇒ Boolean
Instance Method Details
#api_url(upstream = {}) ⇒ Object
47 48 49 |
# File 'app/models/katello/glue/provider.rb', line 47 def api_url(upstream = {}) ENV['REDHAT_RHSM_API_URL'] || normalize_api_url(upstream['apiUrl']) || API_URL end |
#import_logger ⇒ Object
115 116 117 |
# File 'app/models/katello/glue/provider.rb', line 115 def import_logger ::Foreman::Logging.logger('katello/manifest_import_logger') end |
#import_product(product_json) ⇒ Object
141 142 143 144 145 146 147 148 149 |
# File 'app/models/katello/glue/provider.rb', line 141 def import_product(product_json) product = organization.products.find_by(:cp_id => product_json['id']) if product&.redhat? product.update!(:name => product_json['name']) unless product.name == product_json['name'] elsif product.nil? product = Glue::Candlepin::Product.import_redhat_product_from_cp(product_json, organization) end product end |
#import_products_from_cp ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'app/models/katello/glue/provider.rb', line 119 def import_products_from_cp cp_products = ::Katello::Resources::Candlepin::Product.all(organization.label, [:id, :name, :multiplier, :productContent]) cp_products = cp_products.select { |prod| Glue::Candlepin::Product.engineering_product_id?(prod['id']) } prod_content_importer = Katello::ProductContentImporter.new(cp_products) Katello::Logging.time("Imported #{cp_products.size} products") do cp_products.each do |product_json| next if ::Katello::Glue::Provider.orphaned_custom_product?(product_json['id'], organization) product = import_product(product_json) prod_content_importer.add_product_content(product, product_json['productContent']) if product.redhat? end end Katello::Logging.time("Imported product content") do prod_content_importer.import end self.index_subscriptions prod_content_importer end |
#index_subscriptions ⇒ Object
151 152 153 154 |
# File 'app/models/katello/glue/provider.rb', line 151 def index_subscriptions Katello::Subscription.import_all(organization) Katello::Pool.import_all(organization) end |
#last_sync ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'app/models/katello/glue/provider.rb', line 63 def last_sync sync_times = [] self.products.each do |prod| break unless prod.respond_to?(:last_sync) sync = prod.last_sync sync_times << sync unless sync.nil? end sync_times.sort! sync_times.last end |
#normalize_api_url(api_url) ⇒ Object
39 40 41 42 43 44 45 |
# File 'app/models/katello/glue/provider.rb', line 39 def normalize_api_url(api_url) return nil if api_url.blank? uri = URI.parse(api_url) # only take base url; we will overwrite the path to ensure it's correct uri.path = SUBSCRIPTION_PATH + CONSUMERS_PATH # https://subscription.rhsm.redhat.com/subscription/consumers/ uri.to_s end |
#owner_upstream_regenerate_identity_cert(upstream) ⇒ Object
88 89 90 91 92 93 94 |
# File 'app/models/katello/glue/provider.rb', line 88 def owner_upstream_regenerate_identity_cert(upstream) validate_upstream_identity_cert!(upstream) Rails.logger.debug "Sending request to regenerate identity certificate for upstream consumer: #{upstream['uuid']}" response = Resources::Candlepin::UpstreamConsumer.regenerate_upstream_identity("#{api_url(upstream)}#{upstream['uuid']}", upstream['idCert']['cert'], upstream['idCert']['key'], ca_file) JSON.parse(response) end |
#owner_upstream_update(upstream, _options) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/models/katello/glue/provider.rb', line 74 def owner_upstream_update(upstream, ) if !upstream['idCert'] || !upstream['idCert']['cert'] || !upstream['idCert']['key'] Rails.logger.error "Upstream identity certificate not available" fail _("Upstream identity certificate not available") end params = {} params[:capabilities] = Resources::Candlepin::CandlepinPing.ping['managerCapabilities'].inject([]) do |result, element| result << {'name' => element} end params[:facts] = {:distributor_version => DISTRIBUTOR_VERSION } Resources::Candlepin::UpstreamConsumer.update("#{api_url(upstream)}#{upstream['uuid']}", upstream['idCert']['cert'], upstream['idCert']['key'], ca_file, params) end |
#retrieve_owner_upstream_export(upstream, zip_file_path, export_id) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/models/katello/glue/provider.rb', line 103 def retrieve_owner_upstream_export(upstream, zip_file_path, export_id) validate_upstream_identity_cert!(upstream) data = Resources::Candlepin::UpstreamConsumer.retrieve_upstream_export( "#{api_url(upstream)}#{upstream['uuid']}/export/#{export_id}", upstream['idCert']['cert'], upstream['idCert']['key'], ca_file ) File.write(zip_file_path, data, mode: 'wb') true end |
#rules_source ⇒ Object
156 157 158 |
# File 'app/models/katello/glue/provider.rb', line 156 def rules_source redhat_provider? ? candlepin_ping['rulesSource'] : '' end |
#rules_version ⇒ Object
160 161 162 |
# File 'app/models/katello/glue/provider.rb', line 160 def rules_version redhat_provider? ? candlepin_ping['rulesVersion'] : '' end |
#start_owner_upstream_export(upstream) ⇒ Object
96 97 98 99 100 101 |
# File 'app/models/katello/glue/provider.rb', line 96 def start_owner_upstream_export(upstream) validate_upstream_identity_cert!(upstream) response = Resources::Candlepin::UpstreamConsumer.start_upstream_export("#{api_url(upstream)}#{upstream['uuid']}/export/async", upstream['idCert']['cert'], upstream['idCert']['key'], ca_file) JSON.parse(response) end |
#sync ⇒ Object
51 52 53 54 55 56 57 |
# File 'app/models/katello/glue/provider.rb', line 51 def sync Rails.logger.debug "Syncing provider #{name}" syncs = self.products.collect do |p| p.sync end syncs.flatten end |
#synced? ⇒ Boolean
59 60 61 |
# File 'app/models/katello/glue/provider.rb', line 59 def synced? self.products.any? { |p| p.synced? } end |