Project

General

Profile

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

foreman_docker / app / controllers / api / v2 / registries_controller.rb @ 9d5ef1c9

1
module Api
2
  module V2
3
    class RegistriesController < ::Api::V2::BaseController
4
      include Foreman::Controller::Parameters::DockerRegistry
5
      before_action :find_resource, :except => %w(index create)
6

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

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

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

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

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

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

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

    
56
      private
57

    
58
      def resource_class
59
        DockerRegistry
60
      end
61

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