foreman_puppet 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (247) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +619 -0
  3. data/README.md +38 -0
  4. data/Rakefile +31 -0
  5. data/app/assets/stylesheets/foreman_puppet.scss +117 -0
  6. data/app/controllers/concerns/foreman_puppet/api/import_puppetclasses_common_controller.rb +139 -0
  7. data/app/controllers/concerns/foreman_puppet/environments_import.rb +61 -0
  8. data/app/controllers/concerns/foreman_puppet/extensions/api_hostgroups_controller.rb +40 -0
  9. data/app/controllers/concerns/foreman_puppet/extensions/api_template_combinations_controller.rb +23 -0
  10. data/app/controllers/concerns/foreman_puppet/extensions/api_v2_hosts_controller.rb +48 -0
  11. data/app/controllers/concerns/foreman_puppet/extensions/hostgroups_controller_extensions.rb +58 -0
  12. data/app/controllers/concerns/foreman_puppet/extensions/hosts_controller_extensions.rb +228 -0
  13. data/app/controllers/concerns/foreman_puppet/extensions/operatingsystems_controller.rb +11 -0
  14. data/app/controllers/concerns/foreman_puppet/extensions/parameters_host.rb +75 -0
  15. data/app/controllers/concerns/foreman_puppet/extensions/parameters_hostgroup.rb +70 -0
  16. data/app/controllers/concerns/foreman_puppet/extensions/parameters_template_combination.rb +21 -0
  17. data/app/controllers/concerns/foreman_puppet/parameters/config_group.rb +17 -0
  18. data/app/controllers/concerns/foreman_puppet/parameters/environment.rb +21 -0
  19. data/app/controllers/concerns/foreman_puppet/parameters/puppetclass.rb +24 -0
  20. data/app/controllers/concerns/foreman_puppet/parameters/puppetclass_lookup_key.rb +24 -0
  21. data/app/controllers/foreman_puppet/api/v2/base_controller.rb +26 -0
  22. data/app/controllers/foreman_puppet/api/v2/config_groups_controller.rb +57 -0
  23. data/app/controllers/foreman_puppet/api/v2/environments_controller.rb +91 -0
  24. data/app/controllers/foreman_puppet/api/v2/host_classes_controller.rb +59 -0
  25. data/app/controllers/foreman_puppet/api/v2/hostgroup_classes_controller.rb +46 -0
  26. data/app/controllers/foreman_puppet/api/v2/lookups_common_controller.rb +114 -0
  27. data/app/controllers/foreman_puppet/api/v2/override_values_controller.rb +99 -0
  28. data/app/controllers/foreman_puppet/api/v2/puppetclasses_controller.rb +99 -0
  29. data/app/controllers/foreman_puppet/api/v2/smart_class_parameters_controller.rb +76 -0
  30. data/app/controllers/foreman_puppet/config_groups_controller.rb +46 -0
  31. data/app/controllers/foreman_puppet/environments_controller.rb +51 -0
  32. data/app/controllers/foreman_puppet/puppet_smart_proxies_controller.rb +39 -0
  33. data/app/controllers/foreman_puppet/puppetclass_lookup_keys_controller.rb +33 -0
  34. data/app/controllers/foreman_puppet/puppetclasses_controller.rb +113 -0
  35. data/app/controllers/foreman_puppet/react_controller.rb +19 -0
  36. data/app/helpers/concerns/foreman_puppet/template_renderer_scope.rb +14 -0
  37. data/app/helpers/foreman_puppet/environments_helper.rb +17 -0
  38. data/app/helpers/foreman_puppet/hosts_and_hostgroups_helper.rb +96 -0
  39. data/app/helpers/foreman_puppet/hosts_helper.rb +32 -0
  40. data/app/helpers/foreman_puppet/puppet_smart_proxies_helper.rb +8 -0
  41. data/app/helpers/foreman_puppet/puppetclass_lookup_keys_helper.rb +135 -0
  42. data/app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb +55 -0
  43. data/app/helpers/foreman_puppet/puppetclasses_helper.rb +59 -0
  44. data/app/helpers/foreman_puppet/template_combinations_helper.rb +33 -0
  45. data/app/models/concerns/foreman_puppet/extensions/host.rb +88 -0
  46. data/app/models/concerns/foreman_puppet/extensions/hostgroup.rb +40 -0
  47. data/app/models/concerns/foreman_puppet/extensions/nic_managed.rb +11 -0
  48. data/app/models/concerns/foreman_puppet/extensions/operatingsystem.rb +11 -0
  49. data/app/models/concerns/foreman_puppet/extensions/provisioning_template.rb +64 -0
  50. data/app/models/concerns/foreman_puppet/extensions/report.rb +11 -0
  51. data/app/models/concerns/foreman_puppet/extensions/taxonomy.rb +19 -0
  52. data/app/models/concerns/foreman_puppet/extensions/template_combination.rb +23 -0
  53. data/app/models/concerns/foreman_puppet/extensions/user.rb +22 -0
  54. data/app/models/concerns/foreman_puppet/host_common.rb +90 -0
  55. data/app/models/concerns/foreman_puppet/puppet_lookup_value_extensions.rb +13 -0
  56. data/app/models/foreman_puppet/config_group.rb +45 -0
  57. data/app/models/foreman_puppet/config_group_class.rb +19 -0
  58. data/app/models/foreman_puppet/environment.rb +63 -0
  59. data/app/models/foreman_puppet/environment_class.rb +40 -0
  60. data/app/models/foreman_puppet/host_class.rb +23 -0
  61. data/app/models/foreman_puppet/host_config_group.rb +15 -0
  62. data/app/models/foreman_puppet/host_puppet_facet.rb +130 -0
  63. data/app/models/foreman_puppet/hostgroup_class.rb +23 -0
  64. data/app/models/foreman_puppet/hostgroup_puppet_facet.rb +98 -0
  65. data/app/models/foreman_puppet/puppetclass.rb +132 -0
  66. data/app/models/foreman_puppet/puppetclass_lookup_key.rb +58 -0
  67. data/app/services/foreman_puppet/host_info_providers/config_groups_info.rb +10 -0
  68. data/app/services/foreman_puppet/host_info_providers/puppet_info.rb +92 -0
  69. data/app/services/foreman_puppet/input_type/puppet_parameter_input.rb +35 -0
  70. data/app/services/foreman_puppet/proxy_status/puppet.rb +17 -0
  71. data/app/services/foreman_puppet/puppet_class_importer.rb +355 -0
  72. data/app/views/api/v2/template_combinations/base.json.erb +9 -0
  73. data/app/views/foreman_puppet/api/v2/config_groups/base.json.rabl +3 -0
  74. data/app/views/foreman_puppet/api/v2/config_groups/create.json.rabl +3 -0
  75. data/app/views/foreman_puppet/api/v2/config_groups/index.json.rabl +3 -0
  76. data/app/views/foreman_puppet/api/v2/config_groups/main.json.rabl +8 -0
  77. data/app/views/foreman_puppet/api/v2/config_groups/show.json.rabl +3 -0
  78. data/app/views/foreman_puppet/api/v2/config_groups/update.json.rabl +3 -0
  79. data/app/views/foreman_puppet/api/v2/environments/base.json.rabl +3 -0
  80. data/app/views/foreman_puppet/api/v2/environments/create.json.rabl +3 -0
  81. data/app/views/foreman_puppet/api/v2/environments/index.json.rabl +3 -0
  82. data/app/views/foreman_puppet/api/v2/environments/main.json.rabl +5 -0
  83. data/app/views/foreman_puppet/api/v2/environments/show.json.rabl +15 -0
  84. data/app/views/foreman_puppet/api/v2/environments/update.json.rabl +3 -0
  85. data/app/views/foreman_puppet/api/v2/host_puppet_facets/base.json.rabl +1 -0
  86. data/app/views/foreman_puppet/api/v2/host_puppet_facets/host_single.json.rabl +17 -0
  87. data/app/views/foreman_puppet/api/v2/host_puppet_facets/show.json.rabl +11 -0
  88. data/app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/base.json.rabl +5 -0
  89. data/app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/hostgroup_single.json.rabl +16 -0
  90. data/app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/show.json.rabl +11 -0
  91. data/app/views/foreman_puppet/api/v2/import_puppetclasses/index.json.rabl +3 -0
  92. data/app/views/foreman_puppet/api/v2/import_puppetclasses/show.json.rabl +36 -0
  93. data/app/views/foreman_puppet/api/v2/override_values/create.json.rabl +3 -0
  94. data/app/views/foreman_puppet/api/v2/override_values/index.json.rabl +3 -0
  95. data/app/views/foreman_puppet/api/v2/override_values/show.json.rabl +3 -0
  96. data/app/views/foreman_puppet/api/v2/override_values/update.json.rabl +3 -0
  97. data/app/views/foreman_puppet/api/v2/puppetclasses/base.json.rabl +3 -0
  98. data/app/views/foreman_puppet/api/v2/puppetclasses/create.json.rabl +3 -0
  99. data/app/views/foreman_puppet/api/v2/puppetclasses/index.json.rabl +4 -0
  100. data/app/views/foreman_puppet/api/v2/puppetclasses/list.json.rabl +3 -0
  101. data/app/views/foreman_puppet/api/v2/puppetclasses/main.json.rabl +5 -0
  102. data/app/views/foreman_puppet/api/v2/puppetclasses/show.json.rabl +15 -0
  103. data/app/views/foreman_puppet/api/v2/puppetclasses/update.json.rabl +3 -0
  104. data/app/views/foreman_puppet/api/v2/smart_class_parameters/base.json.rabl +4 -0
  105. data/app/views/foreman_puppet/api/v2/smart_class_parameters/create.json.rabl +3 -0
  106. data/app/views/foreman_puppet/api/v2/smart_class_parameters/destroy.json.rabl +3 -0
  107. data/app/views/foreman_puppet/api/v2/smart_class_parameters/index.json.rabl +3 -0
  108. data/app/views/foreman_puppet/api/v2/smart_class_parameters/main.json.rabl +23 -0
  109. data/app/views/foreman_puppet/api/v2/smart_class_parameters/show.json.rabl +19 -0
  110. data/app/views/foreman_puppet/api/v2/smart_class_parameters/update.json.rabl +3 -0
  111. data/app/views/foreman_puppet/config_groups/_config_group.html.erb +34 -0
  112. data/app/views/foreman_puppet/config_groups/_config_groups_selection.html.erb +36 -0
  113. data/app/views/foreman_puppet/config_groups/_form.html.erb +9 -0
  114. data/app/views/foreman_puppet/config_groups/edit.html.erb +3 -0
  115. data/app/views/foreman_puppet/config_groups/index.html.erb +31 -0
  116. data/app/views/foreman_puppet/config_groups/new.html.erb +3 -0
  117. data/app/views/foreman_puppet/config_groups/welcome.html.erb +12 -0
  118. data/app/views/foreman_puppet/environments/_form.html.erb +20 -0
  119. data/app/views/foreman_puppet/environments/edit.html.erb +8 -0
  120. data/app/views/foreman_puppet/environments/index.html.erb +32 -0
  121. data/app/views/foreman_puppet/environments/new.html.erb +7 -0
  122. data/app/views/foreman_puppet/environments/welcome.html.erb +16 -0
  123. data/app/views/foreman_puppet/layouts/application_react.html.erb +15 -0
  124. data/app/views/foreman_puppet/puppet_smart_proxies/_dashboard.html.erb +9 -0
  125. data/app/views/foreman_puppet/puppet_smart_proxies/_environments.html.erb +30 -0
  126. data/app/views/foreman_puppet/puppetclass_lookup_keys/edit.html.erb +3 -0
  127. data/app/views/foreman_puppet/puppetclass_lookup_keys/index.html.erb +22 -0
  128. data/app/views/foreman_puppet/puppetclass_lookup_keys/welcome.html.erb +9 -0
  129. data/app/views/foreman_puppet/puppetclasses/_class_parameters.html.erb +37 -0
  130. data/app/views/foreman_puppet/puppetclasses/_class_selection.html.erb +70 -0
  131. data/app/views/foreman_puppet/puppetclasses/_classes.html.erb +22 -0
  132. data/app/views/foreman_puppet/puppetclasses/_classes_in_groups.html.erb +5 -0
  133. data/app/views/foreman_puppet/puppetclasses/_classes_parameters.html.erb +16 -0
  134. data/app/views/foreman_puppet/puppetclasses/_form.html.erb +62 -0
  135. data/app/views/foreman_puppet/puppetclasses/_selected_classes.html.erb +4 -0
  136. data/app/views/foreman_puppet/puppetclasses/edit.html.erb +4 -0
  137. data/app/views/foreman_puppet/puppetclasses/index.html.erb +47 -0
  138. data/app/views/hosts/_form_puppet_enc_tab.html.erb +24 -0
  139. data/app/views/hosts/foreman_puppet/_form_main_tab_fields.html.erb +1 -0
  140. data/app/views/hosts/select_multiple_environment.html.erb +8 -0
  141. data/app/views/provisioning_templates/_combination.html.erb +5 -0
  142. data/app/views/provisioning_templates/_combinations.html.erb +6 -0
  143. data/app/views/smart_proxies/plugins/_puppet.html.erb +24 -0
  144. data/config/api_routes.rb +81 -0
  145. data/config/routes.rb +89 -0
  146. data/db/migrate/20101121140000_add_environment_to_template_combinations.foreman_puppet.rb +9 -0
  147. data/db/migrate/20200720123005_migrate_puppet_core_types.foreman_puppet.rb +19 -0
  148. data/db/migrate/20200722171017_create_host_puppet_facet.foreman_puppet.rb +10 -0
  149. data/db/migrate/20200803113531_create_hostgroup_puppet_facet.foreman_puppet.rb +10 -0
  150. data/db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb +22 -0
  151. data/db/migrate/20200803113903_migrate_host_type_in_host_config_groups.foreman_puppet.rb +29 -0
  152. data/db/migrate/20201125113903_migrate_puppetclasses_to_facets.foreman_puppet.rb +47 -0
  153. data/db/migrate_foreman/20090722141107_create_environments.rb +17 -0
  154. data/db/migrate_foreman/20120905095532_create_environment_classes.rb +15 -0
  155. data/db/migrate_foreman/20140407161817_create_config_groups.rb +9 -0
  156. data/db/migrate_foreman/20140407162007_create_config_group_classes.rb +10 -0
  157. data/db/migrate_foreman/20140407162059_create_host_config_groups.rb +11 -0
  158. data/db/migrate_foreman/20161205142618_delete_orphaned_smart_class_parameters.rb +10 -0
  159. data/db/migrate_foreman/20170109115157_fix_lookup_key_auditable_type.rb +15 -0
  160. data/db/migrate_foreman/20180816134832_cast_lookup_key_values.rb +35 -0
  161. data/db/migrate_foreman/20181023112532_add_environment_puppetclass_id.rb +7 -0
  162. data/db/migrate_foreman/20181224174419_add_index_to_environment_class_by_lookup_key_and_puppetclass.rb +6 -0
  163. data/db/seeds.d/111_puppet_proxy_feature.rb +8 -0
  164. data/lib/foreman_puppet.rb +10 -0
  165. data/lib/foreman_puppet/engine.rb +82 -0
  166. data/lib/foreman_puppet/register.rb +218 -0
  167. data/lib/foreman_puppet/version.rb +3 -0
  168. data/lib/tasks/foreman_puppet_tasks.rake +31 -0
  169. data/locale/Makefile +60 -0
  170. data/locale/action_names.rb +5 -0
  171. data/locale/en/foreman_puppet.edit.po +911 -0
  172. data/locale/en/foreman_puppet.po +690 -0
  173. data/locale/en/foreman_puppet.po.time_stamp +0 -0
  174. data/locale/foreman_puppet.pot +1076 -0
  175. data/locale/gemspec.rb +2 -0
  176. data/test/controllers/foreman_puppet/api/v2/config_groups_controller_test.rb +28 -0
  177. data/test/controllers/foreman_puppet/api/v2/environments_controller_test.rb +346 -0
  178. data/test/controllers/foreman_puppet/api/v2/host_classes_controller_test.rb +48 -0
  179. data/test/controllers/foreman_puppet/api/v2/hostgroup_classes_controller_test.rb +41 -0
  180. data/test/controllers/foreman_puppet/api/v2/hostgroups_controller_test.rb +79 -0
  181. data/test/controllers/foreman_puppet/api/v2/hosts_controller_test.rb +101 -0
  182. data/test/controllers/foreman_puppet/api/v2/lookups_common_controller_test.rb +29 -0
  183. data/test/controllers/foreman_puppet/api/v2/override_values_controller_test.rb +169 -0
  184. data/test/controllers/foreman_puppet/api/v2/puppetclasses_controller_test.rb +144 -0
  185. data/test/controllers/foreman_puppet/api/v2/smart_class_parameters_controller_test.rb +557 -0
  186. data/test/controllers/foreman_puppet/api/v2/template_combinations_controller_test.rb +81 -0
  187. data/test/controllers/foreman_puppet/config_groups_controller_test.rb +47 -0
  188. data/test/controllers/foreman_puppet/environments_controller_test.rb +230 -0
  189. data/test/controllers/foreman_puppet/hostgroups_controller_test.rb +72 -0
  190. data/test/controllers/foreman_puppet/hosts_controller_test.rb +346 -0
  191. data/test/controllers/foreman_puppet/puppet_smart_proxies_controller_test.rb +29 -0
  192. data/test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb +59 -0
  193. data/test/controllers/foreman_puppet/puppetclasses_controller_test.rb +235 -0
  194. data/test/controllers/provisioning_templates_controller_test.rb +70 -0
  195. data/test/factories/foreman_puppet_factories.rb +134 -0
  196. data/test/factories/host_puppet_enhancements.rb +61 -0
  197. data/test/factories/proxy_puppet_enhancements.rb +33 -0
  198. data/test/helpers/foreman_puppet/hosts_and_hostgroups_helper_test.rb +65 -0
  199. data/test/helpers/foreman_puppet/puppetclasses_helper_test.rb +33 -0
  200. data/test/integration/foreman_puppet/environment_js_test.rb +27 -0
  201. data/test/integration/foreman_puppet/host_js_test.rb +371 -0
  202. data/test/integration/foreman_puppet/hostgroup_js_test.rb +100 -0
  203. data/test/integration/foreman_puppet/puppetclass_js_test.rb +37 -0
  204. data/test/integration/foreman_puppet/smartclass_parameter_js_test.rb +84 -0
  205. data/test/models/foreman_puppet/config_group_class_test.rb +9 -0
  206. data/test/models/foreman_puppet/config_group_test.rb +8 -0
  207. data/test/models/foreman_puppet/environment_test.rb +92 -0
  208. data/test/models/foreman_puppet/host_config_group_test.rb +39 -0
  209. data/test/models/foreman_puppet/host_puppet_facet_test.rb +116 -0
  210. data/test/models/foreman_puppet/host_test.rb +288 -0
  211. data/test/models/foreman_puppet/hostgroup_puppet_facet_test.rb +200 -0
  212. data/test/models/foreman_puppet/hostgroup_test.rb +14 -0
  213. data/test/models/foreman_puppet/lookup_value_test.rb +69 -0
  214. data/test/models/foreman_puppet/provisioning_template_test.rb +124 -0
  215. data/test/models/foreman_puppet/puppetclass_lookup_key_test.rb +81 -0
  216. data/test/models/foreman_puppet/puppetclass_test.rb +144 -0
  217. data/test/models/foreman_puppet/smart_proxy_test.rb +28 -0
  218. data/test/qraphql/queries/host_puppet_query_test.rb +36 -0
  219. data/test/qraphql/queries/hostgroup_puppet_query_test.rb +36 -0
  220. data/test/services/foreman_puppet/host_info_providers/puppet_info_test.rb +791 -0
  221. data/test/services/foreman_puppet/input_type/puppet_parameter_input_test.rb +14 -0
  222. data/test/test_puppet_helper.rb +30 -0
  223. data/test/unit/foreman_puppet/access_permissions_test.rb +16 -0
  224. data/test/unit/foreman_puppet/puppet_class_importer_test.rb +247 -0
  225. data/test/unit/foreman_puppet/template_rendering_test.rb +20 -0
  226. data/test/unit/foreman_puppet_test.rb +11 -0
  227. data/webpack/__mocks__/foremanReact/common/I18n.js +7 -0
  228. data/webpack/__mocks__/foremanReact/components/Layout/LayoutActions.js +2 -0
  229. data/webpack/__mocks__/foremanReact/readme.md +11 -0
  230. data/webpack/__mocks__/foremanReact/redux/API/APISelectors.js +10 -0
  231. data/webpack/__mocks__/foremanReact/redux/API/index.js +10 -0
  232. data/webpack/__mocks__/foremanReact/redux/actions/toasts.js +8 -0
  233. data/webpack/__mocks__/foremanReact/redux/index.js +1 -0
  234. data/webpack/__mocks__/foremanReact/redux/middlewares/IntervalMiddleware.js +5 -0
  235. data/webpack/fills_index.js +30 -0
  236. data/webpack/index.js +18 -0
  237. data/webpack/src/ForemanPuppet.js +11 -0
  238. data/webpack/src/Router/__snapshots__/routes.test.js.snap +3 -0
  239. data/webpack/src/Router/index.js +14 -0
  240. data/webpack/src/Router/routes.js +3 -0
  241. data/webpack/src/Router/routes.test.js +16 -0
  242. data/webpack/src/foreman_class_edit.js +224 -0
  243. data/webpack/src/foreman_puppet_host_form.js +140 -0
  244. data/webpack/src/foreman_puppet_host_form.test.js +65 -0
  245. data/webpack/src/index.js +1 -0
  246. data/webpack/src/reducers.js +7 -0
  247. metadata +340 -0
