foreman_salt 14.0.0 → 14.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -2
  3. data/Rakefile +2 -2
  4. data/app/controllers/foreman_salt/api/v2/jobs_controller.rb +9 -9
  5. data/app/controllers/foreman_salt/api/v2/salt_autosign_controller.rb +15 -14
  6. data/app/controllers/foreman_salt/api/v2/salt_environments_controller.rb +6 -6
  7. data/app/controllers/foreman_salt/api/v2/salt_hostgroups_controller.rb +42 -0
  8. data/app/controllers/foreman_salt/api/v2/salt_keys_controller.rb +14 -14
  9. data/app/controllers/foreman_salt/api/v2/salt_minions_controller.rb +8 -8
  10. data/app/controllers/foreman_salt/api/v2/salt_states_controller.rb +24 -26
  11. data/app/controllers/foreman_salt/api/v2/salt_variables_controller.rb +22 -21
  12. data/app/controllers/foreman_salt/concerns/hostgroups_controller_extensions.rb +3 -3
  13. data/app/controllers/foreman_salt/concerns/hosts_controller_extensions.rb +4 -4
  14. data/app/controllers/foreman_salt/concerns/salt_environment_parameters.rb +1 -1
  15. data/app/controllers/foreman_salt/concerns/salt_hostgroup_parameters.rb +25 -0
  16. data/app/controllers/foreman_salt/concerns/salt_module_parameters.rb +1 -1
  17. data/app/controllers/foreman_salt/concerns/salt_override_value.rb +4 -4
  18. data/app/controllers/foreman_salt/concerns/salt_variable_parameters.rb +5 -5
  19. data/app/controllers/foreman_salt/minions_controller.rb +9 -9
  20. data/app/controllers/foreman_salt/salt_autosign_controller.rb +8 -8
  21. data/app/controllers/foreman_salt/salt_environments_controller.rb +4 -4
  22. data/app/controllers/foreman_salt/salt_keys_controller.rb +11 -11
  23. data/app/controllers/foreman_salt/salt_modules_controller.rb +10 -11
  24. data/app/controllers/foreman_salt/salt_variables_controller.rb +5 -4
  25. data/app/controllers/foreman_salt/state_importer.rb +12 -13
  26. data/app/helpers/concerns/foreman_salt/hosts_helper_extensions.rb +16 -10
  27. data/app/helpers/concerns/foreman_salt/smart_proxies_helper_extensions.rb +2 -2
  28. data/app/helpers/foreman_salt/salt_keys_helper.rb +2 -1
  29. data/app/helpers/foreman_salt/salt_modules_helper.rb +11 -11
  30. data/app/helpers/foreman_salt/salt_reports_helper.rb +0 -1
  31. data/app/lib/actions/foreman_salt/report_import.rb +2 -2
  32. data/app/lib/proxy_api/salt.rb +17 -17
  33. data/app/models/foreman_salt/concerns/host_managed_extensions.rb +47 -46
  34. data/app/models/foreman_salt/concerns/hostgroup_extensions.rb +14 -11
  35. data/app/models/foreman_salt/host_salt_module.rb +1 -1
  36. data/app/models/foreman_salt/salt_environment.rb +8 -8
  37. data/app/models/foreman_salt/salt_module.rb +15 -13
  38. data/app/models/foreman_salt/salt_module_environment.rb +1 -1
  39. data/app/models/foreman_salt/salt_provider.rb +7 -4
  40. data/app/models/foreman_salt/salt_variable.rb +8 -8
  41. data/app/models/setting/salt.rb +12 -10
  42. data/app/overrides/salt_environment_host_selector.rb +4 -4
  43. data/app/overrides/salt_environment_hostgroup_selector.rb +4 -4
  44. data/app/overrides/salt_modules_selector.rb +16 -16
  45. data/app/overrides/salt_proxy_selector.rb +11 -9
  46. data/app/services/foreman_salt/report_importer.rb +26 -26
  47. data/app/services/foreman_salt/smart_proxies/salt_keys.rb +47 -45
  48. data/app/views/foreman_salt/api/v2/salt_autosign/create.json.rabl +1 -1
  49. data/app/views/foreman_salt/api/v2/salt_environments/create.json.rabl +1 -1
  50. data/app/views/foreman_salt/api/v2/salt_environments/show.json.rabl +1 -1
  51. data/app/views/foreman_salt/api/v2/salt_hostgroups/base.json.rabl +7 -0
  52. data/app/views/foreman_salt/api/v2/salt_hostgroups/show.json.rabl +3 -0
  53. data/app/views/foreman_salt/api/v2/salt_hostgroups/update.json.rabl +3 -0
  54. data/app/views/foreman_salt/api/v2/salt_keys/update.json.rabl +1 -1
  55. data/app/views/foreman_salt/api/v2/salt_minions/show.json.rabl +3 -4
  56. data/app/views/foreman_salt/api/v2/salt_states/create.json.rabl +1 -1
  57. data/app/views/foreman_salt/api/v2/salt_states/show.json.rabl +0 -1
  58. data/app/views/foreman_salt/api/v2/salt_variables/create.json.rabl +1 -1
  59. data/app/views/foreman_salt/api/v2/salt_variables/destroy.json.rabl +1 -1
  60. data/app/views/foreman_salt/api/v2/salt_variables/show.json.rabl +8 -8
  61. data/config/api_routes.rb +31 -0
  62. data/config/routes.rb +16 -44
  63. data/db/migrate/20140817210214_create_salt_modules.rb +4 -4
  64. data/db/migrate/20140829210214_add_salt_modules_to_hostgroups.rb +1 -1
  65. data/db/migrate/20140920232200_create_salt_environments.rb +3 -3
  66. data/db/migrate/20150220122707_fix_incorrect_report_metrics.rb +6 -2
  67. data/db/migrate/20211108211312_add_missing_permissions.rb +9 -0
  68. data/db/seeds.d/75-salt_seeds.rb +1 -1
  69. data/db/seeds.d/76-job_templates.rb +3 -3
  70. data/lib/foreman_salt/engine.rb +24 -16
  71. data/lib/foreman_salt/extensions.rb +8 -8
  72. data/lib/foreman_salt/plugin.rb +120 -114
  73. data/lib/foreman_salt/version.rb +1 -1
  74. data/lib/foreman_salt.rb +1 -1
  75. data/lib/tasks/foreman_salt_tasks.rake +3 -5
  76. data/locale/action_names.rb +4 -4
  77. data/test/factories/foreman_salt_factories.rb +5 -5
  78. data/test/functional/api/v2/salt_autosign_controller_test.rb +26 -20
  79. data/test/functional/api/v2/salt_environments_controller_test.rb +29 -23
  80. data/test/functional/api/v2/salt_hostgroups_controller_test.rb +76 -0
  81. data/test/functional/api/v2/salt_keys_controller_test.rb +25 -19
  82. data/test/functional/api/v2/salt_states_controller_test.rb +72 -66
  83. data/test/functional/api/v2/salt_variables_controller_test.rb +4 -4
  84. data/test/functional/hosts_controller_test.rb +26 -26
  85. data/test/functional/minions_controller_test.rb +22 -22
  86. data/test/functional/salt_modules_controller_test.rb +3 -3
  87. data/test/functional/salt_variables_controller_test.rb +5 -5
  88. data/test/integration/hosts_js_test.rb +11 -11
  89. data/test/integration/salt_autosign_test.rb +5 -5
  90. data/test/integration/salt_environment_test.rb +2 -2
  91. data/test/integration/salt_keys_test.rb +7 -7
  92. data/test/integration/salt_module_test.rb +9 -9
  93. data/test/integration/salt_variable_test.rb +2 -2
  94. data/test/test_plugin_helper.rb +1 -1
  95. data/test/unit/grains_importer_test.rb +12 -12
  96. data/test/unit/host_extensions_test.rb +19 -19
  97. data/test/unit/hostgroup_extensions_test.rb +13 -13
  98. data/test/unit/report_importer_test.rb +9 -9
  99. data/test/unit/salt_keys_test.rb +2 -2
  100. data/test/unit/salt_modules_test.rb +2 -2
  101. data/test/unit/salt_variables_test.rb +10 -10
  102. metadata +22 -13
