foreman_puppet 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 06c268d86cd3905acdfcd56bc9898df23218553a632bb167c08de6c708351ee8
4
- data.tar.gz: fc9d44ecfdd418571796ccc39a302a5ac086bae221bc155ba5e827edfd45a9f0
3
+ metadata.gz: 0f4ecdeb14e00d3daed1a47021174874190c39173dbcf50548f8652128cff8c9
4
+ data.tar.gz: ee23eb1076fbf0a2d5a6b95e7d066c4eb88a343b99d039903f9350233095bb89
5
5
  SHA512:
6
- metadata.gz: e4169751ebd02e01e6628a8583490d7257e27c7f0852e7539fc42b4b989258d3efef9324c684db31776a0d8f48e9360d0e3d40bdb12c03e8dd66d923f7d521e2
7
- data.tar.gz: a0384e376fa23ed7dd0ada27f525d04cbeaebd19a1933e91ce97628dc3a4abe74ba79d6857040e4c920071e3afeef7858d121329ecbd3f6db2aa0486de9dba5f
6
+ metadata.gz: fa9df4333cfdf456010e4a67e5a7d67c7a198424b471c48a22a04f86ee8896e8be69ffcdcdc8b0b7df87d081cc7773dc13a489fd1586a5924329fbe3adc0742e
7
+ data.tar.gz: 4fc2f8dfccfb68519faed7519b65a8347e156dc776240d66d235c52c36bbed9736755b79bae5407b6bf67c5f8fd46628f126e075099a781b040d0d00a7a87f32
@@ -14,12 +14,7 @@ module ForemanPuppet
14
14
  module PatchedClassMethods
15
15
  def host_params_filter
16
16
  super.tap do |filter|
17
- filter.permit :environment_id, :environment_name, :environment,
18
- config_groups: [], config_group_ids: [], config_group_names: [],
19
- puppetclasses: [], puppetclass_ids: [], puppetclass_names: []
20
-
21
- # TODO: bring to core - this is what facets should do, but does not
22
- filter.permit(puppet_attributes: {})
17
+ add_host_puppet_params_filter(filter)
23
18
  end
24
19
  end
25
20
  end
@@ -27,40 +22,54 @@ module ForemanPuppet
27
22
  module PatchedMethods
28
23
  def host_params(*attrs)
29
24
  params = super(*attrs)
30
-
31
- process_deprecated_environment_params!(params)
32
- process_deprecated_attributes!(params)
25
+ process_deprecated_puppet_params!(params)
33
26
  params
34
27
  end
28
+ end
35
29
 
36
- def process_deprecated_environment_params!(params)
37
- env_id = params.delete(:environment_id)
38
- env_name = params.delete(:environment_name)
39
- env = params.delete(:environment)
40
-
41
- return unless env_id || env_name || env
42
- ::Foreman::Deprecation.api_deprecation_warning('param host[environment_*] has been deprecated in favor of host[puppet_attributes][environment_*]')
30
+ class_methods do
31
+ def add_host_puppet_params_filter(filter)
32
+ filter.permit :environment_id, :environment_name, :environment,
33
+ config_groups: [], config_group_ids: [], config_group_names: [],
34
+ puppetclasses: [], puppetclass_ids: [], puppetclass_names: []
43
35
 
44
- params[:puppet_attributes] ||= {}
45
- params[:puppet_attributes][:environment_id] ||= env_id if env_id
46
- params[:puppet_attributes][:environment_name] ||= env_name if env_name
47
- params[:puppet_attributes][:environment] ||= env if env
36
+ # TODO: bring to core - this is what facets should do, but does not
37
+ filter.permit(puppet_attributes: {})
48
38
  end
39
+ end
40
+
41
+ def process_deprecated_puppet_params!(params, top_level_hash = controller_name.singularize)
42
+ process_deprecated_environment_params!(params, top_level_hash)
43
+ process_deprecated_attributes!(params, top_level_hash)
44
+ end
49
45
 
50
- def process_deprecated_attributes!(params)
51
- %w[puppetclass config_group].each do |relation|
52
- ids = params.delete("#{relation}_ids".to_sym)
53
- names = params.delete("#{relation}_names".to_sym)
54
- plains = params.delete(relation.pluralize.to_sym)
46
+ def process_deprecated_environment_params!(params, top_level_hash = 'host')
47
+ env_id = params.delete(:environment_id)
48
+ env_name = params.delete(:environment_name)
49
+ env = params.delete(:environment)
55
50
 
