foreman_puppet 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +61 -7
  3. data/app/controllers/concerns/foreman_puppet/environments_import.rb +1 -1
  4. data/app/controllers/concerns/foreman_puppet/extensions/api_base_controller.rb +28 -0
  5. data/app/controllers/concerns/foreman_puppet/extensions/api_template_combinations_controller.rb +1 -1
  6. data/app/controllers/concerns/foreman_puppet/extensions/hostgroups_controller_extensions.rb +1 -1
  7. data/app/controllers/concerns/foreman_puppet/extensions/hosts_controller_extensions.rb +1 -1
  8. data/app/controllers/concerns/foreman_puppet/extensions/parameters_host.rb +3 -10
  9. data/app/controllers/concerns/foreman_puppet/parameters/puppetclass_lookup_key.rb +2 -2
  10. data/app/controllers/foreman_puppet/api/v2/config_groups_controller.rb +9 -1
  11. data/app/controllers/foreman_puppet/api/v2/environments_controller.rb +5 -2
  12. data/app/controllers/foreman_puppet/api/v2/host_classes_controller.rb +9 -1
  13. data/app/controllers/foreman_puppet/api/v2/hostgroup_classes_controller.rb +9 -1
  14. data/app/controllers/foreman_puppet/api/v2/override_values_controller.rb +1 -2
  15. data/app/controllers/foreman_puppet/api/v2/{base_controller.rb → puppet_base_controller.rb} +3 -4
  16. data/app/controllers/foreman_puppet/api/v2/{lookups_common_controller.rb → puppet_lookups_common_controller.rb} +6 -2
  17. data/app/controllers/foreman_puppet/api/v2/puppetclasses_controller.rb +5 -1
  18. data/app/controllers/foreman_puppet/api/v2/smart_class_parameters_controller.rb +1 -2
  19. data/app/controllers/foreman_puppet/config_groups_controller.rb +4 -0
  20. data/app/controllers/foreman_puppet/puppet_smart_proxies_controller.rb +4 -0
  21. data/app/controllers/foreman_puppet/puppetclass_lookup_keys_controller.rb +2 -2
  22. data/app/controllers/foreman_puppet/puppetclasses_controller.rb +12 -4
  23. data/app/graphgl/concerns/foreman_puppet/mutations/hosts/create_extensions.rb +29 -0
  24. data/app/graphgl/concerns/foreman_puppet/types/host_extensions.rb +13 -0
  25. data/app/graphgl/concerns/foreman_puppet/types/hostgroup_extensions.rb +13 -0
  26. data/app/graphgl/concerns/foreman_puppet/types/interface_attributes_input_extensions.rb +9 -0
  27. data/app/graphgl/concerns/foreman_puppet/types/location_extensions.rb +14 -0
  28. data/app/graphgl/concerns/foreman_puppet/types/organization_extensions.rb +14 -0
  29. data/app/graphgl/foreman_puppet/types/environment.rb +20 -0
  30. data/app/graphgl/foreman_puppet/types/puppetclass.rb +20 -0
  31. data/app/helpers/foreman_puppet/environments_helper.rb +1 -1
  32. data/app/helpers/foreman_puppet/hosts_helper.rb +15 -0
  33. data/app/helpers/foreman_puppet/puppetclass_lookup_keys_helper.rb +2 -2
  34. data/app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb +1 -1
  35. data/app/helpers/foreman_puppet/puppetclasses_helper.rb +2 -2
  36. data/app/models/concerns/foreman_puppet/extensions/host.rb +24 -9
  37. data/app/models/concerns/foreman_puppet/extensions/host_common.rb +17 -0
  38. data/app/models/concerns/foreman_puppet/extensions/hostgroup.rb +13 -7
  39. data/app/models/concerns/foreman_puppet/extensions/operatingsystem.rb +1 -1
  40. data/app/models/concerns/foreman_puppet/extensions/provisioning_template.rb +19 -13
  41. data/app/models/concerns/foreman_puppet/extensions/report.rb +18 -0
  42. data/app/models/concerns/foreman_puppet/extensions/taxonomy.rb +1 -1
  43. data/app/models/concerns/foreman_puppet/extensions/template_combination.rb +1 -1
  44. data/app/models/concerns/foreman_puppet/extensions/user.rb +19 -12
  45. data/app/models/foreman_puppet/environment.rb +2 -0
  46. data/app/models/foreman_puppet/environment_class.rb +1 -1
  47. data/app/models/foreman_puppet/host_class.rb +1 -1
  48. data/app/models/foreman_puppet/host_puppet_facet.rb +6 -5
  49. data/app/models/foreman_puppet/hostgroup_puppet_facet.rb +1 -1
  50. data/app/models/{concerns/foreman_puppet/host_common.rb → foreman_puppet/puppet_facet_common.rb} +1 -1
  51. data/app/models/foreman_puppet/puppetclass.rb +15 -1
  52. data/app/{views/api/v2/template_combinations/base.json.erb → prepend_views/api/v2/template_combinations/base.json.rabl} +0 -0
  53. data/app/services/foreman_puppet/host_info_providers/config_groups_info.rb +2 -0
  54. data/app/services/foreman_puppet/puppet_class_importer.rb +17 -18
  55. data/app/views/foreman_puppet/common/_puppetclasses_or_envs_changed.html.erb +62 -0
  56. data/app/views/foreman_puppet/config_groups/index.html.erb +2 -2
  57. data/app/views/foreman_puppet/config_groups/welcome.html.erb +12 -11
  58. data/app/views/foreman_puppet/environments/index.html.erb +1 -1
  59. data/app/views/foreman_puppet/environments/welcome.html.erb +3 -15
  60. data/app/views/foreman_puppet/puppetclass_lookup_keys/welcome.html.erb +10 -8
  61. data/app/views/foreman_puppet/puppetclasses/_classes.html.erb +1 -1
  62. data/app/views/foreman_puppet/puppetclasses/_selected_classes.html.erb +1 -1
  63. data/app/views/foreman_puppet/puppetclasses/index.html.erb +1 -1
  64. data/app/views/hosts/_form_puppet_enc_tab.html.erb +1 -1
  65. data/app/views/hosts/select_multiple_environment.html.erb +1 -1
  66. data/app/views/smart_proxies/plugins/_puppet_ca.html.erb +44 -0
  67. data/config/initializers/api_reroute.rb +13 -0
  68. data/db/migrate/20200803113903_migrate_host_type_in_host_config_groups.foreman_puppet.rb +37 -12
  69. data/db/migrate/20201125113903_migrate_puppetclasses_to_facets.foreman_puppet.rb +13 -1
  70. data/lib/foreman_puppet/engine.rb +68 -20
  71. data/lib/foreman_puppet/register.rb +7 -2
  72. data/lib/foreman_puppet/version.rb +1 -1
  73. data/lib/foreman_puppet.rb +3 -3
  74. data/locale/Makefile +1 -1
  75. data/locale/en/LC_MESSAGES/foreman_puppet.mo +0 -0
  76. data/locale/en/foreman_puppet.edit.po +19 -3
  77. data/locale/en/foreman_puppet.po +18 -6
  78. data/locale/en/foreman_puppet.pox +0 -0
  79. data/locale/foreman_puppet.pot +19 -3
  80. data/locale/messages.mo +0 -0
  81. data/test/controllers/foreman_puppet/api/v2/config_groups_controller_test.rb +7 -3
  82. data/test/controllers/foreman_puppet/api/v2/environments_controller_test.rb +18 -16
  83. data/test/controllers/foreman_puppet/api/v2/hosts_controller_test.rb +3 -2
  84. data/test/controllers/foreman_puppet/api/v2/lookups_common_controller_test.rb +1 -1
  85. data/test/controllers/foreman_puppet/api/v2/provisioning_templates_controller_test.rb +32 -0
  86. data/test/controllers/foreman_puppet/api/v2/puppetclasses_controller_test.rb +3 -0
  87. data/test/controllers/foreman_puppet/api/v2/smart_class_parameters_controller_test.rb +7 -1
  88. data/test/controllers/foreman_puppet/api/v2/template_combinations_controller_test.rb +2 -2
  89. data/test/controllers/foreman_puppet/config_groups_controller_test.rb +7 -3
  90. data/test/controllers/foreman_puppet/environments_controller_test.rb +2 -2
  91. data/test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb +2 -2
  92. data/test/controllers/foreman_puppet/puppetclasses_controller_test.rb +5 -6
  93. data/test/factories/foreman_puppet_factories.rb +3 -0
  94. data/test/factories/host_puppet_enhancements.rb +6 -6
  95. data/test/graphql/mutations/hosts/create_mutation_test.rb +87 -0
  96. data/test/graphql/queries/environment_query_test.rb +54 -0
  97. data/test/graphql/queries/environments_query_test.rb +43 -0
  98. data/test/{qraphql → graphql}/queries/host_puppet_query_test.rb +3 -8
  99. data/test/{qraphql → graphql}/queries/hostgroup_puppet_query_test.rb +1 -6
  100. data/test/graphql/queries/location_query_test.rb +52 -0
  101. data/test/graphql/queries/organization_query_test.rb +52 -0
  102. data/test/graphql/queries/puppetclass_query_test.rb +68 -0
  103. data/test/graphql/queries/puppetclasses_query_test.rb +43 -0
  104. data/test/integration/foreman_puppet/environment_js_test.rb +4 -1
  105. data/test/integration/foreman_puppet/host_js_test.rb +1 -1
  106. data/test/integration/foreman_puppet/puppetclass_js_test.rb +4 -0
  107. data/test/models/foreman_puppet/config_group_class_test.rb +3 -1
  108. data/test/models/foreman_puppet/environment_test.rb +2 -0
  109. data/test/models/foreman_puppet/host_puppet_facet_test.rb +34 -1
  110. data/test/models/foreman_puppet/host_test.rb +4 -3
  111. data/test/models/foreman_puppet/hostgroup_puppet_facet_test.rb +2 -3
  112. data/test/models/foreman_puppet/provisioning_template_test.rb +14 -7
  113. data/test/models/foreman_puppet/report_test.rb +21 -0
  114. data/test/models/foreman_puppet/smart_proxy_test.rb +1 -1
  115. data/test/models/foreman_puppet/user_test.rb +37 -0
  116. data/test/services/foreman_puppet/host_info_providers/config_groups_info_test.rb +35 -0
  117. data/test/services/foreman_puppet/host_info_providers/puppet_info_test.rb +159 -197
  118. data/test/unit/foreman_puppet/puppet_class_importer_test.rb +16 -2
  119. data/webpack/index.js +3 -4
  120. data/webpack/src/Components/Environments/Welcome.js +37 -0
  121. metadata +51 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 063aa962a333e59fdec2a1fb2d301eef47ae7006aebee443c48b0ec0d2311016
