Class: Katello::Resources::Candlepin::Owner

Inherits:
CandlepinResource show all
Extended by:
OwnerResource
Defined in:
app/lib/katello/resources/candlepin/owner.rb

Constant Summary

Constants inherited from HttpResource

HttpResource::REQUEST_MAP

Instance Attribute Summary

Attributes inherited from HttpResource

#json

Class Method Summary collapse

Methods included from OwnerResource

path

Methods inherited from CandlepinResource

default_headers, fetch_paged, included_list, logger, name_to_key, process_response, raise_rest_client_exception

Methods inherited from HttpResource

#[], #[]=, hash_to_query, #initialize, issue_request, join_path, logger, process_response, raise_rest_client_exception, rest_client

Methods included from Concerns::FilterSensitiveData

#filter_sensitive_data

Constructor Details

This class inherits a constructor from Katello::HttpResource

Class Method Details

.allObject



8
9
10
11
# File 'app/lib/katello/resources/candlepin/owner.rb', line 8

def all
  response = self.get(path, default_headers)
  JSON.parse(response.body)
end

.create(key, description) ⇒ Object

Set the contentPrefix at creation time so that the client will get content only for the org it has been subscribed to



15
16
17
18
19
20
21
22
23
24
25
# File 'app/lib/katello/resources/candlepin/owner.rb', line 15

def create(key, description)
  attrs = {
    :key => key,
    :displayName => description,
    :contentPrefix => "/#{key}/$env",
    :contentAccessMode => 'org_environment',
    :contentAccessModeList => 'org_environment',
  }
  owner_json = self.post(path, attrs.to_json, self.default_headers).body
  JSON.parse(owner_json).with_indifferent_access
end

.create_user(_key, username, password) ⇒ Object

create the first user for owner



28
29
30
31
# File 'app/lib/katello/resources/candlepin/owner.rb', line 28

def create_user(_key, username, password)
  # create user with superadmin flag (no role, permissions etc)
  CPUser.create(:username => name_to_key(username), :password => name_to_key(password), :superAdmin => true)
end

.destroy(key) ⇒ Object



33
34
35
# File 'app/lib/katello/resources/candlepin/owner.rb', line 33

def destroy(key)
  self.delete(path(key), User.cp_oauth_header).code.to_i
end

.destroy_imports(organization_name, wait_until_complete: false) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/lib/katello/resources/candlepin/owner.rb', line 66

def destroy_imports(organization_name, wait_until_complete: false)
  response_json = self.delete(join_path(path(organization_name), 'imports'), self.default_headers)
  response = JSON.parse(response_json).with_indifferent_access
  if wait_until_complete && response['state'] == 'CREATED'
    while !response['state'].nil? && response['state'] != 'FINISHED' && response['state'] != 'ERROR'
      path = join_path('candlepin', response['statusPath'][1..])
      response_json = self.get(path, self.default_headers)
      response = JSON.parse(response_json).with_indifferent_access
    end
  end

  response
end

.find(key) ⇒ Object



37
38
39
40
# File 'app/lib/katello/resources/candlepin/owner.rb', line 37

def find(key)
  owner_json = self.get(path(key), {'accept' => 'application/json'}.merge(User.cp_oauth_header)).body
  JSON.parse(owner_json).with_indifferent_access
end

.generate_ueber_cert(key) ⇒ Object



103
104
105
106
# File 'app/lib/katello/resources/candlepin/owner.rb', line 103

def generate_ueber_cert(key)
  ueber_cert_json = self.post(join_path(path(key), "uebercert"), {}.to_json, self.default_headers).body
  JSON.parse(ueber_cert_json).with_indifferent_access
end

.get_ueber_cert(key) ⇒ Object



108
109
110
111
# File 'app/lib/katello/resources/candlepin/owner.rb', line 108

def get_ueber_cert(key)
  ueber_cert_json = self.get(join_path(path(key), "uebercert"), {'accept' => 'application/json'}.merge(User.cp_oauth_header)).body
  JSON.parse(ueber_cert_json).with_indifferent_access