56
- next unless ids || names || plains
57
- ::Foreman::Deprecation.api_deprecation_warning("param host[#{relation}_*] has been deprecated in favor of host[puppet_attributes][#{relation}_*]")
51
+ return unless env_id || env_name || env
52
+ ::Foreman::Deprecation.api_deprecation_warning("param #{top_level_hash}[environment_*] has been deprecated in favor of #{top_level_hash}[puppet_attributes][environment_*]")
58
53
 
59
- params[:puppet_attributes] ||= {}
60
- params[:puppet_attributes]["#{relation}_ids".to_sym] ||= ids if ids
61
- params[:puppet_attributes]["#{relation}_names".to_sym] ||= names if names
62
- params[:puppet_attributes][relation.pluralize.to_sym] ||= plains if plains
63
- end
54
+ params[:puppet_attributes] ||= {}
55
+ params[:puppet_attributes][:environment_id] ||= env_id if env_id
56
+ params[:puppet_attributes][:environment_name] ||= env_name if env_name
57
+ params[:puppet_attributes][:environment] ||= env if env
58
+ end
59
+
60
+ def process_deprecated_attributes!(params, top_level_hash = 'host')
61
+ %w[puppetclass config_group].each do |relation|
62
+ ids = params.delete("#{relation}_ids".to_sym)
63
+ names = params.delete("#{relation}_names".to_sym)
64
+ plains = params.delete(relation.pluralize.to_sym)
65
+
66
+ next unless ids || names || plains
67
+ ::Foreman::Deprecation.api_deprecation_warning("param #{top_level_hash}[#{relation}_*] has been deprecated in favor of #{top_level_hash}[puppet_attributes][#{relation}_*]")
68
+
69
+ params[:puppet_attributes] ||= {}
70
+ params[:puppet_attributes]["#{relation}_ids".to_sym] ||= ids if ids
71
+ params[:puppet_attributes]["#{relation}_names".to_sym] ||= names if names
72
+ params[:puppet_attributes][relation.pluralize.to_sym] ||= plains if plains
64
73
  end
65
74
  end
66
75
  end
@@ -14,12 +14,7 @@ module ForemanPuppet
14
14
  module PatchedClassMethods
15
15
  def hostgroup_params_filter
16
16
  super.tap do |filter|
17
- filter.permit :environment_id, :environment_name,
18
- config_group_ids: [], config_group_names: [],
19
- puppetclass_ids: [], puppetclass_names: []
20
-
21
- # TODO: bring to core - this is what facets should do, but does not
22
- filter.permit(puppet_attributes: {})
17
+ add_hostgroup_puppet_params_filter(filter)
23
18
  end
24
19
  end
25
20
  end
@@ -27,42 +22,56 @@ module ForemanPuppet
27
22
  module PatchedMethods
28
23
  def hostgroup_params(*attrs)
29
24
  params = super(*attrs)
30
-
31
- process_deprecated_hostgroup_environment_params!(params)
32
- process_deprecated_hostgroup_attributes!(params)
25
+ process_deprecated_hostgroup_puppet_params!(params)
33
26
  params
34
27
  end
28
+ end
35
29
 
36
- def process_deprecated_hostgroup_environment_params!(params)
37
- env_id = env_name = nil
38
- if ForemanPuppet.extracted_from_core?
39
- env_id = params.delete(:environment_id)
40
- env_name = params.delete(:environment_name)
41
- else
42
- env_id = params[:environment_id]
43
- env_name = params[:environment_name]
44
- end
30
+ class_methods do
31
+ def add_hostgroup_puppet_params_filter(filter)
32
+ filter.permit :environment_id, :environment_name,
33
+ config_group_ids: [], config_group_names: [],
34
+ puppetclass_ids: [], puppetclass_names: []
45
35
 
46
- return unless env_id || env_name
47
- ::Foreman::Deprecation.api_deprecation_warning('param hostgroup[environment_*] has been deprecated in favor of hostgroup[puppet_attributes][environment_*]')
36
+ # TODO: bring to core - this is what facets should do, but does not
37
+ filter.permit(puppet_attributes: {})
38
+ end
39
+ end
48
40
 
