Project

General

Profile

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

foreman_docker / app / controllers / api / v2 / registries_controller.rb @ d2e54db4

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 :url, String, :required => true
16
          param :description, String
17
          param :username, String
18
          param :password, String
19
        end
20
      end
21

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

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

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

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

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

    
54
      private
55

    
56
      def resource_class
57
        DockerRegistry
58
      end
59

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