@@ -10,7 +10,7 @@ module ForemanSalt
10
10
 
11
11
  def params
12
12
  params = super
13
- params['salt_master'] = salt_master unless salt_master.blank?
13
+ params['salt_master'] = salt_master if salt_master.present?
14
14
  params
15
15
  end
16
16
 
@@ -23,31 +23,31 @@ module ForemanSalt
23
23
  end
24
24
 
25
25
  def inherited_attributes
26
- super + %w(salt_proxy_id salt_environment_id)
26
+ super + %w[salt_proxy_id salt_environment_id]
27
27
  end
28
28
  end
29
29
 
30
30
  included do
31
- has_many :host_salt_modules, :foreign_key => :host_id, :class_name => '::ForemanSalt::HostSaltModule'
32
- has_many :salt_modules, :through => :host_salt_modules, :class_name => '::ForemanSalt::SaltModule'
31
+ has_many :host_salt_modules, foreign_key: :host_id, class_name: '::ForemanSalt::HostSaltModule'
32
+ has_many :salt_modules, through: :host_salt_modules, class_name: '::ForemanSalt::SaltModule'
33
33
 
34
- belongs_to :salt_proxy, :class_name => 'SmartProxy'
35
- belongs_to :salt_environment, :class_name => 'ForemanSalt::SaltEnvironment'
34
+ belongs_to :salt_proxy, class_name: 'SmartProxy'
35
+ belongs_to :salt_environment, class_name: 'ForemanSalt::SaltEnvironment'
36
36
 
