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

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, get, 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

.auto_attach(key) ⇒ Object



434
435
436
437
438
439
440
441
# File 'app/lib/katello/resources/candlepin.rb', line 434

def auto_attach(key)
  response = self.post(join_path(path(key), 'entitlements'), "", self.default_headers).body
  if response.empty?
    return nil
  else
    JSON.parse(response)
  end
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



327
328
329
330
331
# File 'app/lib/katello/resources/candlepin.rb', line 327

def create(key, description)
  attrs = {:key => key, :displayName => description, :contentPrefix => "/#{key}/$env"}
  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



334
335
336
337
# File 'app/lib/katello/resources/candlepin.rb', line 334

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



339
340
341
# File 'app/lib/katello/resources/candlepin.rb', line 339

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

.destroy_imports(organization_name, wait_until_complete = false) ⇒ Object



366
367
368
369
370
371
372
373
374
375
376
377
378
# File 'app/lib/katello/resources/candlepin.rb', line 366

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..-1])
      response_json = self.get(path, self.default_headers)
      response = JSON.parse(response_json).with_indifferent_access
    end
  end

  response
end

.events(key) ⇒ Object



420
421
422
423
# File 'app/lib/katello/resources/candlepin.rb', line 420

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

.find(key) ⇒ Object



343
344
345
346
# File 'app/lib/katello/resources/candlepin.rb', line 343

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



403
404
405
406
# File 'app/lib/katello/resources/candlepin.rb', line 403

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



408
409
410
411
# File 'app/lib/katello/resources/candlepin.rb', line 408

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



413
414
415
416
417
418
# File 'app/lib/katello/resources/candlepin.rb', line 413

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



354
355
356
357
358
359
360
361
362
363
364
# File 'app/lib/katello/resources/candlepin.rb', line 354

def import(organization_name, path_to_file, options)
  path = join_path(path(organization_name), 'imports')

  query_params = {}
  query_params[:force] = true if options[:force] == "true"
  unless query_params.empty?
    path << "?" << query_params.to_param
  end

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

.imports(organization_name) ⇒ Object



380
381
382
383
# File 'app/lib/katello/resources/candlepin.rb', line 380

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

.path(id = nil) ⇒ Object



443
444
445
# File 'app/lib/katello/resources/candlepin.rb', line 443

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

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



385
386
387
388
389
390
391
392
393
394
395
396
# File 'app/lib/katello/resources/candlepin.rb', line 385

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

.service_levels(uuid) ⇒ Object



425
426
427
428
429
430
431
432
# File 'app/lib/katello/resources/candlepin.rb', line 425

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



398
399
400
401
# File 'app/lib/katello/resources/candlepin.rb', line 398

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

.update(key, attrs) ⇒ Object



348
349
350
351
352
# File 'app/lib/katello/resources/candlepin.rb', line 348

def update(key, attrs)
  owner = find(key)
  owner.merge!(attrs)
  self.put(path(key), JSON.generate(owner), self.default_headers).body
end