4
- data.tar.gz: de47e4d6cc3f191b551e43e1fc5fd134e386129a2d85bdf61439103fa87dbc72
3
+ metadata.gz: 49e644faeeffa930e09b12d75395777a23aa7bec00b9dbdf16eeed14b3d2e9bc
4
+ data.tar.gz: 9da4592a03b0fc3431a8f3c12c8bd046782544b5df29419949471b5919388c66
5
5
  SHA512:
6
- metadata.gz: 0b3a81c10ef66fab6dfa6e4ba9726e19080c5d8308a89eeb21232a3d35a0c8cd9ffc3b2722fbbc297a76a94c3c6470d82782a301bbf4589b37a0419461068ea6
7
- data.tar.gz: d349b0fffba53ff1fb31c2e161a985785d47022325e3b5443c5885aba017a85fa7cae4d4234e65dee3b4be5980897ec789da9bdac21b2872abfa8afbbb7ca6df
6
+ metadata.gz: 2e40390e1c1b70276056a455672397f0425c48fa71dda42cdf814f3718b3869f6b59ab3fa0250acbb5699754a9bdc7ef64640aef07e0cf1388e9b5b4ebc4fe27
7
+ data.tar.gz: c6a7e53a32381af7bef757d359e14e5828b3a3536e31f9291fda67af175ca637e971d605c302e479f49bf2e09c9ce8cdcf22494bcd28afe2244f19bbe429f053
data/README.md CHANGED
@@ -1,19 +1,74 @@
1
1
  # ForemanPuppet
