Project

General

Profile

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

foreman_docker / lib / foreman_docker / engine.rb @ 8ffd2fd6

1 9c1fa5fb Daniel Lobato
require 'fast_gettext'
2
require 'gettext_i18n_rails'
3
require 'fog/fogdocker'
4
require 'wicked'
5 387babdd Daniel Lobato
require 'docker'
6 1aa3ddb3 Daniel Lobato
require 'deface'
7 d4e021f3 Amos Benari
8
module ForemanDocker
9 9c1fa5fb Daniel Lobato
  # Inherit from the Rails module of the parent app (Foreman), not the plugin.
10
  # Thus, inherits from ::Rails::Engine and not from Rails::Engine
11 d4e021f3 Amos Benari
  class Engine < ::Rails::Engine
12 916c5290 Dominic Cleal
    engine_name 'foreman_docker'
13
14 e4e8739b Daniel Lobato
    config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]
15 5dc4f6d6 Daniel Lobato
    config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
16
17 9c1fa5fb Daniel Lobato
    initializer 'foreman_docker.load_app_instance_data' do |app|
18 c80f3b10 Tom Caspy
      ForemanDocker::Engine.paths['db/migrate'].existent.each do |path|
19
        app.config.paths['db/migrate'] << path
20
      end
21 fa9ff801 Daniel Lobato
    end
22 d4e021f3 Amos Benari
23 0fabb199 Sebastian Gräßl
    foreman_docker_assets = %w[foreman_docker/autocomplete.css
24
                               foreman_docker/terminal.css
25 329cfcba Sebastian Gräßl
                               foreman_docker/container_image_search.js
26 0fabb199 Sebastian Gräßl
                               foreman_docker/create_registry.js]
27
28 751c6470 Daniel Lobato
    initializer "foreman_docker.assets.precompile" do |app|
29 0fabb199 Sebastian Gräßl
      app.config.assets.precompile += foreman_docker_assets
30 751c6470 Daniel Lobato
    end
31
32
    initializer 'foreman_docker.configure_assets', :group => :assets do
33 916c5290 Dominic Cleal
      SETTINGS[:foreman_docker] =
34 0fabb199 Sebastian Gräßl
        { :assets => { :precompile => foreman_docker_assets } }
35 751c6470 Daniel Lobato
    end
36
37 9c1fa5fb Daniel Lobato
    initializer 'foreman_docker.register_gettext', :after => :load_config_initializers do
38
      locale_dir = File.join(File.expand_path('../../..', __FILE__), 'locale')
39
      locale_domain = 'foreman_docker'
40 d4e021f3 Amos Benari
41
      Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
42
    end
43
44 6d9a867c Daniel Lobato
    initializer 'foreman_docker.register_plugin', :before => :finisher_hook do
45 d4e021f3 Amos Benari
      Foreman::Plugin.register :foreman_docker do
46 1b5f7caa Marek Hulán
        requires_foreman '>= 1.15'
47 29812b3a Dominic Cleal
        compute_resource ForemanDocker::Docker
48 fa9ff801 Daniel Lobato
49 dc3be9a0 David Davis
        sub_menu :top_menu, :containers_menu, :caption => N_('Containers'),
50 a223d2be Walden Raines
                                              :icon => 'fa fa-cube',
51 dc3be9a0 David Davis
                                              :after => :monitor_menu do
52 e5919f78 June Zhang
          menu :top_menu, :containers,    :caption => N_('All Containers'),
53 dc3be9a0 David Davis
                                          :url_hash => { :controller => :containers,
54
                                                         :action => :index }
55 60bdf22b June Zhang
          menu :top_menu, :new_container, :caption => N_('Create Container'),
56 dc3be9a0 David Davis
                                          :url_hash => { :controller => :containers,
57
                                                         :action => :new }
58 ada932ab Dmitri Dolguikh
          menu :top_menu, :registries, :caption => N_('Registries'),
59
                                       :url_hash => { :controller => :registries,
60
                                                      :action => :index }
61 fa9ff801 Daniel Lobato
        end
62 221cfd7c Daniel Lobato
63
        security_block :containers do
64 5274f6bc Daniel Lobato
          permission :view_containers,
65 d0846a1a Dmitri Dolguikh
                     { :containers          => [:index, :show],
66
                       :'api/v2/containers' => [:index, :show, :logs] },
67
                     :resource_type => 'Container'
68
          permission :commit_containers, { :containers => [:commit] },
69
                     :resource_type => 'Container'
70 5274f6bc Daniel Lobato
          permission :create_containers,
71 d0846a1a Dmitri Dolguikh
                     { :'containers/steps'  => [:show, :update],
72
                       :containers          => [:new],
73
                       :'api/v2/containers' => [:create, :power] },
74
                     :resource_type => 'Container'
75 5274f6bc Daniel Lobato
          permission :destroy_containers,
76 d0846a1a Dmitri Dolguikh
                     { :containers          => [:destroy],
77
                       :'api/v2/containers' => [:destroy] },