@@ -0,0 +1,17 @@
1
+ class CreateEnvironments < ActiveRecord::Migration[5.0]
2
+ def up
3
+ create_table :environments do |t|
4
+ t.string :name, null: false, limit: 255
5
+ t.timestamps null: true
6
+ end
7
+ create_table :environments_puppetclasses do |t|
8
+ t.references :puppetclass, foreign_key: true
9
+ t.references :environment, foreign_key: true
10
+ end
11
+ end
12
+
13
+ def down
14
+ drop_table :environments
15
+ drop_table :environments_puppetclasses
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ class CreateEnvironmentClasses < ActiveRecord::Migration[5.0]
2
+ class EnvironmentClass < ApplicationRecord; end
3
+
4
+ def up
5
+ rename_table :environments_puppetclasses, :environment_classes
6
+ add_column :environment_classes, :puppetclass_lookup_key_id, :integer
7
+ add_foreign_key :environment_classes, :lookup_keys, column: :puppetclass_lookup_key_id, name: 'environment_classes_lookup_key_id_fk'
8
+ end
9
+
10
+ def down
11
+ remove_foreign_key :environment_classes, :lookup_key
12
+ drop_column :environment_classes, :puppetclass_lookup_key_id, :integer
13
+ rename_table :environment_classes, :environments_puppetclasses
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ class CreateConfigGroups < ActiveRecord::Migration[4.2]
2
+ def change
3
+ create_table :config_groups do |t|
4
+ t.string :name, limit: 255
5
+
6
+ t.timestamps null: true
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ class CreateConfigGroupClasses < ActiveRecord::Migration[4.2]
2
+ def change
3
+ create_table :config_group_classes do |t|
4
+ t.integer :puppetclass_id
5
+ t.integer :config_group_id
6
+
7
+ t.timestamps null: true
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ class CreateHostConfigGroups < ActiveRecord::Migration[4.2]
2
+ def change
3
+ create_table :host_config_groups do |t|
4
+ t.integer :config_group_id
5
+ t.integer :host_id
6
+ t.string :host_type, limit: 255
7
+
8
+ t.timestamps null: true
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ class DeleteOrphanedSmartClassParameters < ActiveRecord::Migration[4.2]
2
+ def up
3
+ condition = 'NOT EXISTS (SELECT 1 FROM environment_classes WHERE environment_classes.puppetclass_lookup_key_id = lookup_keys.id)'
4
+ LookupValue.joins(:lookup_key).where(condition).where("lookup_keys.type = 'PuppetclassLookupKey'").delete_all
5
+ PuppetclassLookupKey.where(condition).delete_all
6
+ end
7
+
8
+ def down
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ class FixLookupKeyAuditableType < ActiveRecord::Migration[4.2]
2
+ def up
3
+ Audit.reorder(nil).joins('JOIN lookup_keys ON lookup_keys.id = audits.auditable_id')
4
+ .where(auditable_type: 'LookupKey', lookup_keys: { type: 'VariableLookupKey' })
5
+ .update_all(auditable_type: 'VariableLookupKey')
6
+
7
+ Audit.reorder(nil).joins('JOIN lookup_keys ON lookup_keys.id = audits.auditable_id')
8
+ .where(auditable_type: 'LookupKey', lookup_keys: { type: 'PuppetclassLookupKey' })
9
+ .update_all(auditable_type: 'PuppetclassLookupKey')
10
+ end
11
+
12
+ def down
13
+ Audit.where(auditable_type: %w[PuppetclassLookupKey VariableLookupKey]).update_all(auditable_type: 'LookupKey')
14
+ end
15
+ end
@@ -0,0 +1,35 @@
1
+ class CastLookupKeyValues < ActiveRecord::Migration[5.1]
2
+ def up
3
+ # Different LookupKey types handle casting a bit differently
4
+ PuppetclassLookupKey.unscoped.preload(:lookup_values).where(override: true).where.not(key_type: 'string').find_each do |key|
5
+ cast_key_and_values(key)
6
+ end
7
+ end
8
+
9
+ private
10
+
11
+ def cast_key_and_values(key)
12
+ fix_value(key, :default_value)
13
+ key.lookup_values.each do |lv|
14
+ fix_value(lv, :value)
15
+ end
16
+ end
17
+
18
+ def safemode_box
19
+ @safemode_box ||= Safemode::Box.new
20
+ end
21
+
22
+ def fix_value(obj, attribute)
23
+ return if obj.omit && !obj.try(:merge_default)
24
+ value = obj.send(attribute)
25
+ return unless value.is_a? String
26
+ return if value.contains_erb?
27
+ fixed = safemode_box.eval(value)
28
+ obj.update_column(attribute, fixed)
29
+ rescue StandardError => e
30
+ say "Failed to cast #{attribute} for #{obj.inspect}:"
31
+ say "Value: #{value}", subitem: true
32
+ say "Error: #{e.message}", subitem: true
33
+ say 'Perhaps it is invalid? Casting skipped, manual action may be needed.', subitem: true
34
+ end
35
+ end
@@ -0,0 +1,7 @@
1
+ # Added in theforeman/foreman#bb07c3b1cf
2
+ class AddEnvironmentPuppetclassId < ActiveRecord::Migration[5.2]
3
+ def change
4
+ add_index :environment_classes, %i[environment_id puppetclass_id]
5
+ remove_index :environment_classes, :environment_id
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ # Added in theforeman/foreman#6d9e2b7c61
2
+ class AddIndexToEnvironmentClassByLookupKeyAndPuppetclass < ActiveRecord::Migration[5.2]
3
+ def change
4
+ add_index :environment_classes, %i[puppetclass_lookup_key_id puppetclass_id], name: 'index_env_classes_on_lookup_key_and_class'
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ proxy_features = %w[Puppet]
4
+
5
+ proxy_features.each do |f_name|
6
+ f = Feature.where(name: f_name).first_or_create
7
+ raise "Unable to create proxy feature: #{format_errors f}" if f.nil? || f.errors.any?
8
+ end
@@ -0,0 +1,10 @@
1
+ module ForemanPuppet
2
+ FOREMAN_EXTRACTION_VERSION = '2.5'.freeze
3
+
4
+ def self.extracted_from_core?
5
+ ENV['PUPPET_EXTRACTED'] == '1' ||
6
+ Gem::Dependency.new('', ">= #{FOREMAN_EXTRACTION_VERSION}").match?('', SETTINGS[:version])
7
+ end
8
+ end
9
+
10
+ require 'foreman_puppet/engine'
@@ -0,0 +1,82 @@
1
+ module ForemanPuppet
2
+ class Engine < ::Rails::Engine
3
+ engine_name 'foreman_puppet'
4
+ isolate_namespace ForemanPuppet
5
+
6
+ config.paths['db/migrate'] << 'db/migrate_foreman' if Gem::Dependency.new('', ">= #{ForemanPuppet::FOREMAN_EXTRACTION_VERSION}").match?('', SETTINGS[:version])
7
+ config.paths['config/routes.rb'].unshift('config/api_routes.rb')
8
+
9
+ initializer 'foreman_puppet.register_plugin', before: :finisher_hook do |_app|
10
+ require 'foreman_puppet/register'
11
+ Apipie.configuration.checksum_path += ['/foreman_puppet/api/']
12
+ end
13
+
14
+ initializer 'foreman_puppet.migrate_by_default' do |app|
15
+ unless Object.const_defined?(:APP_RAKEFILE)
16
+ paths['db/migrate'].existent.each do |path|
17
+ app.config.paths['db/migrate'] << path
18
+ end
19
+ end
20
+ end
21
+
22
+ initializer 'foreman_ansible.configure_assets', group: :assets do
23
+ SETTINGS[:foreman_puppet] = { assets: { precompile: ['foreman_puppet.scss'] } }
24
+ end
25
+
26
+ # Include concerns in this config.to_prepare block
27
+ config.to_prepare do
28
+ # Parameters should go ASAP as they need to be applied before they are included in core controller
29
+ Foreman::Controller::Parameters::Host.include ForemanPuppet::Extensions::ParametersHost
30
+ Foreman::Controller::Parameters::Hostgroup.include ForemanPuppet::Extensions::ParametersHostgroup
31
+ Foreman::Controller::Parameters::TemplateCombination.include ForemanPuppet::Extensions::ParametersTemplateCombination
32
+
33
+ # Facets extenstion is applied too early - before the Hostgroup is complete
34
+ # We redefine thing, so we need to wait until complete definition of Hostgroup
35
+ # thus separate patching instead of using facet patching
36
+ Hostgroup.include ForemanPuppet::Extensions::Hostgroup
37
+
38
+ # include_in_clone that is used in core Facets::ManagedHostExtensions doesn't support nested objects
39
+ # we need to run our include_in_clone after, so the puppet without nested objects doesnt override the one including them
40
+ Host::Managed.include ForemanPuppet::Extensions::Host
41
+
42
+ LookupValue.include ForemanPuppet::PuppetLookupValueExtensions
43
+ Operatingsystem.include ForemanPuppet::Extensions::Operatingsystem
44
+ Nic::Managed.include ForemanPuppet::Extensions::NicManaged
45
+ Report.include ForemanPuppet::Extensions::Report
46
+ Taxonomy.include ForemanPuppet::Extensions::Taxonomy
47
+ User.include ForemanPuppet::Extensions::User
48
+ TemplateCombination.include ForemanPuppet::Extensions::TemplateCombination
49
+ ProvisioningTemplate.include ForemanPuppet::Extensions::ProvisioningTemplate
50
+
51
+ ::Api::V2::HostsController.include ForemanPuppet::Extensions::ApiV2HostsController
52
+ ::Api::V2::HostgroupsController.include ForemanPuppet::Extensions::ApiHostgroupsController
53
+ ::Api::V2::TemplateCombinationsController.include ForemanPuppet::Extensions::ApiTemplateCombinationsController
54
+ OperatingsystemsController.prepend ForemanPuppet::Extensions::OperatingsystemsController
55
+ HostsController.include ForemanPuppet::Extensions::HostsControllerExtensions
56
+ HostgroupsController.include ForemanPuppet::Extensions::HostgroupsControllerExtensions
57
+
58
+ SmartProxiesHelper::TABBED_FEATURES << 'Puppet'
59
+
60
+ unless ForemanPuppet.extracted_from_core?
61
+ ::HostInfo.local_entries.delete('HostInfoProviders::PuppetInfo'.safe_constantize)
62
+ ::HostInfo.local_entries.delete('HostInfoProviders::ConfigGroupsInfo'.safe_constantize)
63
+ ::ProxyStatus.status_registry.delete('ProxyStatus::Puppet'.safe_constantize)
64
+ Foreman.input_types_registry.input_types.delete('puppet_parameter')
65
+ end
66
+ Foreman.input_types_registry.register(ForemanPuppet::InputType::PuppetParameterInput)
67
+ ::ProxyStatus.status_registry.add(ForemanPuppet::ProxyStatus::Puppet)
68
+ end
69
+
70
+ rake_tasks do
71
+ Rake::Task['db:seed'].enhance do
72
+ ForemanPuppet::Engine.load_seed
73
+ end
74
+ end
75
+
76
+ initializer 'foreman_puppet.register_gettext', after: :load_config_initializers do |_app|
77
+ locale_dir = File.join(File.expand_path('../..', __dir__), 'locale')
78
+ locale_domain = 'foreman_puppet'
79
+ Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,218 @@
1
+ Foreman::Plugin.register :foreman_puppet do
2
+ requires_foreman '>= 2.0.0'
3
+ # Add Global JS file for extending foreman-core components and routes
4
+ register_global_js_file 'fills'
5
+
6
+ apipie_documented_controllers(["#{ForemanPuppet::Engine.root}/app/controllers/foreman_puppet/api/v2/*.rb"])
7
+
8
+ unless ForemanPuppet.extracted_from_core?
9
+ # Remove core permissions
10
+ cfgs = %i[view_config_groups create_config_groups edit_config_groups destroy_config_groups]
11
+ plks = %i[view_external_parameters create_external_parameters edit_external_parameters
12
+ destroy_external_parameters]
13
+ pcls = %i[view_puppetclasses create_puppetclasses edit_puppetclasses destroy_puppetclasses import_puppetclasses]
14
+ (cfgs | plks | pcls).each do |perm_name|
15
+ p = Foreman::AccessControl.permission(perm_name)
16
+ Foreman::AccessControl.remove_permission(p)
17
+ end
18
+
19
+ delete_menu_item(:top_menu, :puppetclasses)
20
+ delete_menu_item(:top_menu, :config_groups)
21
+ delete_menu_item(:top_menu, :puppetclass_lookup_keys)
22
+ delete_menu_item(:top_menu, :environments)
23
+ end
24
+
25
+ # TODO: maybe this would not be necessary if we rething the form
26
+ %i[create_hostgroups edit_hostgroups].each do |perm|
27
+ p = Foreman::AccessControl.permission(perm)
28
+ if ForemanPuppet.extracted_from_core?
29
+ p.actions << 'hostgroups/environment_selected'
30
+ p.actions << 'hostgroups/puppetclass_parameters'
31
+ end
32
+ p.actions << 'foreman_puppet/puppetclasses/parameters'
33
+ end
34
+ p = Foreman::AccessControl.permission(:edit_hostgroups)
35
+ %w[index create destroy].each do |action|
36
+ p.actions << "foreman_puppet/api/v2/hostgroup_classes/#{action}"
37
+ end
38
+ %i[create_hosts edit_hosts].each do |perm|
39
+ p = Foreman::AccessControl.permission(perm)
40
+ if ForemanPuppet.extracted_from_core?
41
+ p.actions << 'hosts/hostgroup_or_environment_selected'
42
+ p.actions << 'hosts/puppetclass_parameters'
43
+ if perm == :edit_hosts
44
+ p.actions << 'hosts/select_multiple_environment'
45
+ p.actions << 'hosts/update_multiple_environment'
46
+ p.actions << 'hosts/select_multiple_puppet_proxy'
47
+ p.actions << 'hosts/update_multiple_puppet_proxy'
48
+ end
49
+ end
50
+ p.actions << 'foreman_puppet/puppetclasses/parameters'
51
+ end
52
+
53
+ p = Foreman::AccessControl.permission(:view_hosts)
54
+ p.actions << 'hosts/externalNodes'
55
+
56
+ p = Foreman::AccessControl.permission(:view_smart_proxies)
57
+ p.actions << 'foreman_puppet/puppet_smart_proxies/dashboard'
58
+ p.actions << 'foreman_puppet/puppet_smart_proxies/environments'
59
+
60
+ # Add permissions
61
+ security_block :puppet_config_groups do
62
+ permission :view_config_groups, { 'foreman_puppet/config_groups': %i[index auto_complete_search welcome],
63
+ 'foreman_puppet/api/v2/config_groups': %i[index show],
64
+ 'foreman_puppet/react': [:index] },
65
+ resource_type: 'ForemanPuppet::ConfigGroup'
66
+ permission :create_config_groups, { 'foreman_puppet/config_groups': %i[new create],
67
+ 'foreman_puppet/api/v2/config_groups': [:create] },
68
+ resource_type: 'ForemanPuppet::ConfigGroup'
69
+ permission :edit_config_groups, { 'foreman_puppet/config_groups': %i[edit update],
70
+ 'foreman_puppet/api/v2/config_groups': [:update] },
71
+ resource_type: 'ForemanPuppet::ConfigGroup'
72
+ permission :destroy_config_groups, { 'foreman_puppet/config_groups': [:destroy],
73
+ 'foreman_puppet/api/v2/config_groups': [:destroy] },
74
+ resource_type: 'ForemanPuppet::ConfigGroup'
75
+ end
76
+
77
+ security_block :puppet_lookup_keys do
78
+ permission :view_external_parameters, { 'foreman_puppet/puppetclass_lookup_keys': %i[index show auto_complete_search welcome],
79
+ lookup_values: [:index],
80
+ 'foreman_puppet/api/v2/smart_class_parameters': %i[index show],
81
+ 'foreman_puppet/api/v2/override_values': %i[index show] },
82
+ resource_type: 'ForemanPuppet::PuppetclassLookupKey'
83
+ permission :create_external_parameters, { 'foreman_puppet/puppetclass_lookup_keys': %i[new create],
84
+ lookup_values: [:create],
85
+ 'foreman_puppet/api/v2/smart_class_parameters': [:create],
86
+ 'foreman_puppet/api/v2/override_values': [:create] },
87
+ resource_type: 'ForemanPuppet::PuppetclassLookupKey'
88
+ permission :edit_external_parameters, { 'foreman_puppet/puppetclass_lookup_keys': %i[edit update],
89
+ lookup_values: %i[create update destroy],
90
+ 'foreman_puppet/api/v2/smart_class_parameters': [:update],
91
+ 'foreman_puppet/api/v2/override_values': %i[create update destroy] },
92
+ resource_type: 'ForemanPuppet::PuppetclassLookupKey'
93
+ permission :destroy_external_parameters, { 'foreman_puppet/puppetclass_lookup_keys': [:destroy],
94
+ lookup_values: [:destroy],
95
+ 'foreman_puppet/api/v2/smart_class_parameters': [:destroy],
96
+ 'foreman_puppet/api/v2/override_values': %i[create update destroy] },
97
+ resource_type: 'ForemanPuppet::PuppetclassLookupKey'
98
+ end
99
+
100
+ security_block :puppet_environments do
101
+ permission :view_environments, { 'foreman_puppet/environments': %i[index show auto_complete_search welcome],
102
+ 'foreman_puppet/api/v2/environments': %i[index show] },
103
+ resource_type: 'ForemanPuppet::Environment'
104
+ permission :create_environments, { 'foreman_puppet/environments': %i[new create],
105
+ 'foreman_puppet/api/v2/environments': %i[create] },
106
+ resource_type: 'ForemanPuppet::Environment'
107
+ permission :edit_environments, { 'foreman_puppet/environments': %i[edit update],
108
+ 'foreman_puppet/api/v2/environments': %i[update] },
109
+ resource_type: 'ForemanPuppet::Environment'
110
+ permission :destroy_environments, { 'foreman_puppet/environments': %i[destroy],
111
+ 'foreman_puppet/api/v2/environments': %i[destroy] },
112
+ resource_type: 'ForemanPuppet::Environment'
113
+ permission :import_environments, { 'foreman_puppet/environments': %i[import_environments obsolete_and_new],
114
+ 'foreman_puppet/api/v2/environments': %i[import_puppetclasses] },
115
+ resource_type: 'ForemanPuppet::Environment'
116
+ end
117
+
118
+ security_block :puppetclasses do
119
+ permission :view_puppetclasses, { 'foreman_puppet/puppetclasses' => %i[index show auto_complete_search],
120
+ 'foreman_puppet/api/v2/puppetclasses' => %i[index show],
121
+ 'foreman_puppet/api/v2/smart_class_parameters' => %i[index show] },
122
+ resource_type: 'ForemanPuppet::Puppetclass'
123
+ permission :create_puppetclasses, { 'foreman_puppet/puppetclasses' => %i[new create],
124
+ 'foreman_puppet/api/v2/puppetclasses' => [:create] },
125
+ resource_type: 'ForemanPuppet::Puppetclass'
126
+ permission :edit_puppetclasses, { 'foreman_puppet/puppetclasses' => %i[edit update override],
127
+ 'foreman_puppet/api/v2/puppetclasses' => [:update],
128
+ 'foreman_puppet/api/v2/smart_class_parameters' => %i[create update destroy] },
129
+ resource_type: 'ForemanPuppet::Puppetclass'
130
+ permission :destroy_puppetclasses, { 'foreman_puppet/puppetclasses' => [:destroy],
131
+ 'foreman_puppet/api/v2/puppetclasses' => [:destroy] },
132
+ resource_type: 'ForemanPuppet::Puppetclass'
133
+ permission :import_puppetclasses, { 'foreman_puppet/puppetclasses' => %i[import_environments obsolete_and_new],
134
+ 'foreman_puppet/api/v2/environments' => [:import_puppetclasses] },
135
+ resource_type: 'ForemanPuppet::Puppetclass'
136
+ permission :edit_classes, { 'foreman_puppet/api/v2/host_classes': %i[index create destroy] },
137
+ resource_type: 'ForemanPuppet::HostClass'
138
+ end
139
+
140
+ add_all_permissions_to_default_roles
141
+ Foreman::Plugin::RbacSupport::AUTO_EXTENDED_ROLES |= ['Site manager']
142
+ add_permissions_to_default_roles(
143
+ 'Site manager' => %w[view_puppetclasses import_puppetclasses view_environments import_environments
144
+ view_external_parameters create_external_parameters edit_external_parameters destroy_external_parameters]
145
+ )
146
+
147
+ # add puppet ENC divider
148
+ divider :top_menu, parent: :configure_menu, caption: N_('Puppet ENC')
149
+
150
+ # add menu entries
151
+ add_menu_item :top_menu, :environments, caption: N_('Environments'),
152
+ engine: ForemanPuppet::Engine,
153
+ parent: :configure_menu
154
+ add_menu_item :top_menu, :puppetclasses, caption: N_('Classes'),
155
+ engine: ForemanPuppet::Engine,
156
+ parent: :configure_menu
157
+ add_menu_item :top_menu, :config_groups, caption: N_('Config Groups'),
158
+ engine: ForemanPuppet::Engine,
159
+ parent: :configure_menu
160
+ add_menu_item :top_menu, :puppetclass_lookup_keys, caption: N_('Smart Class Parameters'),
161
+ engine: ForemanPuppet::Engine,
162
+ parent: :configure_menu
163
+
164
+ register_info_provider(ForemanPuppet::HostInfoProviders::ConfigGroupsInfo)
165
+ register_info_provider(ForemanPuppet::HostInfoProviders::PuppetInfo)
166
+
167
+ # register host and hostgroup facet
168
+ register_facet ForemanPuppet::HostPuppetFacet, :puppet do
169
+ configure_host do
170
+ # extend_model ForemanPuppet::Extensions::Host
171
+ api_view list: 'foreman_puppet/api/v2/host_puppet_facets/base',
172
+ single: 'foreman_puppet/api/v2/host_puppet_facets/host_single'
173
+ template_compatibility_properties :environment, :environment_id, :environment_name
174
+ set_dependent_action :destroy
175
+ end
176
+ configure_hostgroup(ForemanPuppet::HostgroupPuppetFacet) do
177
+ api_view list: 'foreman_puppet/api/v2/hostgroup_puppet_facets/base',
178
+ single: 'foreman_puppet/api/v2/hostgroup_puppet_facets/hostgroup_single'
179
+ template_compatibility_properties :environment, :environment_id, :environment_name
180
+ set_dependent_action :destroy
181
+ end
182
+ end
183
+
184
+ add_controller_action_scope('Api::V2::HostsController', :index) do |base_scope|
185
+ base_scope.preload(puppet: :environment)
186
+ end
187
+
188
+ unless ForemanPuppet.extracted_from_core?
189
+ Rails.application.config.after_initialize do
190
+ list = Pagelets::Manager.instance.instance_variable_get(:@pagelets)['hosts/_form'][:main_tabs]
191
+ core_pagelet = list.detect { |pagelet| pagelet.opts[:id] == :puppet_klasses }
192
+ list.delete(core_pagelet)
193
+ end
194
+ end
195
+
196
+ extend_template_helpers(ForemanPuppet::TemplateRendererScope)
197
+
198
+ # extend host(group) form with puppet ENC Tab
199
+ %i[host hostgroup].each do |resource_type|
200
+ host_onlyif = ->(host, context) { context.send(:accessible_resource, host, :smart_proxy, :name, association: :puppet_proxy).present? }
201
+ extend_page("#{resource_type}s/_form") do |context|
202
+ context.add_pagelet :main_tabs,
203
+ id: :puppet_enc_tab,
204
+ name: N_('Puppet ENC'),
205
+ partial: 'hosts/form_puppet_enc_tab',
206
+ resource_type: resource_type,
207
+ priority: 100,
208
+ onlyif: (host_onlyif if resource_type == :host)
209
+
210
+ if ForemanPuppet.extracted_from_core?
211
+ context.add_pagelet :main_tab_fields,
212
+ partial: 'hosts/foreman_puppet/form_main_tab_fields',
213
+ resource_type: resource_type,
214
+ priority: 100
215
+ end
216
+ end
217
+ end
218
+ end