37
37
  prepend Overrides
38
38
 
39
- scoped_search :relation => :salt_modules, :on => :name, :complete_value => true, :rename => :salt_state
40
- scoped_search :relation => :salt_environment, :on => :name, :complete_value => true, :rename => :salt_environment
41
- scoped_search :relation => :salt_proxy, :on => :name, :complete_value => true, :rename => :saltmaster
39
+ scoped_search relation: :salt_modules, on: :name, complete_value: true, rename: :salt_state
40
+ scoped_search relation: :salt_environment, on: :name, complete_value: true, rename: :salt_environment
41
+ scoped_search relation: :salt_proxy, on: :name, complete_value: true, rename: :saltmaster
42
42
 
43
43
  validate :salt_modules_in_host_environment
44
44
 
45
- after_build :ensure_salt_autosign, :if => ->(host) { host.salt_proxy }
46
- before_destroy :remove_salt_minion, :if => ->(host) { host.salt_proxy }
45
+ after_build :ensure_salt_autosign, if: ->(host) { host.salt_proxy }
46
+ before_destroy :remove_salt_minion, if: ->(host) { host.salt_proxy }
47
47
  end
48
48
 
49
49
  def salt_params
50
- variables = ForemanSalt::SaltVariable.where(:salt_module_id => all_salt_modules.pluck(:id), :override => true)
50
+ variables = ForemanSalt::SaltVariable.where(salt_module_id: all_salt_modules.pluck(:id), override: true)
51
51
  values = variables.values_hash(self)
52
52
 
53
53
  variables.each_with_object({}) do |var, memo|
@@ -58,11 +58,11 @@ module ForemanSalt
58
58
  end
59
59
 
60
60
  def host_params_grains_name
61
- "salt_grains"
61
+ 'salt_grains'
62
62
  end
63
63
 
64
64
  def autosign_grain_name
65
- "autosign_key"
65
+ 'autosign_key'
66
66
  end
67
67
 
68
68
  def salt_modules_for_enc
@@ -73,7 +73,7 @@ module ForemanSalt
73
73
  return [] unless salt_environment
74
74
 
75
75
  modules = salt_modules + (hostgroup ? hostgroup.all_salt_modules : [])
76
- ForemanSalt::SaltModule.in_environment(salt_environment).where(:id => modules)
76
+ ForemanSalt::SaltModule.in_environment(salt_environment).where(id: modules)
77
77
  end
78
78
 
79
79
  def salt_master
@@ -81,22 +81,22 @@ module ForemanSalt
81
81
  end
82
82
 
83
83
  def saltrun!
84
- unless salt_proxy.present?
84
+ if salt_proxy.blank?
85
85
  errors.add(:base, _("No Salt master defined - can't continue"))
86
86
  logger.warn 'Unable to execute salt run, no salt proxies defined'
87
87
  return false
88
88
  end
89
- ProxyAPI::Salt.new(:url => salt_proxy.url).highstate name
90
- rescue => e
89
+ ProxyAPI::Salt.new(url: salt_proxy.url).highstate name
90
+ rescue StandardError => e
91
91
  errors.add(:base, _('Failed to execute state.highstate: %s') % e)
92
92
  false
93
93
  end
94
94
 
95
95
  def salt_modules_in_host_environment
96
- return unless self.salt_modules.any?
96
+ return unless salt_modules.any?
97
97
 