78
                     :resource_type => 'Container'
79 5274f6bc Daniel Lobato
          permission :power_compute_resources_vms,
80 d0846a1a Dmitri Dolguikh
                     { :containers          => [:power],
81
                       :'api/v2/containers' => [:create, :power] },
82
                     :resource_type => 'ComputeResource'
83 221cfd7c Daniel Lobato
        end
84 ada932ab Dmitri Dolguikh
85
        security_block :registries do
86 d2e54db4 David Davis
          permission :view_registries,
87
                     { :registries => [:index, :show],
88
                       :'api/v2/registries' => [:index, :show] },
89 d0846a1a Dmitri Dolguikh
                     :resource_type => 'DockerRegistry'
90 d2e54db4 David Davis
          permission :create_registries,
91
                     { :registries  => [:new, :create, :update, :edit],
92
                       :'api/v2/registries' => [:create, :update] },
93 d0846a1a Dmitri Dolguikh
                     :resource_type => 'DockerRegistry'
94 d2e54db4 David Davis
          permission :destroy_registries,
95
                     { :registries => [:destroy],
96
                       :'api/v2/registries' => [:destroy] },
97 d0846a1a Dmitri Dolguikh
                     :resource_type => 'DockerRegistry'
98 ada932ab Dmitri Dolguikh
        end
99 6d101d7a Dmitri Dolguikh
100
        security_block :image_search do
101
          permission :search_repository_image_search,
102 d0846a1a Dmitri Dolguikh
                     { :image_search => [:auto_complete_repository_name,
103
                                         :auto_complete_image_tag,
104
                                         :search_repository] },
105 8ffd2fd6 Daniel Lobato García
                     :resource_type => 'DockerRegistry'
106 6d101d7a Dmitri Dolguikh
        end
107 5274f6bc Daniel Lobato
108 1b5f7caa Marek Hulán
        add_all_permissions_to_default_roles
109
110 cc6d0d73 David Davis
        parameter_filter ComputeResource, :email
111
112 5274f6bc Daniel Lobato
        # apipie API documentation
113
        # Only available in 1.8, otherwise it has to be in the initializer below
114
        if SETTINGS[:version].to_s.include?('develop') ||
115 8a1d63a3 David Davis
           Gem::Version.new(SETTINGS[:version].notag) >= Gem::Version.new('1.8')
116 5274f6bc Daniel Lobato
          apipie_documented_controllers [
117
            "#{ForemanDocker::Engine.root}/app/controllers/api/v2/*.rb"]
118
        end
119
      end
120
    end
121
122
    initializer "foreman_docker.apipie" do
123
      # this condition is here for compatibility reason to work with Foreman 1.4.x
124
      # Also need to handle the reverse of the 1.8 method above
125
      unless SETTINGS[:version].to_s.include?('develop') ||
126 8a1d63a3 David Davis
             Gem::Version.new(SETTINGS[:version].notag) >= Gem::Version.new('1.8')
127 5274f6bc Daniel Lobato
        if Apipie.configuration.api_controllers_matcher.is_a?(Array)
128
          Apipie.configuration.api_controllers_matcher <<
129
            "#{ForemanDocker::Engine.root}/app/controllers/api/v2/*.rb"
130
        end
131 d4e021f3 Amos Benari
      end
132
    end
133 466cd5ba Daniel Lobato
134 5d7016fd Daniel Lobato
    require 'fog/fogdocker/models/compute/server'
135
    require 'fog/fogdocker/models/compute/image'
136 9f0918fc Daniel Lobato
    require 'fog/fogdocker/models/compute/images'
137 5d7016fd Daniel Lobato
    require File.expand_path('../../../app/models/concerns/fog_extensions/fogdocker/server',
138
                             __FILE__)
139
    require File.expand_path('../../../app/models/concerns/fog_extensions/fogdocker/image',
140
                             __FILE__)
141 9f0918fc Daniel Lobato
    require File.expand_path('../../../app/models/concerns/fog_extensions/fogdocker/images',
142
                             __FILE__)
143 5d7016fd Daniel Lobato
    config.to_prepare do
144
      Fog::Compute::Fogdocker::Server.send(:include, ::FogExtensions::Fogdocker::Server)
145
      Fog::Compute::Fogdocker::Image.send(:include, ::FogExtensions::Fogdocker::Image)
146 9f0918fc Daniel Lobato
      # Compatibility fixes - to be removed once 1.7 compatibility is no longer required
147
      Fog::Compute::Fogdocker::Images.send(:include, ::FogExtensions::Fogdocker::Images)
148 5d7016fd Daniel Lobato
      ::Taxonomy.send(:include, ForemanDocker::TaxonomyExtensions)
149 a373b4f6 Swapnil Abnave
      ComputeResource.send(:include, ForemanDocker::ComputeResourceExtensions)
150 5d7016fd Daniel Lobato
    end
151
  end
152 29812b3a Dominic Cleal
end