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.
- checksums.yaml +4 -4
- data/README.md +61 -7
- data/app/controllers/concerns/foreman_puppet/environments_import.rb +1 -1
- data/app/controllers/concerns/foreman_puppet/extensions/api_base_controller.rb +28 -0
- data/app/controllers/concerns/foreman_puppet/extensions/api_template_combinations_controller.rb +1 -1
- data/app/controllers/concerns/foreman_puppet/extensions/hostgroups_controller_extensions.rb +1 -1
- data/app/controllers/concerns/foreman_puppet/extensions/hosts_controller_extensions.rb +1 -1
- data/app/controllers/concerns/foreman_puppet/extensions/parameters_host.rb +3 -10
- data/app/controllers/concerns/foreman_puppet/parameters/puppetclass_lookup_key.rb +2 -2
- data/app/controllers/foreman_puppet/api/v2/config_groups_controller.rb +9 -1
- data/app/controllers/foreman_puppet/api/v2/environments_controller.rb +5 -2
- data/app/controllers/foreman_puppet/api/v2/host_classes_controller.rb +9 -1
- data/app/controllers/foreman_puppet/api/v2/hostgroup_classes_controller.rb +9 -1
- data/app/controllers/foreman_puppet/api/v2/override_values_controller.rb +1 -2
- data/app/controllers/foreman_puppet/api/v2/{base_controller.rb → puppet_base_controller.rb} +3 -4
- data/app/controllers/foreman_puppet/api/v2/{lookups_common_controller.rb → puppet_lookups_common_controller.rb} +6 -2
- data/app/controllers/foreman_puppet/api/v2/puppetclasses_controller.rb +5 -1
- data/app/controllers/foreman_puppet/api/v2/smart_class_parameters_controller.rb +1 -2
- data/app/controllers/foreman_puppet/config_groups_controller.rb +4 -0
- data/app/controllers/foreman_puppet/puppet_smart_proxies_controller.rb +4 -0
- data/app/controllers/foreman_puppet/puppetclass_lookup_keys_controller.rb +2 -2
- data/app/controllers/foreman_puppet/puppetclasses_controller.rb +12 -4
- data/app/graphgl/concerns/foreman_puppet/mutations/hosts/create_extensions.rb +29 -0
- data/app/graphgl/concerns/foreman_puppet/types/host_extensions.rb +13 -0
- data/app/graphgl/concerns/foreman_puppet/types/hostgroup_extensions.rb +13 -0
- data/app/graphgl/concerns/foreman_puppet/types/interface_attributes_input_extensions.rb +9 -0
- data/app/graphgl/concerns/foreman_puppet/types/location_extensions.rb +14 -0
- data/app/graphgl/concerns/foreman_puppet/types/organization_extensions.rb +14 -0
- data/app/graphgl/foreman_puppet/types/environment.rb +20 -0
- data/app/graphgl/foreman_puppet/types/puppetclass.rb +20 -0
- data/app/helpers/foreman_puppet/environments_helper.rb +1 -1
- data/app/helpers/foreman_puppet/hosts_helper.rb +15 -0
- data/app/helpers/foreman_puppet/puppetclass_lookup_keys_helper.rb +2 -2
- data/app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb +1 -1
- data/app/helpers/foreman_puppet/puppetclasses_helper.rb +2 -2
- data/app/models/concerns/foreman_puppet/extensions/host.rb +24 -9
- data/app/models/concerns/foreman_puppet/extensions/host_common.rb +17 -0
- data/app/models/concerns/foreman_puppet/extensions/hostgroup.rb +13 -7
- data/app/models/concerns/foreman_puppet/extensions/operatingsystem.rb +1 -1
- data/app/models/concerns/foreman_puppet/extensions/provisioning_template.rb +19 -13
- data/app/models/concerns/foreman_puppet/extensions/report.rb +18 -0
- data/app/models/concerns/foreman_puppet/extensions/taxonomy.rb +1 -1
- data/app/models/concerns/foreman_puppet/extensions/template_combination.rb +1 -1
- data/app/models/concerns/foreman_puppet/extensions/user.rb +19 -12
- data/app/models/foreman_puppet/environment.rb +2 -0
- data/app/models/foreman_puppet/environment_class.rb +1 -1
- data/app/models/foreman_puppet/host_class.rb +1 -1
- data/app/models/foreman_puppet/host_puppet_facet.rb +6 -5
- data/app/models/foreman_puppet/hostgroup_puppet_facet.rb +1 -1
- data/app/models/{concerns/foreman_puppet/host_common.rb → foreman_puppet/puppet_facet_common.rb} +1 -1
- data/app/models/foreman_puppet/puppetclass.rb +15 -1
- data/app/{views/api/v2/template_combinations/base.json.erb → prepend_views/api/v2/template_combinations/base.json.rabl} +0 -0
- data/app/services/foreman_puppet/host_info_providers/config_groups_info.rb +2 -0
- data/app/services/foreman_puppet/puppet_class_importer.rb +17 -18
- data/app/views/foreman_puppet/common/_puppetclasses_or_envs_changed.html.erb +62 -0
- data/app/views/foreman_puppet/config_groups/index.html.erb +2 -2
- data/app/views/foreman_puppet/config_groups/welcome.html.erb +12 -11
- data/app/views/foreman_puppet/environments/index.html.erb +1 -1
- data/app/views/foreman_puppet/environments/welcome.html.erb +3 -15
- data/app/views/foreman_puppet/puppetclass_lookup_keys/welcome.html.erb +10 -8
- data/app/views/foreman_puppet/puppetclasses/_classes.html.erb +1 -1
- data/app/views/foreman_puppet/puppetclasses/_selected_classes.html.erb +1 -1
- data/app/views/foreman_puppet/puppetclasses/index.html.erb +1 -1
- data/app/views/hosts/_form_puppet_enc_tab.html.erb +1 -1
- data/app/views/hosts/select_multiple_environment.html.erb +1 -1
- data/app/views/smart_proxies/plugins/_puppet_ca.html.erb +44 -0
- data/config/initializers/api_reroute.rb +13 -0
- data/db/migrate/20200803113903_migrate_host_type_in_host_config_groups.foreman_puppet.rb +37 -12
- data/db/migrate/20201125113903_migrate_puppetclasses_to_facets.foreman_puppet.rb +13 -1
- data/lib/foreman_puppet/engine.rb +68 -20
- data/lib/foreman_puppet/register.rb +7 -2
- data/lib/foreman_puppet/version.rb +1 -1
- data/lib/foreman_puppet.rb +3 -3
- data/locale/Makefile +1 -1
- data/locale/en/LC_MESSAGES/foreman_puppet.mo +0 -0
- data/locale/en/foreman_puppet.edit.po +19 -3
- data/locale/en/foreman_puppet.po +18 -6
- data/locale/en/foreman_puppet.pox +0 -0
- data/locale/foreman_puppet.pot +19 -3
- data/locale/messages.mo +0 -0
- data/test/controllers/foreman_puppet/api/v2/config_groups_controller_test.rb +7 -3
- data/test/controllers/foreman_puppet/api/v2/environments_controller_test.rb +18 -16
- data/test/controllers/foreman_puppet/api/v2/hosts_controller_test.rb +3 -2
- data/test/controllers/foreman_puppet/api/v2/lookups_common_controller_test.rb +1 -1
- data/test/controllers/foreman_puppet/api/v2/provisioning_templates_controller_test.rb +32 -0
- data/test/controllers/foreman_puppet/api/v2/puppetclasses_controller_test.rb +3 -0
- data/test/controllers/foreman_puppet/api/v2/smart_class_parameters_controller_test.rb +7 -1
- data/test/controllers/foreman_puppet/api/v2/template_combinations_controller_test.rb +2 -2
- data/test/controllers/foreman_puppet/config_groups_controller_test.rb +7 -3
- data/test/controllers/foreman_puppet/environments_controller_test.rb +2 -2
- data/test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb +2 -2
- data/test/controllers/foreman_puppet/puppetclasses_controller_test.rb +5 -6
- data/test/factories/foreman_puppet_factories.rb +3 -0
- data/test/factories/host_puppet_enhancements.rb +6 -6
- data/test/graphql/mutations/hosts/create_mutation_test.rb +87 -0
- data/test/graphql/queries/environment_query_test.rb +54 -0
- data/test/graphql/queries/environments_query_test.rb +43 -0
- data/test/{qraphql → graphql}/queries/host_puppet_query_test.rb +3 -8
- data/test/{qraphql → graphql}/queries/hostgroup_puppet_query_test.rb +1 -6
- data/test/graphql/queries/location_query_test.rb +52 -0
- data/test/graphql/queries/organization_query_test.rb +52 -0
- data/test/graphql/queries/puppetclass_query_test.rb +68 -0
- data/test/graphql/queries/puppetclasses_query_test.rb +43 -0
- data/test/integration/foreman_puppet/environment_js_test.rb +4 -1
- data/test/integration/foreman_puppet/host_js_test.rb +1 -1
- data/test/integration/foreman_puppet/puppetclass_js_test.rb +4 -0
- data/test/models/foreman_puppet/config_group_class_test.rb +3 -1
- data/test/models/foreman_puppet/environment_test.rb +2 -0
- data/test/models/foreman_puppet/host_puppet_facet_test.rb +34 -1
- data/test/models/foreman_puppet/host_test.rb +4 -3
- data/test/models/foreman_puppet/hostgroup_puppet_facet_test.rb +2 -3
- data/test/models/foreman_puppet/provisioning_template_test.rb +14 -7
- data/test/models/foreman_puppet/report_test.rb +21 -0
- data/test/models/foreman_puppet/smart_proxy_test.rb +1 -1
- data/test/models/foreman_puppet/user_test.rb +37 -0
- data/test/services/foreman_puppet/host_info_providers/config_groups_info_test.rb +35 -0
- data/test/services/foreman_puppet/host_info_providers/puppet_info_test.rb +159 -197
- data/test/unit/foreman_puppet/puppet_class_importer_test.rb +16 -2
- data/webpack/index.js +3 -4
- data/webpack/src/Components/Environments/Welcome.js +37 -0
- metadata +51 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49e644faeeffa930e09b12d75395777a23aa7bec00b9dbdf16eeed14b3d2e9bc
|
4
|
+
data.tar.gz: 9da4592a03b0fc3431a8f3c12c8bd046782544b5df29419949471b5919388c66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e40390e1c1b70276056a455672397f0425c48fa71dda42cdf814f3718b3869f6b59ab3fa0250acbb5699754a9bdc7ef64640aef07e0cf1388e9b5b4ebc4fe27
|
7
|
+
data.tar.gz: c6a7e53a32381af7bef757d359e14e5828b3a3536e31f9291fda67af175ca637e971d605c302e479f49bf2e09c9ce8cdcf22494bcd28afe2244f19bbe429f053
|
data/README.md
CHANGED
@@ -1,19 +1,74 @@
|
|
1
1
|
# ForemanPuppet
|
2
2
|
|
3
|
-
|
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](
|
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
|
-
|
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
|
-
##
|
68
|
+
## Problems
|
15
69
|
|
16
|
-
|
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) *
|
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
|
data/app/controllers/concerns/foreman_puppet/extensions/api_template_combinations_controller.rb
CHANGED
@@ -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,
|
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
|
-
|
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
|
-
|
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 =
|
38
|
-
|
39
|
-
|
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
|
-
|
11
|
-
|
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 <
|
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 <
|
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::
|
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::
|
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 <
|
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
|
4
|
+
class PuppetBaseController < ::Api::V2::BaseController
|
5
5
|
resource_description do
|
6
|
-
api_version '
|
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
|
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
|
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 <
|
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::
|
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
|
|
@@ -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 =
|
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
|
-
|
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
|
-
|
73
|
-
|
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
|