Class: ImageSearchController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ImageSearchController
- Defined in:
- app/controllers/image_search_controller.rb
Instance Method Summary collapse
- #action_permission ⇒ Object
- #auto_complete_image_tag ⇒ Object
- #auto_complete_repository_name ⇒ Object
- #catch_network_errors ⇒ Object
- #find_resource ⇒ Object
- #hub_auto_complete_image_tags(terms) ⇒ Object
- #hub_image_exists?(terms) ⇒ Boolean
- #hub_search_image(terms) ⇒ Object
- #registry_auto_complete_image_tags(terms) ⇒ Object
- #registry_image_exists?(term) ⇒ Boolean
- #registry_search_image(terms) ⇒ Object
- #search_repository ⇒ Object
- #use_hub? ⇒ Boolean
Instance Method Details
#action_permission ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'app/controllers/image_search_controller.rb', line 88 def case params[:action] when 'auto_complete_repository_name', 'auto_complete_image_tag', 'search_repository' :search_repository else super end end |
#auto_complete_image_tag ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/controllers/image_search_controller.rb', line 11 def auto_complete_image_tag catch_network_errors do # This is the format jQuery UI autocomplete expects = use_hub? ? (params[:search]) : (params[:search]) respond_to do |format| format.js do .map! { |tag| { :label => CGI.escapeHTML(tag), :value => CGI.escapeHTML(tag) } } render :json => end end end end |
#auto_complete_repository_name ⇒ Object
4 5 6 7 8 9 |
# File 'app/controllers/image_search_controller.rb', line 4 def auto_complete_repository_name catch_network_errors do render :text => (use_hub? ? hub_image_exists?(params[:search]) : registry_image_exists?(params[:search])).to_s end end |
#catch_network_errors ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/image_search_controller.rb', line 39 def catch_network_errors yield rescue Docker::Error::NotFoundError => e # not an error logger.debug "image not found: #{e.backtrace}" render :js, :nothing => true rescue Docker::Error::DockerError, Excon::Errors::Error, SystemCallError => e render :js => _("An error occured during repository search: '%s'") % e., :status => 500 end |
#find_resource ⇒ Object
97 98 99 100 101 102 103 104 105 |
# File 'app/controllers/image_search_controller.rb', line 97 def find_resource if params[:registry_id].present? @registry = DockerRegistry.(:view_registries).find(params[:registry_id]) else @compute_resource = ComputeResource.(:view_compute_resources).find(params[:id]) end rescue ActiveRecord::RecordNotFound not_found end |
#hub_auto_complete_image_tags(terms) ⇒ Object
58 59 60 |
# File 'app/controllers/image_search_controller.rb', line 58 def (terms) @compute_resource.(terms) end |
#hub_image_exists?(terms) ⇒ Boolean
54 55 56 |
# File 'app/controllers/image_search_controller.rb', line 54 def hub_image_exists?(terms) @compute_resource.exist?(terms) end |
#hub_search_image(terms) ⇒ Object
62 63 64 |
# File 'app/controllers/image_search_controller.rb', line 62 def hub_search_image(terms) @compute_resource.search(terms) end |
#registry_auto_complete_image_tags(terms) ⇒ Object
75 76 77 78 79 |
# File 'app/controllers/image_search_controller.rb', line 75 def (terms) ::Service::RegistryApi.new(:url => @registry.url, :user => @registry.username, :password => @registry.password).(terms).keys end |
#registry_image_exists?(term) ⇒ Boolean
66 67 68 69 70 71 72 73 |
# File 'app/controllers/image_search_controller.rb', line 66 def registry_image_exists?(term) result = ::Service::RegistryApi.new(:url => @registry.url, :user => @registry.username, :password => @registry.password).search(term) registry_name = term.split('/').size > 1 ? term : 'library/' + term result['results'].any? { |r| r['name'] == registry_name } end |
#registry_search_image(terms) ⇒ Object
81 82 83 84 85 86 |
# File 'app/controllers/image_search_controller.rb', line 81 def registry_search_image(terms) r = ::Service::RegistryApi.new(:url => @registry.url, :user => @registry.username, :password => @registry.password).search(terms) r['results'] end |
#search_repository ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/image_search_controller.rb', line 25 def search_repository catch_network_errors do repositories = use_hub? ? hub_search_image(params[:search]) : registry_search_image(params[:search]) respond_to do |format| format.js do render :partial => 'repository_search_results', :locals => { :repositories => repositories, :use_hub => use_hub? } end end end end |
#use_hub? ⇒ Boolean
50 51 52 |
# File 'app/controllers/image_search_controller.rb', line 50 def use_hub? @registry.nil? end |