98
- if self.salt_environment
99
- errors.add(:base, _('Salt states must be in the environment of the host')) unless (self.salt_modules - self.salt_environment.salt_modules).empty?
98
+ if salt_environment
99
+ errors.add(:base, _('Salt states must be in the environment of the host')) unless (salt_modules - salt_environment.salt_modules).empty?
100
100
  else
101
101
  errors.add(:base, _('Host must have an environment in order to set salt states'))
102
102
  end
@@ -105,10 +105,10 @@ module ForemanSalt
105
105
  def derive_salt_grains(use_autosign: False)
106
106
  grains = {}
107
107
  begin
108
- Rails.logger.info("Derive Salt Grains from host_params and autosign_key")
108
+ Rails.logger.info('Derive Salt Grains from host_params and autosign_key')
109
109
  grains[autosign_grain_name] = salt_autosign_key if use_autosign && !salt_autosign_key.nil?
110
110
  unless host_params[host_params_grains_name].nil? ||
111
- host_params[host_params_grains_name].class != Hash
111
+ host_params[host_params_grains_name].class != Hash
112
112
  grains.merge!(host_params[host_params_grains_name])
113
113
  end
114
114
  rescue Foreman::Exception => e
@@ -131,43 +131,44 @@ module ForemanSalt
131
131
 
132
132
  def remove_salt_key
133
133
  Rails.logger.info("Remove salt key for host #{fqdn}")
134
- api = ProxyAPI::Salt.new(:url => salt_proxy.url)
134
+ api = ProxyAPI::Salt.new(url: salt_proxy.url)
135
135
  api.key_delete(name)
136
136
  end
137
137
 
138
138
  def remove_salt_autosign
139
- key = self.salt_autosign_key
140
- unless key.nil?
141
- Rails.logger.info("Remove salt autosign key for host #{fqdn}")
142
- begin
143
- api = ProxyAPI::Salt.new(:url => salt_proxy.url)
144
- api.autosign_remove_key(key)
145
- rescue Foreman::Exception => e
146
- Rails.logger.warn("Unable to remove salt autosign for #{fqdn}: #{e}")
147
- end
139
+ key = salt_autosign_key
140
+ return if key.nil?
141
+ Rails.logger.info("Remove salt autosign key for host #{fqdn}")
142
+ begin
143
+ api = ProxyAPI::Salt.new(url: salt_proxy.url)
144
+ api.autosign_remove_key(key)
145
+ rescue Foreman::Exception => e
146
+ Rails.logger.warn("Unable to remove salt autosign for #{fqdn}: #{e}")
148
147
  end
149
148
  end
150
149
 
151
150
  def generate_provisioning_key
152
- SecureRandom.hex(10)
151
+ SecureRandom.hex(10)
153
152
  end
154
153
 
155
154
  def create_salt_autosign
156
- begin
157
- Rails.logger.info("Create salt autosign key for host #{fqdn}")
158
- api = ProxyAPI::Salt.new(:url => salt_proxy.url)
159
- key = generate_provisioning_key
160
- api.autosign_create_key(key)
161
- update(:salt_autosign_key => key)
162
- update(:salt_status => ForemanSalt::SaltStatus.minion_auth_waiting)
163
- rescue Foreman::Exception => e
164
- Rails.logger.warn("Unable to create salt autosign for #{fqdn}: #{e}")
165
- end
155
+ Rails.logger.info("Create salt autosign key for host #{fqdn}")
156
+ api = ProxyAPI::Salt.new(url: salt_proxy.url)
157
+ key = generate_provisioning_key
158
+ api.autosign_create_key(key)
159
+ update(salt_autosign_key: key)
160
+ update(salt_status: ForemanSalt::SaltStatus.minion_auth_waiting)
161
+ rescue Foreman::Exception => e
162
+ Rails.logger.warn("Unable to create salt autosign for #{fqdn}: #{e}")
166
163
  end
167
164
  end
168
165
  end
169
166
  end
170
167
 
171
- class ::Host::Managed::Jail < Safemode::Jail
172
- allow :salt_environment, :salt_master, :derive_salt_grains
168
+ # rubocop:disable Style/ClassAndModuleChildren
169
+ class Host::Managed
170
+ class Jail < ::Safemode::Jail
171
+ allow :salt_environment, :salt_master, :derive_salt_grains
172
+ end
173
173
  end