2
2
 
3
- Adds Puppet External node classification funcionality for [Foreman](theforeman.org).
3
+ [![Gem Version](https://img.shields.io/gem/v/foreman_puppet.svg)](https://rubygems.org/gems/foreman_puppet)
4
+ [![GPL License](https://img.shields.io/github/license/theforeman/foreman_puppet.svg)](https://github.com/theforeman/foreman_puppet/blob/master/LICENSE)
5
+
6
+ This plugin adds Puppet External node classification functionality to [Foreman](https://theforeman.org).
7
+
8
+ * Website: [theforeman.org](http://theforeman.org)
9
+ * Support: [Foreman support](http://theforeman.org/support.html)
10
+
11
+ ## Features
12
+
13
+ * Puppet dashboards
14
+ * Puppet
15
+ * Environments
16
+ * Classes
17
+ * Config groups
18
+ * Smart Class parameters
19
+ * Host / Hostgroup
20
+ * Classes assignment
21
+ * Environment assignment
22
+ * Puppet proxy assignment
23
+ * Puppet ENC (external node classifier)
24
+ * Smartproxy Puppet status/tab
25
+ * Template hostgroup / environment
26
+
27
+ Some features will remain in core:
28
+
29
+ * PuppetCA
30
+ * Report/Fact parsing
31
+
32
+ ## Compatibility
33
+
34
+ Foreman 3.0 will be the first release where the Puppet functionality is mostly extracted.
35
+ Therefore, this plugin is only required for 3.0 and onwards.
36
+ You can install it on Foreman 2.5 to prepare for the Foreman update.
37
+
38
+ |Foreman version|Plugin version|Notes |
39
+ |---------------|--------------|------------------------------------------|
40
+ | >= 3.0 | ~> 1.0 | Required |
41
+ | >= 2.5 | ~> 0.1 | Optional; replaces Core features |
42
+ | < 2.5 | - | Not supported (functionality is in Core) |
4
43
 
5
44
  ## Installation
6
45
 
7
- See [How_to_Install_a_Plugin](http://projects.theforeman.org/projects/foreman/wiki/How_to_Install_a_Plugin)
46
+ See [How_to_Install_a_Plugin](https://theforeman.org/plugins/#2.Installation)
8
47
  for how to install Foreman plugins
9
48
 
49
+ You can manually install this plugin using:
50
+
51
+ ```sh
52
+ # On RedHat/CentOS
53
+ yum install tfm-rubygem-foreman_puppet
54
+
55
+ # On Debian
56
+ apt install ruby-foreman-puppet
57
+ ```
58
+
10
59
  ## Usage
11
60
 
12
- *Usage here*
61
+ The usage is identical to the prior core functionality:
62
+
63
+ * Import *environments* and *classes* from a Smartproxy
64
+ * Optionally define *Smart Class* parameters
65
+ * Assign *environment* and *classes* to *Hosts / Hostgroups*
66
+ * Use the *Puppet ENC* on your Puppetserver(s) to query Foreman
13
67
 
14
- ## TODO
68
+ ## Problems
15
69
 
16
- *Todo list here*
70
+ Please feel free to open a [new Github issue](https://github.com/theforeman/foreman_puppet/issues/new)
71
+ if you encounter any bugs/issues using this plugin.
17
72
 
18
73
  ## Contributing
19
74
 
@@ -21,7 +76,7 @@ Fork and send a Pull Request. Thanks!
21
76
 
22
77
  ## Copyright
23
78
 
24
- Copyright (c) *year* *your name*
79
+ Copyright (c) *2021* *The Foreman developers*
25
80
 
26
81
  This program is free software: you can redistribute it and/or modify
27
82
  it under the terms of the GNU General Public License as published by
@@ -35,4 +90,3 @@ GNU General Public License for more details.
35
90
 
36
91
  You should have received a copy of the GNU General Public License
37
92
  along with this program. If not, see <http://www.gnu.org/licenses/>.
38
-
@@ -16,7 +16,7 @@ module ForemanPuppet
16
16
  end
17
17
 
18
18
  if !@changed['new'].empty? || !@changed['obsolete'].empty? || !@changed['updated'].empty?
19
- render 'common/_puppetclasses_or_envs_changed'
19
+ render 'foreman_puppet/common/_puppetclasses_or_envs_changed'
20
20
  else
21
21
  info_message = _('No changes to your environments detected')
22
22
 
@@ -0,0 +1,28 @@
1
+ module ForemanPuppet
2
+ module Extensions
3
+ module ApiBaseController
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ prepend PatchMethods
8
+
9
+ before_action :prepare_views
10
+ end
11
+
12
+ def prepare_views
13
+ prepend_view_path ForemanPuppet::Engine.root.join('app', 'prepend_views')
14
+ end
15
+
16
+ module PatchMethods
17
+ def resource_name(resource = controller_name)
18
+ case resource
19
+ when 'environment'
20
+ 'foreman_puppet/environment'
21
+ else
22
+ super
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -6,7 +6,7 @@ module ForemanPuppet
6
6
  included do
7
7
  if ForemanPuppet.extracted_from_core?
8
8
  apipie_update_methods(%i[index create show update]) do
9
- param :environment_id, String, desc: N_('ID of environment')
9
+ param :environment_id, nil, desc: N_('ID of environment')
10
10
  end
11
11
  end
12
12
 
@@ -42,7 +42,7 @@ module ForemanPuppet
42
42
  def puppetclass_parameters
43
43
  ::Taxonomy.as_taxonomy @organization, @location do
44
44
  render partial: 'foreman_puppet/puppetclasses/classes_parameters',
45
- locals: { obj: refresh_hostgroup }
45
+ locals: { obj: refresh_hostgroup }
46
46
  end
47
47
  end
48
48
 
@@ -104,7 +104,7 @@ module ForemanPuppet
104
104
  rescue StandardError => e
105
105
  Foreman::Logging.exception("Failed to generate external nodes for #{@host}", e)
106
106
  render plain: _('Unable to generate output, Check log files'),
107
- status: :precondition_failed
107
+ status: :precondition_failed
108
108
  end
109
109
  end
110
110
  # rubocop:enable Naming/MethodName
@@ -34,16 +34,9 @@ module ForemanPuppet
34
34
  end
35
35
 
36
36
  def process_deprecated_environment_params!(params)
37
- env_id = env_name = env = nil
38
- if ForemanPuppet.extracted_from_core?
39
- env_id = params.delete(:environment_id)
40
- env_name = params.delete(:environment_name)
41
- env = params.delete(:environment)
42
- else
43
- env_id = params[:environment_id]
44
- env_name = params[:environment_name]
45
- env = params[:environment]
46
- end
37
+ env_id = params.delete(:environment_id)
38
+ env_name = params.delete(:environment_name)
39
+ env = params.delete(:environment)
47
40
 
48
41
  return unless env_id || env_name || env
49
42
  ::Foreman::Deprecation.api_deprecation_warning('param host[environment_*] has been deprecated in favor of host[puppet_attributes][environment_*]')
@@ -7,8 +7,8 @@ module ForemanPuppet
7
7
  def puppetclass_lookup_key_params_filter
8
8
  Foreman::ParameterFilter.new(ForemanPuppet::PuppetclassLookupKey).tap do |filter|
9
9
  filter.permit environments: [], environment_ids: [], environment_names: [],
10
- environment_classes: [], environment_classes_ids: [], environment_classes_names: [],
11
- param_classes: [], param_classes_ids: [], param_classes_names: []
10
+ environment_classes: [], environment_classes_ids: [], environment_classes_names: [],
11
+ param_classes: [], param_classes_ids: [], param_classes_names: []
12
12
  filter.permit_by_context :required, nested: true
13
13
  filter.permit_by_context :id, ui: false, api: false, nested: true
14
14
 
@@ -1,9 +1,13 @@
1
1
  module ForemanPuppet
2
2
  module Api
3
3
  module V2
4
- class ConfigGroupsController < BaseController
4
+ class ConfigGroupsController < ::ForemanPuppet::Api::V2::PuppetBaseController
5
5
  include ForemanPuppet::Parameters::ConfigGroup
6
6
 
7
+ resource_description do
8
+ api_base_url '/foreman_puppet/api'
9
+ end
10
+
7
11
  wrap_parameters ConfigGroup, include: config_group_params_filter.accessible_attributes(parameter_filter_context)
8
12
 
9
13
  before_action :find_resource, only: %i[show update destroy]
@@ -51,6 +55,10 @@ module ForemanPuppet
51
55
  def destroy
52
56
  process_response @config_group.destroy
53
57
  end
58
+
59
+ def resource_class
60
+ ForemanPuppet::ConfigGroup
61
+ end
54
62
  end
55
63
  end
56
64
  end
@@ -1,12 +1,11 @@
1
1
  module ForemanPuppet
2
2
  module Api
3
3
  module V2
4
- class EnvironmentsController < BaseController
4
+ class EnvironmentsController < ::ForemanPuppet::Api::V2::PuppetBaseController
5
5
  include ForemanPuppet::Api::ImportPuppetclassesCommonController
6
6
  include ForemanPuppet::Parameters::Environment
7
7
 
8
8
  resource_description do
9
- api_version '2'
10
9
  api_base_url '/foreman_puppet/api'
11
10
  end
12
11
 
@@ -62,6 +61,10 @@ module ForemanPuppet
62
61
  process_response @environment.destroy
63
62
  end
64
63
 
64
+ def resource_class
65
+ ForemanPuppet::Environment
66
+ end
67
+
65
68
  private
66
69
 
67
70
  def action_permission
@@ -1,7 +1,11 @@
1
1
  module ForemanPuppet
2
2
  module Api
3
3
  module V2
4
- class HostClassesController < V2::BaseController
4
+ class HostClassesController < ::ForemanPuppet::Api::V2::PuppetBaseController
5
+ resource_description do
6
+ api_base_url '/foreman_puppet/api'
7
+ end
8
+
5
9
  before_action :find_host, only: %i[index create destroy]
6
10
  before_action :find_puppetclass, only: %i[create destroy]
7
11
 
@@ -29,6 +33,10 @@ module ForemanPuppet
29
33
  process_response @host_class.destroy_all
30
34
  end
31
35
 
36
+ def resource_class
37
+ ForemanPuppet::HostClass
38
+ end
39
+
32
40
  private
33
41
 
34
42
  # overwrite resource_name so it's host and and not host_class, since we want to return @host
@@ -1,7 +1,11 @@
1
1
  module ForemanPuppet
2
2
  module Api
3
3
  module V2
4
- class HostgroupClassesController < V2::BaseController
4
+ class HostgroupClassesController < ::ForemanPuppet::Api::V2::PuppetBaseController
5
+ resource_description do
6
+ api_base_url '/foreman_puppet/api'
7
+ end
8
+
5
9
  before_action :find_hostgroup, only: %i[index create destroy]
6
10
 
7
11
  api :GET, '/hostgroups/:hostgroup_id/puppetclass_ids/', N_('List all Puppet class IDs for host group')
@@ -28,6 +32,10 @@ module ForemanPuppet
28
32
  process_response @hostgroup_class.destroy_all
29
33
  end
30
34
 
35
+ def resource_class
36
+ ForemanPuppet::HostgroupClass
37
+ end
38
+
31
39
  private
32
40
 
33
41
  def find_hostgroup
@@ -1,11 +1,10 @@
1
1
  module ForemanPuppet
2
2
  module Api
3
3
  module V2
4
- class OverrideValuesController < LookupsCommonController
4
+ class OverrideValuesController < ::ForemanPuppet::Api::V2::PuppetLookupsCommonController
5
5
  include Foreman::Controller::Parameters::LookupValue
6
6
 
7
7
  resource_description do
8
- api_version '2'
9
8
  api_base_url '/foreman_puppet/api'
10
9
  end
11
10
 
@@ -1,10 +1,9 @@
1
1
  module ForemanPuppet
2
2
  module Api
3
3
  module V2
4
- class BaseController < ::Api::V2::BaseController
4
+ class PuppetBaseController < ::Api::V2::BaseController
5
5
  resource_description do
6
- api_version '2'
7
- api_base_url '/foreman_puppet/api'
6
+ api_version 'v2'
8
7
  end
9
8
 
10
9
  before_action :show_deprecation_for_core_routes
@@ -12,7 +11,7 @@ module ForemanPuppet
12
11
  protected
13
12
 
14
13
  def show_deprecation_for_core_routes
15
- return if request.path.starts_with?('/foreman_puppet')
14
+ return if request.path.starts_with?('/foreman_puppet') || request.path.starts_with?('/api/smart_proxies')
16
15
  Foreman::Deprecation.api_deprecation_warning(
17
16
  format(
18
17
  '/api/v2/%{controller} API endpoints are deprecated, please use /foreman_puppet/api/v2/%{controller} instead',
@@ -1,7 +1,11 @@
1
1
  module ForemanPuppet
2
2
  module Api
3
3
  module V2
4
- class LookupsCommonController < ::Api::V2::BaseController
4
+ class PuppetLookupsCommonController < ::Api::V2::BaseController
5
+ resource_description do
6
+ api_version 'v2'
7
+ end
8
+
5
9
  before_action :find_environment, if: :environment_id?
6
10
  before_action :find_puppetclass, if: :puppetclass_id?
7
11
  before_action :find_host, if: :host_id?
@@ -45,7 +49,7 @@ module ForemanPuppet
45
49
 
46
50
  def find_smart_class_parameter
47
51
  id = params.key?('smart_class_parameter_id') ? params['smart_class_parameter_id'] : params['id']
48
- @smart_class_parameter = PuppetclassLookupKey.authorized(:view_external_parameters).smart_class_parameters.find_by(id: id.to_i) if id.to_i > 0
52
+ @smart_class_parameter = PuppetclassLookupKey.authorized(:view_external_parameters).smart_class_parameters.find_by(id: id.to_i) if id.to_i.positive?
49
53
  @smart_class_parameter ||= begin
50
54
  puppet_cond = { 'environment_classes.puppetclass_id' => @puppetclass.id } if @puppetclass
51
55
  env_cond = { 'environment_classes.environment_id' => @environment.id } if @environment
@@ -1,9 +1,13 @@
1
1
  module ForemanPuppet
2
2
  module Api
3
3
  module V2
4
- class PuppetclassesController < BaseController
4
+ class PuppetclassesController < ::ForemanPuppet::Api::V2::PuppetBaseController
5
5
  include ForemanPuppet::Parameters::Puppetclass
6
6
 
7
+ resource_description do
8
+ api_base_url '/foreman_puppet/api'
9
+ end
10
+
7
11
  before_action :find_optional_nested_object
8
12
  before_action :find_resource, only: %w[show update destroy]
9
13
 
@@ -1,11 +1,10 @@
1
1
  module ForemanPuppet
2
2
  module Api
3
3
  module V2
4
- class SmartClassParametersController < ForemanPuppet::Api::V2::LookupsCommonController
4
+ class SmartClassParametersController < ::ForemanPuppet::Api::V2::PuppetLookupsCommonController
5
5
  include ForemanPuppet::Parameters::PuppetclassLookupKey
6
6
 
7
7
  resource_description do
8
- api_version '2'
9
8
  api_base_url '/foreman_puppet/api'
10
9
  end
11
10
 
@@ -42,5 +42,9 @@ module ForemanPuppet
42
42
  process_error
43
43
  end
44
44
  end
45
+
46
+ def resource_class
47
+ model_of_controller
48
+ end
45
49
  end
46
50
  end
@@ -16,6 +16,10 @@ module ForemanPuppet
16
16
  process_ajax_error e
17
17
  end
18
18
 
19
+ def resource_class
20
+ ::SmartProxy
21
+ end
22
+
19
23
  private
20
24
 
21
25
  def find_status
@@ -9,11 +9,11 @@ module ForemanPuppet
9
9
  environment_classes = EnvironmentClass.where(puppetclass_lookup_key_id: @lookup_keys.map(&:id)).select(:puppetclass_id, :puppetclass_lookup_key_id).distinct.preload(:puppetclass)
10
10
  puppetclass_ids = environment_classes.map(&:puppetclass_id).uniq
11
11
  @puppetclass_authorizer = Authorizer.new(User.current, collection: puppetclass_ids)
12
- @lookup_keys_to_class = Hash[environment_classes.map { |environment_class| [environment_class.puppetclass_lookup_key_id, environment_class.puppetclass] }]
12
+ @lookup_keys_to_class = environment_classes.map { |environment_class| [environment_class.puppetclass_lookup_key_id, environment_class.puppetclass] }.to_h
13
13
  end
14
14
 
15
15
  def resource_class
16
- ForemanPuppet::PuppetclassLookupKey
16
+ model_of_controller
17
17
  end
18
18
 
19
19
  private
@@ -3,8 +3,11 @@ module ForemanPuppet
3
3
  include Foreman::Controller::AutoCompleteSearch
4
4
  include Foreman::Controller::Parameters::Host
5
5
  include Foreman::Controller::Parameters::Hostgroup
6
+ include ForemanPuppet::Extensions::ParametersHost
7
+ include ForemanPuppet::Extensions::ParametersHostgroup
6
8
  include ForemanPuppet::Parameters::Environment
7
9
  include ForemanPuppet::Parameters::Puppetclass
10
+ include ForemanPuppet::EnvironmentsImport
8
11
 
9
12
  before_action :find_resource, only: %i[edit update destroy override]
10
13
  before_action :setup_search_options, only: :index
@@ -69,8 +72,8 @@ module ForemanPuppet
69
72
  def parameters
70
73
  puppetclass = Puppetclass.find(params[:id])
71
74
  render partial: 'foreman_puppet/puppetclasses/class_parameters',
72
- locals: { puppetclass: puppetclass,
73
- obj: find_host_or_hostgroup }
75
+ locals: { puppetclass: puppetclass,
76
+ obj: find_host_or_hostgroup }
74
77
  end
75
78
 
76
79
  def resource_class
@@ -92,11 +95,11 @@ module ForemanPuppet
92
95
  @obj.type = 'Host::Managed'
93
96
  end
94
97
  # puppetclass_ids and config_group_ids need to be removed so they don't cause automatic insertsgroup
95
- @obj.attributes = host_params('host')
98
+ @obj.attributes = host_params('host').tap { |params| strip_relation_ids(params) }
96
99
  elsif params['hostgroup']
97
100
  # hostgroup.id is assigned to params['host_id'] by host_edit.js#load_puppet_class_parameters
98
101
  @obj = Hostgroup.find(host_id)
99
- @obj.attributes = hostgroup_params('hostgroup')
102
+ @obj.attributes = hostgroup_params('hostgroup').tap { |params| strip_relation_ids(params) }
100
103
  end
101
104
  @obj
102
105
  end
@@ -109,5 +112,10 @@ module ForemanPuppet
109
112
  super
110
113
  end
111
114
  end
115
+
116
+ def strip_relation_ids(params)
117
+ return unless params[:puppet_attributes]
118
+ params[:puppet_attributes].except!(:puppetclass_ids, :config_group_ids)
119
+ end
112
120
  end
113
121
  end