end

.get_ueber_cert_pkcs12(key, name = nil, password = nil) ⇒ Object



113
114
115
116
117
118
# File 'app/lib/katello/resources/candlepin/owner.rb', line 113

def get_ueber_cert_pkcs12(key, name = nil, password = nil)
  certs = get_ueber_cert(key)
  c = OpenSSL::X509::Certificate.new certs["cert"]
  p = OpenSSL::PKey::RSA.new certs["key"]
  OpenSSL::PKCS12.create(password, name, p, c, nil, "PBE-SHA1-3DES", "PBE-SHA1-3DES")
end

.import(organization_name, path_to_file, options) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'app/lib/katello/resources/candlepin/owner.rb', line 52

def import(organization_name, path_to_file, options)
  path = join_path(path(organization_name), 'imports/async')
  if options[:force] || SETTINGS[:katello].key?(:force_manifest_import)
    path += "?force=#{SETTINGS[:katello][:force_manifest_import]}"
  end

  response = self.post(path, {:import => File.new(path_to_file, 'rb')}, self.default_headers.except('content-type'))
  JSON.parse(response)
end

.imports(organization_name) ⇒ Object



80
81
82
83
# File 'app/lib/katello/resources/candlepin/owner.rb', line 80

def imports(organization_name)
  imports_json = self.get(join_path(path(organization_name), 'imports'), self.default_headers)
  ::Katello::Util::Data.array_with_indifferent_access JSON.parse(imports_json)
end

.pools(owner_label, filter = {}) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
# File 'app/lib/katello/resources/candlepin/owner.rb', line 85

def pools(owner_label, filter = {})
  filter[:add_future] ||= true
  params = hash_to_query(filter)
  if owner_label
    # hash_to_query escapes the ":!" to "%3A%21" which candlepin rejects
    params += '&attribute=unmapped_guests_only:!true'
    json_str = self.get(join_path(path(owner_label), 'pools') + params, self.default_headers).body
  else
    json_str = self.get(join_path('candlepin', 'pools') + params, self.default_headers).body
  end
  ::Katello::Util::Data.array_with_indifferent_access JSON.parse(json_str)
end

.product_content(organization_name) ⇒ Object



62
63
64
# File 'app/lib/katello/resources/candlepin/owner.rb', line 62

def product_content(organization_name)
  Product.all(organization_name, [:id, :productContent])
end

.service_levels(uuid) ⇒ Object



120
121
122
123
124
125
126
127
# File 'app/lib/katello/resources/candlepin/owner.rb', line 120

def service_levels(uuid)
  response = Candlepin::CandlepinResource.get(join_path(path(uuid), 'servicelevels'), self.default_headers).body
  if response.empty?
    return []
  else
    JSON.parse(response)
  end
end

.statistics(key) ⇒ Object



98
99
100
101
# File 'app/lib/katello/resources/candlepin/owner.rb', line 98

def statistics(key)
  json_str = self.get(join_path(path(key), 'statistics'), self.default_headers).body
  ::Katello::Util::Data.array_with_indifferent_access JSON.parse(json_str)
end

.system_purpose(key) ⇒ Object



129
130
131
132
133
134
135
136
# File 'app/lib/katello/resources/candlepin/owner.rb', line 129

def system_purpose(key)
  response = Candlepin::CandlepinResource.get(join_path(path(key), 'system_purpose'), self.default_headers).body
  if response.empty?
    return []
  else
    JSON.parse(response)['systemPurposeAttributes']
  end
end

.update(key, attrs = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'app/lib/katello/resources/candlepin/owner.rb', line 42

def update(key, attrs = {})
  owner = find(key)
  owner.merge!(attrs)
  owner.merge!(
    :contentAccessMode => 'org_environment',
    :contentAccessModeList => 'org_environment'
  )
  self.put(path(key), JSON.generate(owner), self.default_headers).body
end