174
+ # rubocop:enable Style/ClassAndModuleChildren
@@ -4,23 +4,26 @@ module ForemanSalt
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
- has_many :hostgroup_salt_modules, :class_name => '::ForemanSalt::HostgroupSaltModule'
8
- has_many :salt_modules, :through => :hostgroup_salt_modules, :class_name => '::ForemanSalt::SaltModule'
7
+ has_many :hostgroup_salt_modules, class_name: '::ForemanSalt::HostgroupSaltModule'
8
+ has_many :salt_modules, through: :hostgroup_salt_modules, class_name: '::ForemanSalt::SaltModule'
9
9
 
10
- belongs_to :salt_proxy, :class_name => 'SmartProxy'
11
- belongs_to :salt_environment, :class_name => 'ForemanSalt::SaltEnvironment'
10
+ belongs_to :salt_proxy, class_name: 'SmartProxy'
11
+ belongs_to :salt_environment, class_name: 'ForemanSalt::SaltEnvironment'
12
12
 
13
- scoped_search :relation => :salt_modules, :on => :name, :complete_value => true, :rename => :salt_state
14
- scoped_search :relation => :salt_environment, :on => :name, :complete_value => true, :rename => :salt_environment
15
- scoped_search :relation => :salt_proxy, :on => :name, :complete_value => true, :rename => :saltmaster
13
+ scoped_search relation: :salt_modules, on: :name, complete_value: true, rename: :salt_state
14
+ scoped_search relation: :salt_environment, on: :name, complete_value: true, rename: :salt_environment
15
+ scoped_search relation: :salt_proxy, on: :name, complete_value: true, rename: :saltmaster
16
+
17
+ validates :salt_proxy, presence: true, unless: -> { salt_proxy_id.blank? }
18
+ validates :salt_environment, presence: true, unless: -> { salt_environment_id.blank? }
16
19
  end
17
20
 
18
21
  def all_salt_modules
19
- ForemanSalt::SaltModule.in_environment(salt_environment).where(:id => salt_module_ids + inherited_salt_module_ids)
22
+ ForemanSalt::SaltModule.in_environment(salt_environment).where(id: salt_module_ids + inherited_salt_module_ids)
20
23
  end
21
24
 
22
25
  def inherited_salt_modules
23
- ForemanSalt::SaltModule.where(:id => inherited_salt_module_ids)
26
+ ForemanSalt::SaltModule.where(id: inherited_salt_module_ids)
24
27
  end
25
28
 
26
29
  def inherited_salt_module_ids
@@ -29,7 +32,7 @@ module ForemanSalt
29
32
 
30
33
  def salt_proxy
31
34
  if ancestry.present?
32
- SmartProxy.with_features('Salt').find_by_id(inherited_salt_proxy_id)
35
+ SmartProxy.with_features('Salt').find_by(id: inherited_salt_proxy_id)
33
36
  else
34
37
  super
35
38
  end
@@ -41,7 +44,7 @@ module ForemanSalt
41
44
 
42
45
  def salt_environment
43
46
  if ancestry.present?
44
- ForemanSalt::SaltEnvironment.find_by_id(inherited_salt_environment_id)
47
+ ForemanSalt::SaltEnvironment.find_by(id: inherited_salt_environment_id)
45
48
  else
46
49
  super
47
50
  end
@@ -1,6 +1,6 @@
1
1
  module ForemanSalt
2
2
  class HostSaltModule < ApplicationRecord
3
- belongs_to :host, :class_name => 'Host::Managed', :foreign_key => :host_id
3
+ belongs_to :host, class_name: 'Host::Managed'
4
4
  belongs_to :salt_module
5
5
  end
6
6
  end
@@ -5,17 +5,17 @@ module ForemanSalt
5
5
  friendly_id :name
6
6
  include Parameterizable::ByIdName
7
7
 
8
- has_many :hosts, :class_name => '::Host::Managed'
9
- has_many :hostgroups, :class_name => '::Hostgroup'
8
+ has_many :hosts, class_name: '::Host::Managed'
9
+ has_many :hostgroups, class_name: '::Hostgroup'
10
10
 
11
11
  has_many :salt_module_environments
12
- has_many :salt_modules, :through => :salt_module_environments, :before_remove => :remove_from_hosts
12
+ has_many :salt_modules, through: :salt_module_environments, before_remove: :remove_from_hosts
13
13
 
