Class: Katello::Resources::Candlepin::ActivationKey

Inherits:
CandlepinResource show all
Defined in:
app/lib/katello/resources/candlepin.rb

Instance Attribute Summary

Attributes inherited from HttpResource

#json

Class Method Summary collapse

Methods inherited from CandlepinResource

default_headers, logger, name_to_key

Methods inherited from HttpResource

#[], #[]=, 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

Constructor Details

This class inherits a constructor from Katello::HttpResource

Class Method Details

.add_pools(id, pool_id, quantity) ⇒ Object



774
775
776
777
778
779
780
# File 'app/lib/katello/resources/candlepin.rb', line 774

def add_pools(id, pool_id, quantity)
  cppath = join_path(path(id), "pools/#{pool_id}")
  quantity = Integer(quantity) rescue nil
  cppath += "?quantity=#{quantity}" if quantity && quantity > 0
  pool = self.post(cppath, {}, self.default_headers)
  JSON.parse(pool).with_indifferent_access
end

.add_product(id, product_id) ⇒ Object



763
764
765
766
767
# File 'app/lib/katello/resources/candlepin.rb', line 763

def add_product(id, product_id)
  cppath = join_path(path(id), "product/#{product_id}")
  product = self.post(cppath, {}, self.default_headers)
  JSON.parse(product).with_indifferent_access
end

.content_overrides(id) ⇒ Object



787
788
789
790
# File 'app/lib/katello/resources/candlepin.rb', line 787

def content_overrides(id)
  result = Candlepin::CandlepinResource.get(join_path(path(id), 'content_overrides'), self.default_headers).body
  ::Katello::Util::Data.array_with_indifferent_access(JSON.parse(result))
end

.create(name, owner_key, auto_attach) ⇒ Object



738
739
740
741
# File 'app/lib/katello/resources/candlepin.rb', line 738

def create(name, owner_key, auto_attach)
  url = "/candlepin/owners/#{owner_key}/activation_keys"
  JSON.parse(self.post(url, {:name => name, :autoAttach => auto_attach}.to_json, self.default_headers).body).with_indifferent_access
end

.destroy(id) ⇒ Object



748
749
750
751
# File 'app/lib/katello/resources/candlepin.rb', line 748

def destroy(id)
  fail(ArgumentError, "activation key id has to be specified") unless id
  self.delete(path(id), self.default_headers).code.to_i
end

.get(id = nil, params = '') ⇒ Object



731
732
733
734
735
736
# File 'app/lib/katello/resources/candlepin.rb', line 731

def get(id = nil, params = '')
  akeys_json = super(path(id) + params, self.default_headers).body
  akeys = JSON.parse(akeys_json)
  akeys = [akeys] unless id.nil?
  ::Katello::Util::Data.array_with_indifferent_access akeys
end

.key_pools(id) ⇒ Object



757
758
759
760
761
# File 'app/lib/katello/resources/candlepin.rb', line 757

def key_pools(id)
  kp_json = Candlepin::CandlepinResource.get(join_path(path(id), "pools"), self.default_headers).body
  key_pools = JSON.parse(kp_json)
  ::Katello::Util::Data.array_with_indifferent_access key_pools
end

.path(id = nil) ⇒ Object



807
808
809
# File 'app/lib/katello/resources/candlepin.rb', line 807

def path(id = nil)
  "/candlepin/activation_keys/#{id}"
end

.pools(owner_key) ⇒ Object



753
754
755
# File 'app/lib/katello/resources/candlepin.rb', line 753

def pools(owner_key)
  Candlepin::Owner.pools(owner_key)
end

.remove_pools(id, pool_id) ⇒ Object



782
783
784
785
# File 'app/lib/katello/resources/candlepin.rb', line 782

def remove_pools(id, pool_id)
  pool = self.delete(join_path(path(id), "pools/#{pool_id}"), self.default_headers)
  JSON.parse(pool).with_indifferent_access
end

.remove_product(id, product_id) ⇒ Object



769
770
771
772
# File 'app/lib/katello/resources/candlepin.rb', line 769

def remove_product(id, product_id)
  product = self.delete(join_path(path(id), "product/#{product_id}"), self.default_headers)
  JSON.parse(product).with_indifferent_access
end

.update(id, release_version, service_level, auto_attach) ⇒ Object



743
744
745
746
# File 'app/lib/katello/resources/candlepin.rb', line 743

def update(id, release_version, service_level, auto_attach)
  attrs = { :releaseVer => release_version, :serviceLevel => service_level, :autoAttach => auto_attach }.delete_if { |_k, v| v.nil? }
  JSON.parse(self.put(path(id), attrs.to_json, self.default_headers).body).with_indifferent_access
end

.update_content_override(id, content_label, name, value = nil) ⇒ Object



792
793
794
795
796
797
798
799
800
801
802
803
804
805
# File 'app/lib/katello/resources/candlepin.rb', line 792

def update_content_override(id, , name, value = nil)
  attrs = [{ :contentLabel => , :name => name }]
  if value
    attrs[0][:value] = value
    result = Candlepin::CandlepinResource.put(join_path(path(id), 'content_overrides'),
                                              attrs.to_json, self.default_headers)
  else
    client = Candlepin::CandlepinResource.rest_client(Net::HTTP::Delete, :delete,
                                                      join_path(path(id), 'content_overrides'))
    client.options[:payload] = attrs.to_json
    result = client.delete({:accept => :json, :content_type => :json}.merge(User.cp_oauth_header))
  end
  ::Katello::Util::Data.array_with_indifferent_access(JSON.parse(result))
end