foreman_puppet 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +619 -0
- data/README.md +38 -0
- data/Rakefile +31 -0
- data/app/assets/stylesheets/foreman_puppet.scss +117 -0
- data/app/controllers/concerns/foreman_puppet/api/import_puppetclasses_common_controller.rb +139 -0
- data/app/controllers/concerns/foreman_puppet/environments_import.rb +61 -0
- data/app/controllers/concerns/foreman_puppet/extensions/api_hostgroups_controller.rb +40 -0
- data/app/controllers/concerns/foreman_puppet/extensions/api_template_combinations_controller.rb +23 -0
- data/app/controllers/concerns/foreman_puppet/extensions/api_v2_hosts_controller.rb +48 -0
- data/app/controllers/concerns/foreman_puppet/extensions/hostgroups_controller_extensions.rb +58 -0
- data/app/controllers/concerns/foreman_puppet/extensions/hosts_controller_extensions.rb +228 -0
- data/app/controllers/concerns/foreman_puppet/extensions/operatingsystems_controller.rb +11 -0
- data/app/controllers/concerns/foreman_puppet/extensions/parameters_host.rb +75 -0
- data/app/controllers/concerns/foreman_puppet/extensions/parameters_hostgroup.rb +70 -0
- data/app/controllers/concerns/foreman_puppet/extensions/parameters_template_combination.rb +21 -0
- data/app/controllers/concerns/foreman_puppet/parameters/config_group.rb +17 -0
- data/app/controllers/concerns/foreman_puppet/parameters/environment.rb +21 -0
- data/app/controllers/concerns/foreman_puppet/parameters/puppetclass.rb +24 -0
- data/app/controllers/concerns/foreman_puppet/parameters/puppetclass_lookup_key.rb +24 -0
- data/app/controllers/foreman_puppet/api/v2/base_controller.rb +26 -0
- data/app/controllers/foreman_puppet/api/v2/config_groups_controller.rb +57 -0
- data/app/controllers/foreman_puppet/api/v2/environments_controller.rb +91 -0
- data/app/controllers/foreman_puppet/api/v2/host_classes_controller.rb +59 -0
- data/app/controllers/foreman_puppet/api/v2/hostgroup_classes_controller.rb +46 -0
- data/app/controllers/foreman_puppet/api/v2/lookups_common_controller.rb +114 -0
- data/app/controllers/foreman_puppet/api/v2/override_values_controller.rb +99 -0
- data/app/controllers/foreman_puppet/api/v2/puppetclasses_controller.rb +99 -0
- data/app/controllers/foreman_puppet/api/v2/smart_class_parameters_controller.rb +76 -0
- data/app/controllers/foreman_puppet/config_groups_controller.rb +46 -0
- data/app/controllers/foreman_puppet/environments_controller.rb +51 -0
- data/app/controllers/foreman_puppet/puppet_smart_proxies_controller.rb +39 -0
- data/app/controllers/foreman_puppet/puppetclass_lookup_keys_controller.rb +33 -0
- data/app/controllers/foreman_puppet/puppetclasses_controller.rb +113 -0
- data/app/controllers/foreman_puppet/react_controller.rb +19 -0
- data/app/helpers/concerns/foreman_puppet/template_renderer_scope.rb +14 -0
- data/app/helpers/foreman_puppet/environments_helper.rb +17 -0
- data/app/helpers/foreman_puppet/hosts_and_hostgroups_helper.rb +96 -0
- data/app/helpers/foreman_puppet/hosts_helper.rb +32 -0
- data/app/helpers/foreman_puppet/puppet_smart_proxies_helper.rb +8 -0
- data/app/helpers/foreman_puppet/puppetclass_lookup_keys_helper.rb +135 -0
- data/app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb +55 -0
- data/app/helpers/foreman_puppet/puppetclasses_helper.rb +59 -0
- data/app/helpers/foreman_puppet/template_combinations_helper.rb +33 -0
- data/app/models/concerns/foreman_puppet/extensions/host.rb +88 -0
- data/app/models/concerns/foreman_puppet/extensions/hostgroup.rb +40 -0
- data/app/models/concerns/foreman_puppet/extensions/nic_managed.rb +11 -0
- data/app/models/concerns/foreman_puppet/extensions/operatingsystem.rb +11 -0
- data/app/models/concerns/foreman_puppet/extensions/provisioning_template.rb +64 -0
- data/app/models/concerns/foreman_puppet/extensions/report.rb +11 -0
- data/app/models/concerns/foreman_puppet/extensions/taxonomy.rb +19 -0
- data/app/models/concerns/foreman_puppet/extensions/template_combination.rb +23 -0
- data/app/models/concerns/foreman_puppet/extensions/user.rb +22 -0
- data/app/models/concerns/foreman_puppet/host_common.rb +90 -0
- data/app/models/concerns/foreman_puppet/puppet_lookup_value_extensions.rb +13 -0
- data/app/models/foreman_puppet/config_group.rb +45 -0
- data/app/models/foreman_puppet/config_group_class.rb +19 -0
- data/app/models/foreman_puppet/environment.rb +63 -0
- data/app/models/foreman_puppet/environment_class.rb +40 -0
- data/app/models/foreman_puppet/host_class.rb +23 -0
- data/app/models/foreman_puppet/host_config_group.rb +15 -0
- data/app/models/foreman_puppet/host_puppet_facet.rb +130 -0
- data/app/models/foreman_puppet/hostgroup_class.rb +23 -0
- data/app/models/foreman_puppet/hostgroup_puppet_facet.rb +98 -0
- data/app/models/foreman_puppet/puppetclass.rb +132 -0
- data/app/models/foreman_puppet/puppetclass_lookup_key.rb +58 -0
- data/app/services/foreman_puppet/host_info_providers/config_groups_info.rb +10 -0
- data/app/services/foreman_puppet/host_info_providers/puppet_info.rb +92 -0
- data/app/services/foreman_puppet/input_type/puppet_parameter_input.rb +35 -0
- data/app/services/foreman_puppet/proxy_status/puppet.rb +17 -0
- data/app/services/foreman_puppet/puppet_class_importer.rb +355 -0
- data/app/views/api/v2/template_combinations/base.json.erb +9 -0
- data/app/views/foreman_puppet/api/v2/config_groups/base.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/config_groups/create.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/config_groups/index.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/config_groups/main.json.rabl +8 -0
- data/app/views/foreman_puppet/api/v2/config_groups/show.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/config_groups/update.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/environments/base.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/environments/create.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/environments/index.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/environments/main.json.rabl +5 -0
- data/app/views/foreman_puppet/api/v2/environments/show.json.rabl +15 -0
- data/app/views/foreman_puppet/api/v2/environments/update.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/host_puppet_facets/base.json.rabl +1 -0
- data/app/views/foreman_puppet/api/v2/host_puppet_facets/host_single.json.rabl +17 -0
- data/app/views/foreman_puppet/api/v2/host_puppet_facets/show.json.rabl +11 -0
- data/app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/base.json.rabl +5 -0
- data/app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/hostgroup_single.json.rabl +16 -0
- data/app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/show.json.rabl +11 -0
- data/app/views/foreman_puppet/api/v2/import_puppetclasses/index.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/import_puppetclasses/show.json.rabl +36 -0
- data/app/views/foreman_puppet/api/v2/override_values/create.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/override_values/index.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/override_values/show.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/override_values/update.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/puppetclasses/base.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/puppetclasses/create.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/puppetclasses/index.json.rabl +4 -0
- data/app/views/foreman_puppet/api/v2/puppetclasses/list.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/puppetclasses/main.json.rabl +5 -0
- data/app/views/foreman_puppet/api/v2/puppetclasses/show.json.rabl +15 -0
- data/app/views/foreman_puppet/api/v2/puppetclasses/update.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/smart_class_parameters/base.json.rabl +4 -0
- data/app/views/foreman_puppet/api/v2/smart_class_parameters/create.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/smart_class_parameters/destroy.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/smart_class_parameters/index.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/smart_class_parameters/main.json.rabl +23 -0
- data/app/views/foreman_puppet/api/v2/smart_class_parameters/show.json.rabl +19 -0
- data/app/views/foreman_puppet/api/v2/smart_class_parameters/update.json.rabl +3 -0
- data/app/views/foreman_puppet/config_groups/_config_group.html.erb +34 -0
- data/app/views/foreman_puppet/config_groups/_config_groups_selection.html.erb +36 -0
- data/app/views/foreman_puppet/config_groups/_form.html.erb +9 -0
- data/app/views/foreman_puppet/config_groups/edit.html.erb +3 -0
- data/app/views/foreman_puppet/config_groups/index.html.erb +31 -0
- data/app/views/foreman_puppet/config_groups/new.html.erb +3 -0
- data/app/views/foreman_puppet/config_groups/welcome.html.erb +12 -0
- data/app/views/foreman_puppet/environments/_form.html.erb +20 -0
- data/app/views/foreman_puppet/environments/edit.html.erb +8 -0
- data/app/views/foreman_puppet/environments/index.html.erb +32 -0
- data/app/views/foreman_puppet/environments/new.html.erb +7 -0
- data/app/views/foreman_puppet/environments/welcome.html.erb +16 -0
- data/app/views/foreman_puppet/layouts/application_react.html.erb +15 -0
- data/app/views/foreman_puppet/puppet_smart_proxies/_dashboard.html.erb +9 -0
- data/app/views/foreman_puppet/puppet_smart_proxies/_environments.html.erb +30 -0
- data/app/views/foreman_puppet/puppetclass_lookup_keys/edit.html.erb +3 -0
- data/app/views/foreman_puppet/puppetclass_lookup_keys/index.html.erb +22 -0
- data/app/views/foreman_puppet/puppetclass_lookup_keys/welcome.html.erb +9 -0
- data/app/views/foreman_puppet/puppetclasses/_class_parameters.html.erb +37 -0
- data/app/views/foreman_puppet/puppetclasses/_class_selection.html.erb +70 -0
- data/app/views/foreman_puppet/puppetclasses/_classes.html.erb +22 -0
- data/app/views/foreman_puppet/puppetclasses/_classes_in_groups.html.erb +5 -0
- data/app/views/foreman_puppet/puppetclasses/_classes_parameters.html.erb +16 -0
- data/app/views/foreman_puppet/puppetclasses/_form.html.erb +62 -0
- data/app/views/foreman_puppet/puppetclasses/_selected_classes.html.erb +4 -0
- data/app/views/foreman_puppet/puppetclasses/edit.html.erb +4 -0
- data/app/views/foreman_puppet/puppetclasses/index.html.erb +47 -0
- data/app/views/hosts/_form_puppet_enc_tab.html.erb +24 -0
- data/app/views/hosts/foreman_puppet/_form_main_tab_fields.html.erb +1 -0
- data/app/views/hosts/select_multiple_environment.html.erb +8 -0
- data/app/views/provisioning_templates/_combination.html.erb +5 -0
- data/app/views/provisioning_templates/_combinations.html.erb +6 -0
- data/app/views/smart_proxies/plugins/_puppet.html.erb +24 -0
- data/config/api_routes.rb +81 -0
- data/config/routes.rb +89 -0
- data/db/migrate/20101121140000_add_environment_to_template_combinations.foreman_puppet.rb +9 -0
- data/db/migrate/20200720123005_migrate_puppet_core_types.foreman_puppet.rb +19 -0
- data/db/migrate/20200722171017_create_host_puppet_facet.foreman_puppet.rb +10 -0
- data/db/migrate/20200803113531_create_hostgroup_puppet_facet.foreman_puppet.rb +10 -0
- data/db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb +22 -0
- data/db/migrate/20200803113903_migrate_host_type_in_host_config_groups.foreman_puppet.rb +29 -0
- data/db/migrate/20201125113903_migrate_puppetclasses_to_facets.foreman_puppet.rb +47 -0
- data/db/migrate_foreman/20090722141107_create_environments.rb +17 -0
- data/db/migrate_foreman/20120905095532_create_environment_classes.rb +15 -0
- data/db/migrate_foreman/20140407161817_create_config_groups.rb +9 -0
- data/db/migrate_foreman/20140407162007_create_config_group_classes.rb +10 -0
- data/db/migrate_foreman/20140407162059_create_host_config_groups.rb +11 -0
- data/db/migrate_foreman/20161205142618_delete_orphaned_smart_class_parameters.rb +10 -0
- data/db/migrate_foreman/20170109115157_fix_lookup_key_auditable_type.rb +15 -0
- data/db/migrate_foreman/20180816134832_cast_lookup_key_values.rb +35 -0
- data/db/migrate_foreman/20181023112532_add_environment_puppetclass_id.rb +7 -0
- data/db/migrate_foreman/20181224174419_add_index_to_environment_class_by_lookup_key_and_puppetclass.rb +6 -0
- data/db/seeds.d/111_puppet_proxy_feature.rb +8 -0
- data/lib/foreman_puppet.rb +10 -0
- data/lib/foreman_puppet/engine.rb +82 -0
- data/lib/foreman_puppet/register.rb +218 -0
- data/lib/foreman_puppet/version.rb +3 -0
- data/lib/tasks/foreman_puppet_tasks.rake +31 -0
- data/locale/Makefile +60 -0
- data/locale/action_names.rb +5 -0
- data/locale/en/foreman_puppet.edit.po +911 -0
- data/locale/en/foreman_puppet.po +690 -0
- data/locale/en/foreman_puppet.po.time_stamp +0 -0
- data/locale/foreman_puppet.pot +1076 -0
- data/locale/gemspec.rb +2 -0
- data/test/controllers/foreman_puppet/api/v2/config_groups_controller_test.rb +28 -0
- data/test/controllers/foreman_puppet/api/v2/environments_controller_test.rb +346 -0
- data/test/controllers/foreman_puppet/api/v2/host_classes_controller_test.rb +48 -0
- data/test/controllers/foreman_puppet/api/v2/hostgroup_classes_controller_test.rb +41 -0
- data/test/controllers/foreman_puppet/api/v2/hostgroups_controller_test.rb +79 -0
- data/test/controllers/foreman_puppet/api/v2/hosts_controller_test.rb +101 -0
- data/test/controllers/foreman_puppet/api/v2/lookups_common_controller_test.rb +29 -0
- data/test/controllers/foreman_puppet/api/v2/override_values_controller_test.rb +169 -0
- data/test/controllers/foreman_puppet/api/v2/puppetclasses_controller_test.rb +144 -0
- data/test/controllers/foreman_puppet/api/v2/smart_class_parameters_controller_test.rb +557 -0
- data/test/controllers/foreman_puppet/api/v2/template_combinations_controller_test.rb +81 -0
- data/test/controllers/foreman_puppet/config_groups_controller_test.rb +47 -0
- data/test/controllers/foreman_puppet/environments_controller_test.rb +230 -0
- data/test/controllers/foreman_puppet/hostgroups_controller_test.rb +72 -0
- data/test/controllers/foreman_puppet/hosts_controller_test.rb +346 -0
- data/test/controllers/foreman_puppet/puppet_smart_proxies_controller_test.rb +29 -0
- data/test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb +59 -0
- data/test/controllers/foreman_puppet/puppetclasses_controller_test.rb +235 -0
- data/test/controllers/provisioning_templates_controller_test.rb +70 -0
- data/test/factories/foreman_puppet_factories.rb +134 -0
- data/test/factories/host_puppet_enhancements.rb +61 -0
- data/test/factories/proxy_puppet_enhancements.rb +33 -0
- data/test/helpers/foreman_puppet/hosts_and_hostgroups_helper_test.rb +65 -0
- data/test/helpers/foreman_puppet/puppetclasses_helper_test.rb +33 -0
- data/test/integration/foreman_puppet/environment_js_test.rb +27 -0
- data/test/integration/foreman_puppet/host_js_test.rb +371 -0
- data/test/integration/foreman_puppet/hostgroup_js_test.rb +100 -0
- data/test/integration/foreman_puppet/puppetclass_js_test.rb +37 -0
- data/test/integration/foreman_puppet/smartclass_parameter_js_test.rb +84 -0
- data/test/models/foreman_puppet/config_group_class_test.rb +9 -0
- data/test/models/foreman_puppet/config_group_test.rb +8 -0
- data/test/models/foreman_puppet/environment_test.rb +92 -0
- data/test/models/foreman_puppet/host_config_group_test.rb +39 -0
- data/test/models/foreman_puppet/host_puppet_facet_test.rb +116 -0
- data/test/models/foreman_puppet/host_test.rb +288 -0
- data/test/models/foreman_puppet/hostgroup_puppet_facet_test.rb +200 -0
- data/test/models/foreman_puppet/hostgroup_test.rb +14 -0
- data/test/models/foreman_puppet/lookup_value_test.rb +69 -0
- data/test/models/foreman_puppet/provisioning_template_test.rb +124 -0
- data/test/models/foreman_puppet/puppetclass_lookup_key_test.rb +81 -0
- data/test/models/foreman_puppet/puppetclass_test.rb +144 -0
- data/test/models/foreman_puppet/smart_proxy_test.rb +28 -0
- data/test/qraphql/queries/host_puppet_query_test.rb +36 -0
- data/test/qraphql/queries/hostgroup_puppet_query_test.rb +36 -0
- data/test/services/foreman_puppet/host_info_providers/puppet_info_test.rb +791 -0
- data/test/services/foreman_puppet/input_type/puppet_parameter_input_test.rb +14 -0
- data/test/test_puppet_helper.rb +30 -0
- data/test/unit/foreman_puppet/access_permissions_test.rb +16 -0
- data/test/unit/foreman_puppet/puppet_class_importer_test.rb +247 -0
- data/test/unit/foreman_puppet/template_rendering_test.rb +20 -0
- data/test/unit/foreman_puppet_test.rb +11 -0
- data/webpack/__mocks__/foremanReact/common/I18n.js +7 -0
- data/webpack/__mocks__/foremanReact/components/Layout/LayoutActions.js +2 -0
- data/webpack/__mocks__/foremanReact/readme.md +11 -0
- data/webpack/__mocks__/foremanReact/redux/API/APISelectors.js +10 -0
- data/webpack/__mocks__/foremanReact/redux/API/index.js +10 -0
- data/webpack/__mocks__/foremanReact/redux/actions/toasts.js +8 -0
- data/webpack/__mocks__/foremanReact/redux/index.js +1 -0
- data/webpack/__mocks__/foremanReact/redux/middlewares/IntervalMiddleware.js +5 -0
- data/webpack/fills_index.js +30 -0
- data/webpack/index.js +18 -0
- data/webpack/src/ForemanPuppet.js +11 -0
- data/webpack/src/Router/__snapshots__/routes.test.js.snap +3 -0
- data/webpack/src/Router/index.js +14 -0
- data/webpack/src/Router/routes.js +3 -0
- data/webpack/src/Router/routes.test.js +16 -0
- data/webpack/src/foreman_class_edit.js +224 -0
- data/webpack/src/foreman_puppet_host_form.js +140 -0
- data/webpack/src/foreman_puppet_host_form.test.js +65 -0
- data/webpack/src/index.js +1 -0
- data/webpack/src/reducers.js +7 -0
- metadata +340 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
module ForemanPuppet
|
2
|
+
module Extensions
|
3
|
+
module ParametersTemplateCombination
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
class << self
|
8
|
+
prepend PrependedClassMethods
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module PrependedClassMethods
|
13
|
+
def template_combination_params_filter
|
14
|
+
super.tap do |filter|
|
15
|
+
filter.permit_by_context :environment_id, :environment_name, :environment, nested: true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module ForemanPuppet::Parameters::ConfigGroup
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
class_methods do
|
5
|
+
def config_group_params_filter
|
6
|
+
Foreman::ParameterFilter.new(ForemanPuppet::ConfigGroup).tap do |filter|
|
7
|
+
filter.permit :name,
|
8
|
+
class_environments: [],
|
9
|
+
puppetclass_ids: [], puppetclass_names: []
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def config_group_params
|
15
|
+
self.class.config_group_params_filter.filter_params(params, parameter_filter_context)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ForemanPuppet
|
2
|
+
module Parameters
|
3
|
+
module Environment
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
include Foreman::Controller::Parameters::Taxonomix
|
6
|
+
|
7
|
+
class_methods do
|
8
|
+
def environment_params_filter
|
9
|
+
Foreman::ParameterFilter.new(ForemanPuppet::Environment).tap do |filter|
|
10
|
+
filter.permit :name
|
11
|
+
add_taxonomix_params_filter(filter)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def environment_params
|
17
|
+
self.class.environment_params_filter.filter_params(params, parameter_filter_context)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ForemanPuppet
|
2
|
+
module Parameters
|
3
|
+
module Puppetclass
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
include Parameters::PuppetclassLookupKey
|
6
|
+
|
7
|
+
class_methods do
|
8
|
+
def puppetclass_params_filter
|
9
|
+
Foreman::ParameterFilter.new(ForemanPuppet::Puppetclass).tap do |filter|
|
10
|
+
filter.permit :name,
|
11
|
+
class_params_attributes: [puppetclass_lookup_key_params_filter],
|
12
|
+
hostgroup_ids: [], hostgroup_names: [],
|
13
|
+
smart_class_parameters: [puppetclass_lookup_key_params_filter],
|
14
|
+
smart_class_parameter_ids: [], smart_class_parameter_names: []
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def puppetclass_params
|
20
|
+
self.class.puppetclass_params_filter.filter_params(params, parameter_filter_context)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ForemanPuppet
|
2
|
+
module Parameters::PuppetclassLookupKey
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
include Foreman::Controller::Parameters::LookupKey
|
5
|
+
|
6
|
+
class_methods do
|
7
|
+
def puppetclass_lookup_key_params_filter
|
8
|
+
Foreman::ParameterFilter.new(ForemanPuppet::PuppetclassLookupKey).tap do |filter|
|
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: []
|
12
|
+
filter.permit_by_context :required, nested: true
|
13
|
+
filter.permit_by_context :id, ui: false, api: false, nested: true
|
14
|
+
|
15
|
+
add_lookup_key_params_filter(filter)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def puppetclass_lookup_key_params
|
21
|
+
self.class.puppetclass_lookup_key_params_filter.filter_params(params, parameter_filter_context)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ForemanPuppet
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
class BaseController < ::Api::V2::BaseController
|
5
|
+
resource_description do
|
6
|
+
api_version '2'
|
7
|
+
api_base_url '/foreman_puppet/api'
|
8
|
+
end
|
9
|
+
|
10
|
+
before_action :show_deprecation_for_core_routes
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def show_deprecation_for_core_routes
|
15
|
+
return if request.path.starts_with?('/foreman_puppet')
|
16
|
+
Foreman::Deprecation.api_deprecation_warning(
|
17
|
+
format(
|
18
|
+
'/api/v2/%{controller} API endpoints are deprecated, please use /foreman_puppet/api/v2/%{controller} instead',
|
19
|
+
controller: controller_name
|
20
|
+
)
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module ForemanPuppet
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
class ConfigGroupsController < BaseController
|
5
|
+
include ForemanPuppet::Parameters::ConfigGroup
|
6
|
+
|
7
|
+
wrap_parameters ConfigGroup, include: config_group_params_filter.accessible_attributes(parameter_filter_context)
|
8
|
+
|
9
|
+
before_action :find_resource, only: %i[show update destroy]
|
10
|
+
|
11
|
+
api :GET, '/config_groups', N_('List of config groups')
|
12
|
+
param_group :search_and_pagination, ::Api::V2::BaseController
|
13
|
+
add_scoped_search_description_for(ConfigGroup)
|
14
|
+
|
15
|
+
def index
|
16
|
+
@config_groups = resource_scope_for_index
|
17
|
+
end
|
18
|
+
|
19
|
+
api :GET, '/config_groups/:id/', N_('Show a config group')
|
20
|
+
param :id, :identifier, required: true
|
21
|
+
|
22
|
+
def show
|
23
|
+
end
|
24
|
+
|
25
|
+
def_param_group :config_group do
|
26
|
+
param :config_group, Hash, required: true, action_aware: true do
|
27
|
+
param :name, String, required: true
|
28
|
+
param :puppetclass_ids, Array
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
api :POST, '/config_groups/', N_('Create a config group')
|
33
|
+
param_group :config_group, as: :create
|
34
|
+
|
35
|
+
def create
|
36
|
+
@config_group = ConfigGroup.new(config_group_params)
|
37
|
+
process_response @config_group.save
|
38
|
+
end
|
39
|
+
|
40
|
+
api :PUT, '/config_groups/:id/', N_('Update a config group')
|
41
|
+
param :id, String, required: true
|
42
|
+
param_group :config_group
|
43
|
+
|
44
|
+
def update
|
45
|
+
process_response @config_group.update(config_group_params)
|
46
|
+
end
|
47
|
+
|
48
|
+
api :DELETE, '/config_groups/:id/', N_('Delete a config group')
|
49
|
+
param :id, String, required: true
|
50
|
+
|
51
|
+
def destroy
|
52
|
+
process_response @config_group.destroy
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module ForemanPuppet
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
class EnvironmentsController < BaseController
|
5
|
+
include ForemanPuppet::Api::ImportPuppetclassesCommonController
|
6
|
+
include ForemanPuppet::Parameters::Environment
|
7
|
+
|
8
|
+
resource_description do
|
9
|
+
api_version '2'
|
10
|
+
api_base_url '/foreman_puppet/api'
|
11
|
+
end
|
12
|
+
|
13
|
+
before_action :find_optional_nested_object
|
14
|
+
before_action :find_resource, only: %w[show update destroy]
|
15
|
+
|
16
|
+
api :GET, '/environments/', N_('List all environments')
|
17
|
+
api :GET, '/puppetclasses/:puppetclass_id/environments', N_('List environments of Puppet class')
|
18
|
+
api :GET, '/locations/:location_id/environments', N_('List environments per location')
|
19
|
+
api :GET, '/organizations/:organization_id/environments', N_('List environments per organization')
|
20
|
+
param :puppetclass_id, String, desc: N_('ID of Puppet class')
|
21
|
+
param_group :taxonomy_scope, ::Api::V2::BaseController
|
22
|
+
param_group :search_and_pagination, ::Api::V2::BaseController
|
23
|
+
add_scoped_search_description_for(Environment)
|
24
|
+
|
25
|
+
def index
|
26
|
+
@environments = resource_scope_for_index
|
27
|
+
end
|
28
|
+
|
29
|
+
api :GET, '/environments/:id/', N_('Show an environment')
|
30
|
+
param :id, :identifier, required: true
|
31
|
+
|
32
|
+
def show
|
33
|
+
end
|
34
|
+
|
35
|
+
def_param_group :environment do
|
36
|
+
param :environment, Hash, required: true, action_aware: true do
|
37
|
+
param :name, String, required: true
|
38
|
+
param_group :taxonomies, ::Api::V2::BaseController
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
api :POST, '/environments/', N_('Create an environment')
|
43
|
+
param_group :environment, as: :create
|
44
|
+
|
45
|
+
def create
|
46
|
+
@environment = Environment.new(environment_params)
|
47
|
+
process_response @environment.save
|
48
|
+
end
|
49
|
+
|
50
|
+
api :PUT, '/environments/:id/', N_('Update an environment')
|
51
|
+
param :id, :identifier, required: true
|
52
|
+
param_group :environment
|
53
|
+
|
54
|
+
def update
|
55
|
+
process_response @environment.update(environment_params)
|
56
|
+
end
|
57
|
+
|
58
|
+
api :DELETE, '/environments/:id/', N_('Delete an environment')
|
59
|
+
param :id, :identifier, required: true
|
60
|
+
|
61
|
+
def destroy
|
62
|
+
process_response @environment.destroy
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def action_permission
|
68
|
+
case params[:action]
|
69
|
+
when 'import_puppetclasses'
|
70
|
+
:import_puppetclasses
|
71
|
+
else
|
72
|
+
super
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def parent_permission(child_permission)
|
77
|
+
case child_permission.to_s
|
78
|
+
when 'import_puppetclasses'
|
79
|
+
:view
|
80
|
+
else
|
81
|
+
super
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def allowed_nested_id
|
86
|
+
%w[puppetclass_id location_id organization_id]
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module ForemanPuppet
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
class HostClassesController < V2::BaseController
|
5
|
+
before_action :find_host, only: %i[index create destroy]
|
6
|
+
before_action :find_puppetclass, only: %i[create destroy]
|
7
|
+
|
8
|
+
api :GET, '/hosts/:host_id/puppetclass_ids/', N_('List all Puppet class IDs for host')
|
9
|
+
|
10
|
+
def index
|
11
|
+
render json: { root_node_name => HostClass.authorized(:edit_classes).where(host_puppet_facet_id: @host.puppet.id).pluck('puppetclass_id') }
|
12
|
+
end
|
13
|
+
|
14
|
+
api :POST, '/hosts/:host_id/puppetclass_ids', N_('Add a Puppet class to host')
|
15
|
+
param :host_id, String, required: true, desc: N_('ID of host')
|
16
|
+
param :puppetclass_id, String, required: true, desc: N_('ID of Puppet class')
|
17
|
+
|
18
|
+
def create
|
19
|
+
@host_class = HostClass.create!(host_puppet_facet_id: @host.puppet.id, puppetclass_id: @puppetclass.id)
|
20
|
+
render json: { host_id: @host.id, puppetclass_id: @host_class.puppetclass_id }
|
21
|
+
end
|
22
|
+
|
23
|
+
api :DELETE, '/hosts/:host_id/puppetclass_ids/:id/', N_('Remove a Puppet class from host')
|
24
|
+
param :host_id, String, required: true, desc: N_('ID of host')
|
25
|
+
param :id, String, required: true, desc: N_('ID of Puppet class')
|
26
|
+
|
27
|
+
def destroy
|
28
|
+
@host_class = HostClass.authorized(:edit_classes).where(host_puppet_facet_id: @host.puppet.id, puppetclass_id: @puppetclass.id)
|
29
|
+
process_response @host_class.destroy_all
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
# overwrite resource_name so it's host and and not host_class, since we want to return @host
|
35
|
+
def find_host
|
36
|
+
if params[:host_id].blank?
|
37
|
+
not_found
|
38
|
+
return false
|
39
|
+
end
|
40
|
+
if ::Host::Managed.respond_to?(:authorized) &&
|
41
|
+
::Host::Managed.authorized('view_host', Host::Managed)
|
42
|
+
@host = resource_finder(::Host.authorized(:view_hosts), params[:host_id])
|
43
|
+
@host.puppet || @host.create_puppet
|
44
|
+
@host
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def find_puppetclass
|
49
|
+
puppetclass_id = if params[:action] == 'create'
|
50
|
+
params[:puppetclass_id]
|
51
|
+
else
|
52
|
+
params[:id]
|
53
|
+
end
|
54
|
+
@puppetclass = resource_finder(Puppetclass.authorized(:view_puppetclasses), puppetclass_id)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module ForemanPuppet
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
class HostgroupClassesController < V2::BaseController
|
5
|
+
before_action :find_hostgroup, only: %i[index create destroy]
|
6
|
+
|
7
|
+
api :GET, '/hostgroups/:hostgroup_id/puppetclass_ids/', N_('List all Puppet class IDs for host group')
|
8
|
+
|
9
|
+
def index
|
10
|
+
render json: { root_node_name => HostgroupClass.where(hostgroup_puppet_facet_id: @hostgroup.puppet.id).pluck('puppetclass_id') }
|
11
|
+
end
|
12
|
+
|
13
|
+
api :POST, '/hostgroups/:hostgroup_id/puppetclass_ids', N_('Add a Puppet class to host group')
|
14
|
+
param :hostgroup_id, String, required: true, desc: N_('ID of host group')
|
15
|
+
param :puppetclass_id, String, required: true, desc: N_('ID of Puppet class')
|
16
|
+
|
17
|
+
def create
|
18
|
+
@hostgroup_class = HostgroupClass.create!(hostgroup_puppet_facet_id: @hostgroup.puppet.id, puppetclass_id: params[:puppetclass_id].to_i)
|
19
|
+
render json: { hostgroup_id: @hostgroup_class.hostgroup_id, puppetclass_id: @hostgroup_class.puppetclass_id }
|
20
|
+
end
|
21
|
+
|
22
|
+
api :DELETE, '/hostgroups/:hostgroup_id/puppetclass_ids/:id/', N_('Remove a Puppet class from host group')
|
23
|
+
param :hostgroup_id, String, required: true, desc: N_('ID of host group')
|
24
|
+
param :id, String, required: true, desc: N_('ID of Puppet class')
|
25
|
+
|
26
|
+
def destroy
|
27
|
+
@hostgroup_class = HostgroupClass.where(hostgroup_puppet_facet_id: @hostgroup.puppet.id, puppetclass_id: params[:id])
|
28
|
+
process_response @hostgroup_class.destroy_all
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def find_hostgroup
|
34
|
+
if params[:hostgroup_id].blank?
|
35
|
+
not_found
|
36
|
+
return false
|
37
|
+
end
|
38
|
+
@hostgroup = Hostgroup.find(params[:hostgroup_id]) if Hostgroup.respond_to?(:authorized) &&
|
39
|
+
Hostgroup.authorized('view_hostgroup', Hostgroup)
|
40
|
+
@hostgroup.puppet || @hostgroup.create_puppet
|
41
|
+
@hostgroup
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
module ForemanPuppet
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
class LookupsCommonController < ::Api::V2::BaseController
|
5
|
+
before_action :find_environment, if: :environment_id?
|
6
|
+
before_action :find_puppetclass, if: :puppetclass_id?
|
7
|
+
before_action :find_host, if: :host_id?
|
8
|
+
before_action :find_hostgroup, if: :hostgroup_id?
|
9
|
+
|
10
|
+
before_action :find_smart_class_parameters
|
11
|
+
before_action :find_smart_class_parameter
|
12
|
+
before_action :return_if_smart_mismatch, only: %i[show update destroy]
|
13
|
+
before_action :cast_default_value, only: %i[create update]
|
14
|
+
|
15
|
+
def show
|
16
|
+
end
|
17
|
+
|
18
|
+
def create
|
19
|
+
end
|
20
|
+
|
21
|
+
def update
|
22
|
+
end
|
23
|
+
|
24
|
+
def destroy
|
25
|
+
end
|
26
|
+
|
27
|
+
['ForemanPuppet::Puppetclass', 'ForemanPuppet::Environment', 'Host::Base', 'Hostgroup'].each do |klass|
|
28
|
+
model_string = klass.split('::').last.downcase
|
29
|
+
model_string = 'host' if klass == 'Host::Base'
|
30
|
+
|
31
|
+
define_method("#{model_string}_id?") do
|
32
|
+
params.key?("#{model_string}_id")
|
33
|
+
end
|
34
|
+
|
35
|
+
define_method("find_#{model_string}") do
|
36
|
+
scope = klass.constantize.authorized(:"view_#{model_string.pluralize}")
|
37
|
+
begin
|
38
|
+
instance_variable_set("@#{model_string}",
|
39
|
+
resource_finder(scope, params["#{model_string}_id"]))
|
40
|
+
rescue ActiveRecord::RecordNotFound
|
41
|
+
model_not_found(model_string)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def find_smart_class_parameter
|
47
|
+
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
|
49
|
+
@smart_class_parameter ||= begin
|
50
|
+
puppet_cond = { 'environment_classes.puppetclass_id' => @puppetclass.id } if @puppetclass
|
51
|
+
env_cond = { 'environment_classes.environment_id' => @environment.id } if @environment
|
52
|
+
PuppetclassLookupKey.authorized(:view_external_parameters).smart_class_parameters.where(puppet_cond).where(env_cond).where(key: id).first
|
53
|
+
end
|
54
|
+
@smart_class_parameter
|
55
|
+
end
|
56
|
+
|
57
|
+
def find_smart_class_parameters
|
58
|
+
@smart_class_parameters = smart_class_parameters_resource_scope.search_for(*search_options).paginate(paginate_options)
|
59
|
+
end
|
60
|
+
|
61
|
+
def smart_class_parameters_resource_scope
|
62
|
+
base = PuppetclassLookupKey.authorized(:view_external_parameters)
|
63
|
+
params = if !@puppetclass && !@environment && !@host && !@hostgroup
|
64
|
+
base.smart_class_parameters
|
65
|
+
elsif @puppetclass && @environment
|
66
|
+
base.smart_class_parameters_for_class(@puppetclass.id, @environment.id)
|
67
|
+
elsif @puppetclass && !@environment
|
68
|
+
environment_ids = @puppetclass.environment_classes.pluck(:environment_id).uniq
|
69
|
+
base.smart_class_parameters_for_class(@puppetclass.id, environment_ids)
|
70
|
+
elsif !@puppetclass && @environment
|
71
|
+
puppetclass_ids = @environment.environment_classes.pluck(:puppetclass_id).uniq
|
72
|
+
base.smart_class_parameters_for_class(puppetclass_ids, @environment.id)
|
73
|
+
elsif @host || @hostgroup
|
74
|
+
puppet_facet = (@host || @hostgroup).puppet || (@host || @hostgroup).build_puppet
|
75
|
+
puppetclass_ids = puppet_facet.all_puppetclasses.map(&:id)
|
76
|
+
environment_id = puppet_facet.environment_id
|
77
|
+
# scope :parameters_for_class uses .override
|
78
|
+
base.parameters_for_class(puppetclass_ids, environment_id)
|
79
|
+
end
|
80
|
+
params.distinct
|
81
|
+
end
|
82
|
+
|
83
|
+
def return_if_smart_mismatch
|
84
|
+
return unless @smart_class_parameters && (!smart_param_exists? || !@smart_class_parameter)
|
85
|
+
id = params.key?('smart_class_parameter_id') ? params['smart_variable_id'] : params['id']
|
86
|
+
not_found "Smart class parameter not found by id '#{id}''"
|
87
|
+
end
|
88
|
+
|
89
|
+
def cast_default_value
|
90
|
+
cast_value(:smart_class_parameter, :default_value)
|
91
|
+
end
|
92
|
+
|
93
|
+
def cast_value(obj = :override_value, value = :value)
|
94
|
+
return unless params[obj]&.key?(value)
|
95
|
+
param_value = params[obj][value]
|
96
|
+
return if param_value.is_a?(Hash)
|
97
|
+
params[obj][value] = param_value.to_s
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
def smart_param_exists?
|
103
|
+
@smart_class_parameter && @smart_class_parameters.find_by(id: @smart_class_parameter.id)
|
104
|
+
end
|
105
|
+
|
106
|
+
def model_not_found(model)
|
107
|
+
error_message =
|
108
|
+
format(_("%{model} with id '%{id}' was not found"), id: params["#{model}_id"], model: model.capitalize)
|
109
|
+
not_found(error: { message: error_message })
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|