foreman_salt 14.0.0 → 15.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) 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 -20
  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 +13 -21
  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 +46 -56
  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/overrides/salt_environment_host_selector.rb +4 -4
  42. data/app/overrides/salt_environment_hostgroup_selector.rb +4 -4
  43. data/app/overrides/salt_modules_selector.rb +16 -16
  44. data/app/overrides/salt_proxy_selector.rb +11 -9
  45. data/app/services/foreman_salt/report_importer.rb +30 -30
  46. data/app/services/foreman_salt/smart_proxies/salt_keys.rb +47 -45
  47. data/app/views/foreman_salt/api/v2/salt_autosign/create.json.rabl +1 -1
  48. data/app/views/foreman_salt/api/v2/salt_environments/create.json.rabl +1 -1
  49. data/app/views/foreman_salt/api/v2/salt_environments/show.json.rabl +1 -1
  50. data/app/views/foreman_salt/api/v2/salt_hostgroups/base.json.rabl +7 -0
  51. data/app/views/foreman_salt/api/v2/salt_hostgroups/show.json.rabl +3 -0
  52. data/app/views/foreman_salt/api/v2/salt_hostgroups/update.json.rabl +3 -0
  53. data/app/views/foreman_salt/api/v2/salt_keys/update.json.rabl +1 -1
  54. data/app/views/foreman_salt/api/v2/salt_minions/show.json.rabl +3 -4
  55. data/app/views/foreman_salt/api/v2/salt_states/create.json.rabl +1 -1
  56. data/app/views/foreman_salt/api/v2/salt_states/show.json.rabl +0 -1
  57. data/app/views/foreman_salt/api/v2/salt_variables/create.json.rabl +1 -1
  58. data/app/views/foreman_salt/api/v2/salt_variables/destroy.json.rabl +1 -1
  59. data/app/views/foreman_salt/api/v2/salt_variables/show.json.rabl +8 -8
  60. data/app/views/foreman_salt/salt_autosign/index.html.erb +1 -2
  61. data/app/views/foreman_salt/salt_environments/index.html.erb +1 -3
  62. data/app/views/foreman_salt/salt_keys/index.erb +1 -3
  63. data/app/views/foreman_salt/salt_modules/index.html.erb +1 -2
  64. data/config/api_routes.rb +31 -0
  65. data/config/routes.rb +16 -44
  66. data/db/migrate/20140817210214_create_salt_modules.rb +4 -4
  67. data/db/migrate/20140829210214_add_salt_modules_to_hostgroups.rb +1 -1
  68. data/db/migrate/20140920232200_create_salt_environments.rb +3 -3
  69. data/db/migrate/20150220122707_fix_incorrect_report_metrics.rb +6 -2
  70. data/db/migrate/20211108211312_add_missing_permissions.rb +9 -0
  71. data/db/migrate/20220118160349_drop_salt_hide_run_salt_button_setting.rb +5 -0
  72. data/db/migrate/20220406185204_fix_salt_setting_category_to_dsl.rb +5 -0
  73. data/db/seeds.d/75-salt_seeds.rb +1 -1
  74. data/db/seeds.d/76-job_templates.rb +7 -5
  75. data/lib/foreman_salt/engine.rb +17 -19
  76. data/lib/foreman_salt/extensions.rb +8 -8
  77. data/lib/foreman_salt/plugin.rb +130 -114
  78. data/lib/foreman_salt/version.rb +1 -1
  79. data/lib/foreman_salt.rb +1 -1
  80. data/lib/tasks/foreman_salt_tasks.rake +3 -5
  81. data/locale/action_names.rb +4 -4
  82. data/test/factories/foreman_salt_factories.rb +5 -5
  83. data/test/functional/api/v2/salt_autosign_controller_test.rb +26 -20
  84. data/test/functional/api/v2/salt_environments_controller_test.rb +29 -23
  85. data/test/functional/api/v2/salt_hostgroups_controller_test.rb +76 -0
  86. data/test/functional/api/v2/salt_keys_controller_test.rb +25 -19
  87. data/test/functional/api/v2/salt_states_controller_test.rb +72 -66
  88. data/test/functional/api/v2/salt_variables_controller_test.rb +4 -4
  89. data/test/functional/hosts_controller_test.rb +26 -26
  90. data/test/functional/minions_controller_test.rb +23 -24
  91. data/test/functional/salt_modules_controller_test.rb +3 -3
  92. data/test/functional/salt_variables_controller_test.rb +5 -5
  93. data/test/integration/hosts_js_test.rb +7 -23
  94. data/test/integration/salt_autosign_test.rb +5 -6
  95. data/test/integration/salt_environment_test.rb +2 -2
  96. data/test/integration/salt_keys_test.rb +7 -8
  97. data/test/integration/salt_module_test.rb +9 -9
  98. data/test/integration/salt_variable_test.rb +2 -2
  99. data/test/test_plugin_helper.rb +1 -1
  100. data/test/unit/grains_importer_test.rb +13 -13
  101. data/test/unit/host_extensions_test.rb +21 -19
  102. data/test/unit/hostgroup_extensions_test.rb +13 -13
  103. data/test/unit/report_importer_test.rb +9 -9
  104. data/test/unit/salt_keys_test.rb +2 -2
  105. data/test/unit/salt_modules_test.rb +2 -2
  106. data/test/unit/salt_variables_test.rb +10 -10
  107. metadata +24 -14
  108. data/app/models/setting/salt.rb +0 -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,42 +73,30 @@ 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
