Project

General

Profile

Download (1.93 KB) Statistics
| Branch: | Tag: | Revision:

foreman-docker / app / controllers / api / v2 / registries_controller.rb @ 26c5ba32

1
module Api
2
  module V2
3
    class RegistriesController < ::Api::V2::BaseController
4
      before_filter :find_resource, :except => %w(index create)
5

    
6
      resource_description do
7
        resource_id 'registries'
8
        api_version 'v2'
9
        api_base_url '/docker/api/v2'
10
      end
11

    
12
      def_param_group :registry do
13
        param :registry, Hash, :required => true, :action_aware => true do
14
          param :name, String, :required => true
15
          param_group :taxonomies, ::Api::V2::BaseController
16
          param :url, String, :required => true
17
          param :description, String
18
          param :username, String
19
          param :password, String
20
        end
21
      end
22

    
23
      api :GET, '/registries/', N_('List all docker registries')
24
      param_group :search_and_pagination, ::Api::V2::BaseController
25
      def index
26
        @registries = DockerRegistry.search_for(params[:search], :order => params[:order])
27
                      .paginate(:page => params[:page])
28
      end
29

    
30
      api :GET, '/registries/:id', N_("Show a docker registry")
31
      param :id, :identifier, :required => true
32
      def show
33
      end
34

    
35
      api :POST, '/registries/', N_('Create a docker registry')
36
      param_group :registry, :as => :create
37
      def create
38
        @registry = DockerRegistry.new(params[:registry])
39
        process_response @registry.save
40
      end
41

    
42
      api :PUT, '/registries/:id', N_('Update a docker registry')
43
      param :id, :identifier, :required => true
44
      param_group :registry, :as => :update
45
      def update
46
        process_response @registry.update_attributes(params[:registry])
47
      end
48

    
49
      api :DELETE, '/registries/:id/', N_('Delete a docker registry')
50
      param :id, :identifier, :required => true
51
      def destroy
52
        process_response @registry.destroy
53
      end
54

    
55
      private
56

    
57
      def resource_class
58
        DockerRegistry
59
      end
60

    
61
      def docker_registry_url(registry)
62
        registry_url(registry)
63
      end
64
    end
65
  end
66
end