49
- params[:puppet_attributes] ||= {}
50
- params[:puppet_attributes][:environment_id] ||= env_id if env_id
51
- params[:puppet_attributes][:environment_name] ||= env_name if env_name
41
+ def process_deprecated_hostgroup_puppet_params!(params, top_level_hash = 'hostgroup')
42
+ process_deprecated_hostgroup_environment_params!(params, top_level_hash)
43
+ process_deprecated_hostgroup_attributes!(params, top_level_hash)
44
+ end
45
+
46
+ def process_deprecated_hostgroup_environment_params!(params, top_level_hash = 'hostgroup')
47
+ env_id = env_name = nil
48
+ if ForemanPuppet.extracted_from_core?
49
+ env_id = params.delete(:environment_id)
50
+ env_name = params.delete(:environment_name)
51
+ else
52
+ env_id = params[:environment_id]
53
+ env_name = params[:environment_name]
52
54
  end
53
55
 
54
- def process_deprecated_hostgroup_attributes!(params)
55
- %w[puppetclass config_group].each do |relation|
56
- ids = params.delete("#{relation}_ids")
57
- names = params.delete("#{relation}_names")
56
+ return unless env_id || env_name
57
+ ::Foreman::Deprecation.api_deprecation_warning("param #{top_level_hash}[environment_*] has been deprecated in favor of #{top_level_hash}[puppet_attributes][environment_*]")
58
58
 
59
- next unless ids || names
60
- ::Foreman::Deprecation.api_deprecation_warning("param hostgroup[#{relation}_*] has been deprecated in favor of hostgroup[puppet_attributes][#{relation}_*]")
59
+ params[:puppet_attributes] ||= {}
60
+ params[:puppet_attributes][:environment_id] ||= env_id if env_id
61
+ params[:puppet_attributes][:environment_name] ||= env_name if env_name
62
+ end
61
63
 
62
- params[:puppet_attributes] ||= {}
63
- params[:puppet_attributes]["#{relation}_ids".to_sym] ||= ids if ids
64
- params[:puppet_attributes]["#{relation}_names".to_sym] ||= names if names
65
- end
64
+ def process_deprecated_hostgroup_attributes!(params, top_level_hash = 'hostgroup')
65
+ %w[puppetclass config_group].each do |relation|
66
+ ids = params.delete("#{relation}_ids")
67
+ names = params.delete("#{relation}_names")
68
+
69
+ next unless ids || names
70
+ ::Foreman::Deprecation.api_deprecation_warning("param #{top_level_hash}[#{relation}_*] has been deprecated in favor of #{top_level_hash}[puppet_attributes][#{relation}_*]")
71
+
72
+ params[:puppet_attributes] ||= {}
73
+ params[:puppet_attributes]["#{relation}_ids".to_sym] ||= ids if ids
74
+ params[:puppet_attributes]["#{relation}_names".to_sym] ||= names if names
66
75
  end
67
76
  end
68
77
  end
@@ -0,0 +1,17 @@
1
+ module ForemanPuppet
2
+ module Extensions
3
+ module HostCounter
4
+ extend ActiveSupport::Concern
5
+
6
+ def counted_hosts
7
+ case @association.to_s
8
+ when 'environment'
9
+ hosts_scope = ::Host::Managed.reorder('').joins(:puppet)
10
+ hosts_scope.authorized(:view_hosts).group(HostPuppetFacet.arel_table[:environment_id]).count
11
+ else
12
+ super
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -79,6 +79,8 @@ module ForemanPuppet
79
79
  ::TemplateCombination.include ForemanPuppet::Extensions::TemplateCombination
80
80
  ::ProvisioningTemplate.include ForemanPuppet::Extensions::ProvisioningTemplate
81
81
 
82
+ ::HostCounter.prepend ForemanPuppet::Extensions::HostCounter
83
+
82
84
  ::Api::V2::BaseController.include ForemanPuppet::Extensions::ApiBaseController
83
85
  ::Api::V2::HostsController.include ForemanPuppet::Extensions::ApiV2HostsController
84
86
  ::Api::V2::HostgroupsController.include ForemanPuppet::Extensions::ApiHostgroupsController
@@ -1,3 +1,3 @@
1
1
  module ForemanPuppet
