Module: Katello::Pulp3::ServiceCommon

Included in:
AlternateContentSource, Repository
Defined in:
app/services/katello/pulp3/service_common.rb

Instance Method Summary collapse

Instance Method Details

#create_remoteObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/services/katello/pulp3/service_common.rb', line 4

def create_remote
  response = nil
  if remote_options[:url]&.start_with?('uln')
    remote_file_data = api.class.remote_uln_class.new(remote_options)
  else
    remote_file_data = api.remote_class.new(remote_options)
  end
  reformat_api_exception do
    if remote_options[:url]&.start_with?('uln')
      response = api.remotes_uln_api.create(remote_file_data)
    else
      response = api.remotes_api.create(remote_file_data)
    end
  end
  response
end

#create_test_remoteObject

When updating a repository, we need to update the remote, but this is an async task. If some validation occurs, we won’t know about it until the task runs. Errors during a repository update task are very difficult to handle once the task is in its run phase, so this creates a test remote with a random name in order to validate the remote’s configuration



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/services/katello/pulp3/service_common.rb', line 30

def create_test_remote
  test_remote_options = remote_options
  test_remote_options[:name] = test_remote_name
  if remote_options[:url]&.start_with?('uln')
    remote_file_data = api.class.remote_uln_class.new(test_remote_options)
  else
    remote_file_data = api.remote_class.new(test_remote_options)
  end

  reformat_api_exception do
    if remote_options[:url]&.start_with?('uln')
      response = api.remotes_uln_api.create(remote_file_data)
    else
      response = api.remotes_api.create(remote_file_data)
    end
    #delete is async, but if its not properly deleted, orphan cleanup will take care of it later
    delete_remote(href: response.pulp_href)
  end
end

#ignore_404_exceptionObject



50
51
52
53
54
55
# File 'app/services/katello/pulp3/service_common.rb', line 50

def ignore_404_exception(*)
  yield
rescue api.api_exception_class => e
  raise e unless e.code == 404
  nil
end

#reformat_api_exceptionObject



57
58
59
60
61
62
63
# File 'app/services/katello/pulp3/service_common.rb', line 57

def reformat_api_exception
  yield
rescue api.client_module::ApiError => exception
  body = JSON.parse(exception.response_body) rescue body
  body = body.values.join(',') if body.respond_to?(:values)
  raise ::Katello::Errors::Pulp3Error, body
end

#test_remote_nameObject



21
22
23
# File 'app/services/katello/pulp3/service_common.rb', line 21

def test_remote_name
  "test_remote_#{SecureRandom.uuid}"
end