Class: Katello::Resources::Candlepin::Product
Instance Attribute Summary
Attributes inherited from HttpResource
#json
Class Method Summary
collapse
default_headers, logger, name_to_key
#[], #[]=, create_thing, delete, hash_to_query, #initialize, join_path, logger, post, print_debug_info, process_response, put, raise_rest_client_exception, rest_client, url_encode
Class Method Details
._certificate_and_key(id, owner) ⇒ Object
628
629
630
631
632
633
634
635
636
637
638
639
640
641
|
# File 'app/lib/katello/resources/candlepin.rb', line 628
def _certificate_and_key(id, owner)
subscriptions_json = Candlepin::CandlepinResource.get("/candlepin/owners/#{owner}/subscriptions", self.).body
subscriptions = JSON.parse(subscriptions_json)
product_subscription = subscriptions.find do |sub|
sub["product"]["id"] == id ||
sub["providedProducts"].any? { |provided| provided["id"] == id } ||
sub["derivedProvidedProducts"].any? { |provided| provided["id"] == id }
end
if product_subscription
return product_subscription["certificate"]
end
end
|
.add_content(product_id, content_id, enabled) ⇒ Object
656
657
658
|
# File 'app/lib/katello/resources/candlepin.rb', line 656
def add_content(product_id, content_id, enabled)
self.post(join_path(path(product_id), "content/#{content_id}?enabled=#{enabled}"), nil, self.).code.to_i
end
|
.certificate(id, owner) ⇒ Object
643
644
645
|
# File 'app/lib/katello/resources/candlepin.rb', line 643
def certificate(id, owner)
self._certificate_and_key(id, owner).try :[], 'cert'
end
|
.create(attr) ⇒ Object
617
618
619
|
# File 'app/lib/katello/resources/candlepin.rb', line 617
def create(attr)
JSON.parse(self.post(path, attr.to_json, self.).body).with_indifferent_access
end
|
.create_unlimited_subscription(owner_key, product_id) ⇒ Object
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
|
# File 'app/lib/katello/resources/candlepin.rb', line 664
def create_unlimited_subscription(owner_key, product_id)
start_date ||= DateTime.now
end_date ||= start_date + 10_950
subscription = {
'startDate' => start_date,
'endDate' => end_date,
'quantity' => -1,
'accountNumber' => '',
'product' => { 'id' => product_id },
'providedProducts' => [],
'contractNumber' => ''
}
JSON.parse(Candlepin::Subscription.create_for_owner(owner_key, subscription))
end
|
.delete_subscriptions(owner_key, product_id) ⇒ Object
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
|
# File 'app/lib/katello/resources/candlepin.rb', line 685
def delete_subscriptions(owner_key, product_id)
update_subscriptions = false
subscriptions = Candlepin::Subscription.get_for_owner owner_key
subscriptions.each do |s|
products = ([s['product']] + s['providedProducts'])
products.each do |p|
if p['id'] == product_id
logger.debug "Deleting subscription: " + s.to_json
Candlepin::Subscription.destroy s['id']
update_subscriptions = true
end
end
end
if update_subscriptions
return Candlepin::Subscription.refresh_for_owner owner_key
else
return nil
end
end
|
.destroy(product_id) ⇒ Object
651
652
653
654
|
# File 'app/lib/katello/resources/candlepin.rb', line 651
def destroy(product_id)
fail ArgumentError, "product id has to be specified" unless product_id
self.delete(path(product_id), self.).code.to_i
end
|
.get(id = nil) ⇒ Object
621
622
623
624
625
626
|
# File 'app/lib/katello/resources/candlepin.rb', line 621
def get(id = nil)
products_json = super(path(id), self.).body
products = JSON.parse(products_json)
products = [products] unless id.nil?
::Katello::Util::Data.array_with_indifferent_access products
end
|
.key(id, owner) ⇒ Object
647
648
649
|
# File 'app/lib/katello/resources/candlepin.rb', line 647
def key(id, owner)
self._certificate_and_key(id, owner).try :[], 'key'
end
|
.path(id = nil) ⇒ Object
706
707
708
|
# File 'app/lib/katello/resources/candlepin.rb', line 706
def path(id = nil)
"/candlepin/products/#{id}"
end
|
.pools(owner_key, product_id) ⇒ Object
681
682
683
|
# File 'app/lib/katello/resources/candlepin.rb', line 681
def pools(owner_key, product_id)
Candlepin::Pool.get_for_owner(owner_key).find_all { |pool| pool['productId'] == product_id }
end
|
.remove_content(product_id, content_id) ⇒ Object
660
661
662
|
# File 'app/lib/katello/resources/candlepin.rb', line 660
def remove_content(product_id, content_id)
self.delete(join_path(path(product_id), "content/#{content_id}"), self.).code.to_i
end
|