2
- VERSION = '1.0.3'.freeze
2
+ VERSION = '1.0.4'.freeze
3
3
  end
@@ -0,0 +1,17 @@
1
+ require 'test_puppet_helper'
2
+
3
+ module ForemanPuppet
4
+ class HostCounterTest < ActiveSupport::TestCase
5
+ def hosts_count(association)
6
+ ::HostCounter.new(association)
7
+ end
8
+
9
+ let(:environment) { FactoryBot.create(:environment) }
10
+
11
+ test 'it should get number of hosts associated to environment' do
12
+ FactoryBot.create(:host, :with_puppet_enc, environment: environment)
13
+ count = hosts_count(:environment)
14
+ assert_equal 1, count[environment]
15
+ end
16
+ end
17
+ end
@@ -7,11 +7,11 @@ import { foremanUrl, getManualURL } from 'foremanReact/common/helpers';
7
7
  export const WelcomeEnv = ({ canCreate }) => {
8
8
  const action = canCreate && {
9
9
  title: __('Create Puppet Environment'),
10
- url: foremanUrl('environments/new'),
10
+ url: foremanUrl('/foreman_puppet/environments/new'),
11
11
  };
12
12
 
13
13
  const content = __(`If you are planning to use Foreman as an external node classifier you should provide information about one or more environments.<br/>
14
- This information is commonly imported from a pre-existing Puppet configuration by the use of the <a href=${getManualURL(
14
+ This information is commonly imported from a pre-existing Puppet configuration by the use of the <a target="_blank" href=${getManualURL(
15
15
  '4.2.2Classes'
16
16
  )}>Puppet classes and environment importer.</a>`);
17
17
  return (
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_puppet
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ondřej Ezr
8
8
  - Shira Maximov
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-09-17 00:00:00.000000000 Z
12
+ date: 2021-10-27 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Allow assigning Puppet environmets and classes to the Foreman Hosts.
15
15
  email:
@@ -94,6 +94,7 @@ files:
94
94
  - app/models/foreman_puppet/puppetclass.rb
95
95
  - app/models/foreman_puppet/puppetclass_lookup_key.rb
96
96
  - app/prepend_views/api/v2/template_combinations/base.json.rabl
97
+ - app/services/concerns/foreman_puppet/extensions/host_counter.rb
97
98
  - app/services/foreman_puppet/host_info_providers/config_groups_info.rb
98
99
  - app/services/foreman_puppet/host_info_providers/puppet_info.rb
99
100
  - app/services/foreman_puppet/input_type/puppet_parameter_input.rb
@@ -263,6 +264,7 @@ files:
263
264
  - test/models/foreman_puppet/report_test.rb
264
265
  - test/models/foreman_puppet/smart_proxy_test.rb
265
266
  - test/models/foreman_puppet/user_test.rb
267
+ - test/services/foreman_puppet/host_counter_test.rb
266
268
  - test/services/foreman_puppet/host_info_providers/config_groups_info_test.rb
267
269
  - test/services/foreman_puppet/host_info_providers/puppet_info_test.rb
268
270
  - test/services/foreman_puppet/input_type/puppet_parameter_input_test.rb
@@ -296,7 +298,7 @@ homepage: https://github.com/theforeman/foreman_puppet
296
298
  licenses:
297
299
  - GPL-3.0
298
300
  metadata: {}
299
- post_install_message:
301
+ post_install_message:
300
302
  rdoc_options: []
301
303
  require_paths:
302
304
  - lib
@@ -312,13 +314,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
312
314
  version: '0'
313
315
  requirements: []
314
316
  rubygems_version: 3.1.6
315
- signing_key:
317
+ signing_key:
316
318
  specification_version: 4
317
319
  summary: Adds puppet ENC features
318
320
  test_files:
319
321
  - test/services/foreman_puppet/host_info_providers/config_groups_info_test.rb
320
322
  - test/services/foreman_puppet/host_info_providers/puppet_info_test.rb
321
323
  - test/services/foreman_puppet/input_type/puppet_parameter_input_test.rb
324
+ - test/services/foreman_puppet/host_counter_test.rb
322
325
  - test/integration/foreman_puppet/smartclass_parameter_js_test.rb
323
326
  - test/integration/foreman_puppet/puppetclass_js_test.rb
324
327
  - test/integration/foreman_puppet/hostgroup_js_test.rb