14
- validates :name, :uniqueness => true, :presence => true, :format => { :with => /\A[\w\d\.]+\z/, :message => N_('is alphanumeric and cannot contain spaces') }
14
+ validates :name, uniqueness: true, presence: true, format: { with: /\A[\w\d.]+\z/, message: N_('is alphanumeric and cannot contain spaces') }
15
15
 
16
- scoped_search :on => :name, :complete_value => true
17
- scoped_search :relation => :hostgroups, :on => :name, :complete_value => true, :rename => :hostgroup
18
- scoped_search :relation => :hosts, :on => :name, :complete_value => true, :rename => :host
16
+ scoped_search on: :name, complete_value: true
17
+ scoped_search relation: :hostgroups, on: :name, complete_value: true, rename: :hostgroup
18
+ scoped_search relation: :hosts, on: :name, complete_value: true, rename: :host
19
19
 
20
20
  def self.humanize_class_name(_name = nil)
21
21
  _('Salt environment')
@@ -28,7 +28,7 @@ module ForemanSalt
28
28
  private
29
29
 
30
30
  def remove_from_hosts(state)
31
- HostSaltModule.joins(:host).where(:hosts => { :salt_environment_id => id }, :salt_module_id => state).destroy
31
+ HostSaltModule.joins(:host).where(hosts: { salt_environment_id: id }, salt_module_id: state).destroy
32
32
  end
33
33
  end
34
34
  end
@@ -7,19 +7,21 @@ module ForemanSalt
7
7
  friendly_id :name
8
8
  include Parameterizable::ByIdName
9
9
 
10
- has_many :host_salt_modules, :foreign_key => :salt_module_id
11
- has_many :hosts, :through => :host_salt_modules, :class_name => '::Host::Managed'
10
+ has_many :host_salt_modules
11
+ has_many :hosts, through: :host_salt_modules, class_name: '::Host::Managed'
12
12
 
13
- has_many :hostgroup_salt_modules, :foreign_key => :salt_module_id
14
- has_many :hostgroups, :through => :hostgroup_salt_modules
13
+ has_many :hostgroup_salt_modules
14
+ has_many :hostgroups, through: :hostgroup_salt_modules
15
15
 
16
- has_many :salt_variables, :inverse_of => :salt_module,
17
- :dependent => :destroy
16
+ has_many :salt_variables, inverse_of: :salt_module,
17
+ dependent: :destroy
18
18
 
19
19
  has_many :salt_module_environments
20
- has_many :salt_environments, :through => :salt_module_environments
20
+ has_many :salt_environments, through: :salt_module_environments
21
21
 
22
- validates :name, :uniqueness => true, :presence => true, :format => { :with => /\A(?:[\w\d\-]+\.{0,1})+[^\.]\z/, :message => N_('must be alphanumeric, can contain periods, dashes, underscores and must not contain spaces') }
22
+ validates :name, uniqueness: true, presence: true,
23
+ format: { with: /\A(?:[\w\d\-]+\.{0,1})+[^.]\z/,
24
+ message: N_('must be alphanumeric, can contain periods, dashes, underscores and must not contain spaces') }
23
25
 
