Class: Katello::Resources::Candlepin::Product
Constant Summary
Constants inherited
from HttpResource
HttpResource::REQUEST_MAP
Instance Attribute Summary
Attributes inherited from HttpResource
#json
Class Method Summary
collapse
-
.add_content(owner_label, product_id, content_id, enabled) ⇒ Object
-
.all(owner_label, included = []) ⇒ Object
-
.certificate(id, owner) ⇒ Object
-
.create(owner_label, attr) ⇒ Object
-
.create_unlimited_subscription(owner_key, product_id, start_date) ⇒ Object
-
.delete_subscriptions(owner_key, product_id) ⇒ Object
-
.destroy(owner_label, product_id) ⇒ Object
-
.find_for_stacking_id(owner_key, stacking_id) ⇒ Object
-
.get(owner_label, id = nil, included = []) ⇒ Object
-
.key(id, owner) ⇒ Object
-
.path(owner_label, id = nil) ⇒ Object
-
.pools(owner_key, product_id) ⇒ Object
-
.product_certificate(id, owner) ⇒ Object
-
.remove_content(owner_label, product_id, content_id) ⇒ Object
-
.update(owner_label, attrs) ⇒ Object
default_headers, fetch_paged, included_list, logger, name_to_key, process_response, raise_rest_client_exception
#[], #[]=, hash_to_query, #initialize, issue_request, join_path, logger, process_response, raise_rest_client_exception, rest_client
#filter_sensitive_data
Class Method Details
.add_content(owner_label, product_id, content_id, enabled) ⇒ Object
66
67
68
|
# File 'app/lib/katello/resources/candlepin/product.rb', line 66
def add_content(owner_label, product_id, content_id, enabled)
self.post(join_path(path(owner_label, product_id), "content/#{content_id}?enabled=#{enabled}"), nil, self.).code.to_i
end
|
.all(owner_label, included = []) ⇒ Object
.certificate(id, owner) ⇒ Object
53
54
55
|
# File 'app/lib/katello/resources/candlepin/product.rb', line 53
def certificate(id, owner)
self.product_certificate(id, owner).try :[], 'cert'
end
|
.create(owner_label, attr) ⇒ Object
21
22
23
|
# File 'app/lib/katello/resources/candlepin/product.rb', line 21
def create(owner_label, attr)
JSON.parse(self.post(path(owner_label), attr.to_json, self.).body).with_indifferent_access
end
|
.create_unlimited_subscription(owner_key, product_id, start_date) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'app/lib/katello/resources/candlepin/product.rb', line 74
def create_unlimited_subscription(owner_key, product_id, start_date)
start_date ||= Time.now
end_date = Time.parse('2049-12-01 00:00:00 +0000')
pool = {
'startDate' => start_date,
'endDate' => end_date,
'quantity' => -1,
'accountNumber' => '',
'productId' => product_id,
'providedProducts' => [],
'contractNumber' => '',
}
JSON.parse(Candlepin::Pool.create(owner_key, pool))
end
|
.delete_subscriptions(owner_key, product_id) ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'app/lib/katello/resources/candlepin/product.rb', line 99
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
nil
end
|
.destroy(owner_label, product_id) ⇒ Object
61
62
63
64
|
# File 'app/lib/katello/resources/candlepin/product.rb', line 61
def destroy(owner_label, product_id)
fail ArgumentError, "product id has to be specified" unless product_id
self.delete(path(owner_label, product_id), self.).code.to_i
end
|
.find_for_stacking_id(owner_key, stacking_id) ⇒ Object
12
13
14
15
16
17
18
19
|
# File 'app/lib/katello/resources/candlepin/product.rb', line 12
def find_for_stacking_id(owner_key, stacking_id)
Resources::Candlepin::Subscription.get_for_owner(owner_key).each do |subscription|
if subscription['product']['attributes'].any? { |attr| attr['name'] == 'stacking_id' && attr['value'] == stacking_id }
return subscription['product']
end
end
nil
end
|
.get(owner_label, id = nil, included = []) ⇒ Object
25
26
27
28
29
30
|
# File 'app/lib/katello/resources/candlepin/product.rb', line 25
def get(owner_label, id = nil, included = [])
products_json = super(path(owner_label, id + "/?#{included_list(included)}"), 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
57
58
59
|
# File 'app/lib/katello/resources/candlepin/product.rb', line 57
def key(id, owner)
self.product_certificate(id, owner).try :[], 'key'
end
|
.path(owner_label, id = nil) ⇒ Object
115
116
117
|
# File 'app/lib/katello/resources/candlepin/product.rb', line 115
def path(owner_label, id = nil)
"/candlepin/owners/#{owner_label}/products/#{id}"
end
|
.pools(owner_key, product_id) ⇒ Object
95
96
97
|
# File 'app/lib/katello/resources/candlepin/product.rb', line 95
def pools(owner_key, product_id)
Candlepin::Pool.get_for_owner(owner_key).find_all { |pool| pool['productId'] == product_id }
end
|
.product_certificate(id, owner) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'app/lib/katello/resources/candlepin/product.rb', line 32
def product_certificate(id, owner)
included = %w(certificate product.id providedProducts.id
derivedProvidedProducts.id startDate)
subscriptions_json = Candlepin::CandlepinResource.get(
"/candlepin/owners/#{owner}/subscriptions?#{included_list(included)}",
self.
).body
subscriptions = JSON.parse(subscriptions_json)
product_subscription = subscriptions.find do |sub|
sub['certificate'] && Time.parse(sub['startDate']) < Time.now &&
(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
|
.remove_content(owner_label, product_id, content_id) ⇒ Object
70
71
72
|
# File 'app/lib/katello/resources/candlepin/product.rb', line 70
def remove_content(owner_label, product_id, content_id)
self.delete(join_path(path(owner_label, product_id), "content/#{content_id}"), self.).code.to_i
end
|
.update(owner_label, attrs) ⇒ Object
119
120
121
|
# File 'app/lib/katello/resources/candlepin/product.rb', line 119
def update(owner_label, attrs)
JSON.parse(self.put(path(owner_label, attrs[:id] || attrs['id']), JSON.generate(attrs), self.).body).with_indifferent_access
end
|