80
80
  salt_proxy.to_s
81
81
  end
82
82
 
83
- def saltrun!
84
- unless salt_proxy.present?
85
- errors.add(:base, _("No Salt master defined - can't continue"))
86
- logger.warn 'Unable to execute salt run, no salt proxies defined'
87
- return false
88
- end
89
- ProxyAPI::Salt.new(:url => salt_proxy.url).highstate name
90
- rescue => e
91
- errors.add(:base, _('Failed to execute state.highstate: %s') % e)
92
- false
93
- end
94
-
95
83
  def salt_modules_in_host_environment
96
- return unless self.salt_modules.any?
84
+ return unless salt_modules.any?
97
85
 
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?
86
+ if salt_environment
87
+ errors.add(:base, _('Salt states must be in the environment of the host')) unless (salt_modules - salt_environment.salt_modules).empty?
100
88
  else
101
89
  errors.add(:base, _('Host must have an environment in order to set salt states'))
102
90
  end
103
91
  end
104
92
 
105
- def derive_salt_grains(use_autosign: False)
93
+ def derive_salt_grains(use_autosign: false)
106
94
  grains = {}
107
95
  begin
108
- Rails.logger.info("Derive Salt Grains from host_params and autosign_key")
96
+ Rails.logger.info('Derive Salt Grains from host_params and autosign_key')
109
97
  grains[autosign_grain_name] = salt_autosign_key if use_autosign && !salt_autosign_key.nil?
110
98
  unless host_params[host_params_grains_name].nil? ||
111
- host_params[host_params_grains_name].class != Hash
99
+ host_params[host_params_grains_name].class != Hash
112
100
  grains.merge!(host_params[host_params_grains_name])
113
101
  end
114
102
  rescue Foreman::Exception => e
@@ -120,6 +108,7 @@ module ForemanSalt
120
108
  private
121
109
 
122
110
  def ensure_salt_autosign
111
+ remove_salt_key
123
112
  remove_salt_autosign
124
113
  create_salt_autosign
125
114
  end
@@ -131,43 +120,44 @@ module ForemanSalt
131
120
 
132
121
  def remove_salt_key
133
122
  Rails.logger.info("Remove salt key for host #{fqdn}")
134
- api = ProxyAPI::Salt.new(:url => salt_proxy.url)
123
+ api = ProxyAPI::Salt.new(url: salt_proxy.url)
135
124
  api.key_delete(name)
136
125
  end
137
126
 
138
127
  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
128
+ key = salt_autosign_key
129
+ return if key.nil?
130
+ Rails.logger.info("Remove salt autosign key for host #{fqdn}")
131
+ begin
132
+ api = ProxyAPI::Salt.new(url: salt_proxy.url)
133
+ api.autosign_remove_key(key)
134
+ rescue Foreman::Exception => e
135
+ Rails.logger.warn("Unable to remove salt autosign for #{fqdn}: #{e}")
148
136
  end
149
137
  end
150
138
 
151
139
  def generate_provisioning_key
152
- SecureRandom.hex(10)
140
+ SecureRandom.hex(10)
153
141
  end
154
142
 
155
143
  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
144
+ Rails.logger.info("Create salt autosign key for host #{fqdn}")
145
+ api = ProxyAPI::Salt.new(url: salt_proxy.url)
146
+ key = generate_provisioning_key
147
+ api.autosign_create_key(key)
148
+ update(salt_autosign_key: key)
149
+ update(salt_status: ForemanSalt::SaltStatus.minion_auth_waiting)
150
+ rescue Foreman::Exception => e
151
+ Rails.logger.warn("Unable to create salt autosign for #{fqdn}: #{e}")
166
152
  end
167
153
  end
168
154
  end
169
155
  end
170
156
 
171
- class ::Host::Managed::Jail < Safemode::Jail
172
- allow :salt_environment, :salt_master, :derive_salt_grains
157
+ # rubocop:disable Style/ClassAndModuleChildren
158
+ class Host::Managed
159
+ class Jail < ::Safemode::Jail
160
+ allow :salt_environment, :salt_master, :derive_salt_grains
161
+ end
173
162
  end
163
+ # 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
@@ -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
  )