24
26
  default_scope lambda {
25
27
  order('salt_modules.name')
@@ -27,15 +29,15 @@ module ForemanSalt
27
29
 
28
30
  scope :in_environment, ->(environment) { joins(:salt_environments).where('salt_module_environments.salt_environment_id' => environment) }
29
31
 
30
- scoped_search :on => :name, :complete_value => true
31
- scoped_search :relation => :salt_environments, :on => :name, :complete_value => true, :rename => :environment
32
- scoped_search :relation => :hostgroups, :on => :name, :complete_value => true, :rename => :hostgroup
33
- scoped_search :relation => :hosts, :on => :name, :complete_value => true, :rename => :host
32
+ scoped_search on: :name, complete_value: true
33
+ scoped_search relation: :salt_environments, on: :name, complete_value: true, rename: :environment
34
+ scoped_search relation: :hostgroups, on: :name, complete_value: true, rename: :hostgroup
35
+ scoped_search relation: :hosts, on: :name, complete_value: true, rename: :host
34
36
 
35
37
  def self.to_hash
36
38
  states = {}
37
39
 
38
- SaltEnvironment.all.each do |environment|
40
+ SaltEnvironment.all.find_each do |environment|
39
41
  states[environment.name] = environment.salt_modules.map(&:name)
40
42
  end
41
43
 
@@ -8,7 +8,7 @@ module ForemanSalt
8
8
  private
9
9
 
10
10
  def remove_from_hosts
11
- HostSaltModule.joins(:host).where(:hosts => { :salt_environment_id => salt_environment_id }, :salt_module_id => salt_module_id).destroy
11
+ HostSaltModule.joins(:host).where(hosts: { salt_environment_id: salt_environment_id }, salt_module_id: salt_module_id).destroy
12
12
  end
13
13
  end
14
14
  end
@@ -14,14 +14,17 @@ module ForemanSalt
14
14
  end
15
15
 
16
16
  def proxy_command_options(template_invocation, host)
17
- super(template_invocation, host).merge(:name => host.name)
17
+ super(template_invocation, host).merge(name: host.name)
18
18
  end
19
19
 
20
- def ssh_password(_host); end
20
+ def ssh_password(_host)
21
+ end
21
22
 
22
- def ssh_key_passphrase(_host); end
23
+ def ssh_key_passphrase(_host)
24
+ end
23
25
 
24
- def sudo_password(_host); end
26
+ def sudo_password(_host)
27
+ end
25
28
  end
26
29
  end
27
30
  end
@@ -3,12 +3,12 @@
3
3
  module ForemanSalt
4
4
  # Represents the variables used in Salt
5
5
  class SaltVariable < LookupKey
6
- belongs_to :salt_module, :inverse_of => :salt_variables
7
- validates :salt_module_id, :presence => true
8
- before_validation :cast_default_value, :if => :override?
9
- scoped_search :on => :key, :aliases => [:name], :complete_value => true
10
- scoped_search :relation => :salt_module, :on => :name,
11
- :complete_value => true, :rename => :salt_module
6
+ belongs_to :salt_module, inverse_of: :salt_variables
7
+ validates :salt_module_id, presence: true
8
+ before_validation :cast_default_value, if: :override?
9
+ scoped_search on: :key, aliases: [:name], complete_value: true
10
+ scoped_search relation: :salt_module, on: :name,
11
+ complete_value: true, rename: :salt_module
12
12
 
13
13
  def salt?
14
14
  true
@@ -18,12 +18,12 @@ module ForemanSalt
18
18
  if options.present?
19
19
  super
20
20
  else
21
- "Salt variable"
21
+ 'Salt variable'
22
22
  end
23
23
  end
24
24
 
25
25
  def editable_by_user?
26
- SaltVariable.authorized(:edit_external_parameters).where(:id => id).exists?
26
+ SaltVariable.authorized(:edit_external_parameters).exists?(id: id)
27
27
  end
28
28
  end
29
29
  end
@@ -1,13 +1,15 @@
1
- class Setting::Salt < Setting
2
- def self.default_settings
3
- [
4
- set('salt_namespace_pillars', N_("Namespace Foreman pillars under 'foreman' key"), false),
5
- set('salt_hide_run_salt_button', N_("Hide the Run Salt state.highstate button on the host details page"), false)
6
- ]
7
- end
1
+ class Setting
2
+ class Salt < ::Setting
3
+ def self.default_settings
4
+ [
5
+ set('salt_namespace_pillars', N_("Namespace Foreman pillars under 'foreman' key"), false),
6
+ set('salt_hide_run_salt_button', N_('Hide the Run Salt state.highstate button on the host details page'), false),
7
+ ]
8
+ end
8
9
 
9
- def self.load_defaults
10
- super
11
- Setting['salt_hide_run_salt_button'] = true if ForemanSalt.with_remote_execution?
10
+ def self.load_defaults
11
+ super
12
+ Setting['salt_hide_run_salt_button'] = true if ForemanSalt.with_remote_execution?
13
+ end
12
14
  end
13
15
  end
@@ -7,8 +7,8 @@ selector_text = "<%= select_f f, :salt_environment_id, ForemanSalt::SaltEnvironm
7
7
  :help_inline => :indicator} %>"
8
8
 
9
9
  Deface::Override.new(
10
- :virtual_path => 'hosts/_form',
11
- :name => 'add_salt_environment_to_host',
12
- :insert_bottom => 'div#primary',
13
- :text => selector_text
10
+ virtual_path: 'hosts/_form',
11
+ name: 'add_salt_environment_to_host',
12
+ insert_bottom: 'div#primary',
13
+ text: selector_text
14
14
  )
