Module: Katello::Pulp3::ServiceCommon
- Included in:
- AlternateContentSource, Repository
- Defined in:
- app/services/katello/pulp3/service_common.rb
Instance Method Summary collapse
- #create_remote ⇒ Object
-
#create_test_remote ⇒ Object
When updating a repository, we need to update the remote, but this is an async task.
- #ignore_404_exception ⇒ Object
- #reformat_api_exception ⇒ Object
- #test_remote_name ⇒ Object
Instance Method Details
#create_remote ⇒ Object
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 [:url]&.start_with?('uln') remote_file_data = api.class.remote_uln_class.new() else remote_file_data = api.remote_class.new() end reformat_api_exception do if [: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_remote ⇒ Object
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 = [:name] = test_remote_name if [:url]&.start_with?('uln') remote_file_data = api.class.remote_uln_class.new() else remote_file_data = api.remote_class.new() end reformat_api_exception do if [: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_exception ⇒ Object
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_exception ⇒ Object
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_name ⇒ Object
21 22 23 |
# File 'app/services/katello/pulp3/service_common.rb', line 21 def test_remote_name "test_remote_#{SecureRandom.uuid}" end |