@@ -5,8 +5,8 @@ selector_text = "<%= select_f f, :salt_environment_id, ForemanSalt::SaltEnvironm
5
5
  :'data-host-id' => (@host || @hostgroup).id, :help_inline => :indicator} %>"
6
6
 
7
7
  Deface::Override.new(
8
- :virtual_path => 'hostgroups/_form',
9
- :name => 'add_salt_environment_to_hostgroup',
10
- :insert_bottom => 'div#primary',
11
- :text => selector_text
8
+ virtual_path: 'hostgroups/_form',
9
+ name: 'add_salt_environment_to_hostgroup',
10
+ insert_bottom: 'div#primary',
11
+ text: selector_text
12
12
  )
@@ -1,19 +1,19 @@
1
- Deface::Override.new(:virtual_path => 'hosts/_form',
2
- :name => 'add_salt_modules_tab_to_host',
3
- :insert_after => 'li.active',
4
- :partial => 'foreman_salt/salt_modules/host_tab')
1
+ Deface::Override.new(virtual_path: 'hosts/_form',
2
+ name: 'add_salt_modules_tab_to_host',
3
+ insert_after: 'li.active',
4
+ partial: 'foreman_salt/salt_modules/host_tab')
5
5
 
6
- Deface::Override.new(:virtual_path => 'hosts/_form',
7
- :name => 'add_salt_modules_tab_pane_to_host',
8
- :insert_before => 'div#primary',
9
- :partial => 'foreman_salt/salt_modules/host_tab_pane')
6
+ Deface::Override.new(virtual_path: 'hosts/_form',
7
+ name: 'add_salt_modules_tab_pane_to_host',
8
+ insert_before: 'div#primary',
9
+ partial: 'foreman_salt/salt_modules/host_tab_pane')
10
10
 
11
- Deface::Override.new(:virtual_path => 'hostgroups/_form',
12
- :name => 'add_salt_modules_tab_to_hg',
13
- :insert_after => 'li.active',
14
- :partial => 'foreman_salt/salt_modules/host_tab')
11
+ Deface::Override.new(virtual_path: 'hostgroups/_form',
12
+ name: 'add_salt_modules_tab_to_hg',
13
+ insert_after: 'li.active',
14
+ partial: 'foreman_salt/salt_modules/host_tab')
15
15
 
16
- Deface::Override.new(:virtual_path => 'hostgroups/_form',
17
- :name => 'add_salt_modules_tab_pane_to_hg',
18
- :insert_before => 'div#primary',
19
- :partial => 'foreman_salt/salt_modules/host_tab_pane')
16
+ Deface::Override.new(virtual_path: 'hostgroups/_form',
17
+ name: 'add_salt_modules_tab_pane_to_hg',
18
+ insert_before: 'div#primary',
19
+ partial: 'foreman_salt/salt_modules/host_tab_pane')
@@ -1,17 +1,19 @@
1
- selector_text = "<%= select_f f, :salt_proxy_id, SmartProxy.unscoped.with_features('Salt').with_taxonomy_scope(@location,@organization, :path_ids), :id, :name,
1
+ selector_text = "<%= select_f f, :salt_proxy_id,
2
+ SmartProxy.unscoped.with_features('Salt').with_taxonomy_scope(@location,@organization, :path_ids),
3
+ :id, :name,
2
4
  { :include_blank => blank_or_inherit_f(f, :salt_proxy) },
3
5
  { :label => _('Salt Master') } %>"
4
6
 
5
7
  Deface::Override.new(
6
- :virtual_path => 'hosts/_form',
7
- :name => 'add_salt_proxy_to_host',
8
- :insert_bottom => 'div#primary',
9
- :text => selector_text
8
+ virtual_path: 'hosts/_form',
9
+ name: 'add_salt_proxy_to_host',
10
+ insert_bottom: 'div#primary',
11
+ text: selector_text
10
12
  )
11
13
 
12
14
  Deface::Override.new(
13
- :virtual_path => 'hostgroups/_form',
14
- :name => 'add_salt_proxy_to_hostgroup',
15
- :insert_bottom => 'div#primary',
16
- :text => selector_text
15
+ virtual_path: 'hostgroups/_form',
16
+ name: 'add_salt_proxy_to_hostgroup',
17
+ insert_bottom: 'div#primary',
18
+ text: selector_text
17
19
  )