foreman_host_extra_validator 0.0.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Rakefile +1 -1
- data/app/models/concerns/foreman_host_extra_validator/host_extensions.rb +4 -2
- data/db/migrate/20220923181701_fix_extra_validation_settings_category_to_dsl.rb +5 -0
- data/lib/foreman_host_extra_validator/engine.rb +15 -14
- data/lib/foreman_host_extra_validator/version.rb +1 -1
- data/locale/Makefile +1 -1
- data/locale/gemspec.rb +1 -1
- data/test/unit/foreman_host_extra_validator_test.rb +32 -21
- metadata +10 -11
- data/app/models/setting/foreman_host_extra_validator.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2cd1faf2a634cac57b3603ab51bed47ca72cd9da17ed55d7497d9d108030b61e
|
4
|
+
data.tar.gz: a4802142256b0e139ebc923b1d6615735f40aae117d3968cc0f2ac04bacf5441
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b092cf27e78b4e20ef904026148bda130ab76b05d2d944581ade639c34e939009ffc38d8796971803b863311f123511c8c7787a69f4ce73435e9dc0bdccb439e
|
7
|
+
data.tar.gz: e3fa88d65f80b9885e4c3209c0b29c28c5642d36c5ecb28958c6c812555bea96bfa7dc1fd70668247411b2faae3bb02d61f212a1db450bf34bcff155894b070a
|
data/Rakefile
CHANGED
@@ -20,7 +20,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
20
20
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
21
|
end
|
22
22
|
|
23
|
-
APP_RAKEFILE = File.expand_path('
|
23
|
+
APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
|
24
24
|
|
25
25
|
Bundler::GemHelper.install_tasks
|
26
26
|
|
@@ -6,12 +6,14 @@ module ForemanHostExtraValidator
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def validate_name_by_regex
|
9
|
-
return unless validate_name_regex
|
9
|
+
return unless validate_name_regex.present?
|
10
10
|
errors.add(:name, _('must match regex /%s/') % validate_name_regex) unless shortname =~ /#{validate_name_regex}/
|
11
11
|
end
|
12
12
|
|
13
|
+
private
|
14
|
+
|
13
15
|
def validate_name_regex
|
14
|
-
|
16
|
+
inherited_params_hash.dig('host_name_validation_regex', :value) || Setting[:host_name_validation_regex]
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|
@@ -4,29 +4,30 @@ module ForemanHostExtraValidator
|
|
4
4
|
|
5
5
|
config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
|
6
6
|
|
7
|
-
initializer 'foreman_host_extra_validator.load_default_settings', :before => :load_config_initializers do |_app|
|
8
|
-
require_dependency File.expand_path('../../../app/models/setting/foreman_host_extra_validator.rb', __FILE__) if begin
|
9
|
-
Setting.table_exists?
|
10
|
-
rescue
|
11
|
-
(false)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
7
|
initializer 'foreman_host_extra_validator.register_plugin', :before => :finisher_hook do |_app|
|
16
8
|
Foreman::Plugin.register :foreman_host_extra_validator do
|
9
|
+
requires_foreman '>= 3.0.0'
|
10
|
+
|
11
|
+
settings do
|
12
|
+
category(:host_extra_validator, N_('Host Extra Validator')) do
|
13
|
+
setting('host_name_validation_regex',
|
14
|
+
description: N_('Default regex the name of a host is validated against'),
|
15
|
+
type: :string,
|
16
|
+
default: '^[a-zA-Z0-9\-_]+$',
|
17
|
+
full_name: N_('Regular expresssion'))
|
18
|
+
end
|
19
|
+
end
|
17
20
|
end
|
18
21
|
end
|
19
22
|
|
20
23
|
config.to_prepare do
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
Rails.logger.warn "ForemanPluginTemplate: skipping engine hook (#{e})\n#{e.backtrace}"
|
25
|
-
end
|
24
|
+
Host::Managed.include ForemanHostExtraValidator::HostExtensions
|
25
|
+
rescue => e
|
26
|
+
Rails.logger.warn "ForemanHostExtraValidator: skipping engine hook (#{e})\n#{e.backtrace}"
|
26
27
|
end
|
27
28
|
|
28
29
|
initializer 'foreman_host_extra_validator.register_gettext', after: :load_config_initializers do |_app|
|
29
|
-
locale_dir = File.join(File.expand_path('
|
30
|
+
locale_dir = File.join(File.expand_path('../..', __dir__), 'locale')
|
30
31
|
locale_domain = 'foreman_host_extra_validator'
|
31
32
|
Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
|
32
33
|
end
|
data/locale/Makefile
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
# make tx-update - download and merge translations from Transifex
|
7
7
|
# make clean - clean everything
|
8
8
|
#
|
9
|
-
DOMAIN =
|
9
|
+
DOMAIN = foreman_host_extra_validator
|
10
10
|
VERSION = $(shell ruby -e 'require "rubygems";spec = Gem::Specification::load(Dir.glob("../*.gemspec")[0]);puts spec.version')
|
11
11
|
POTFILE = $(DOMAIN).pot
|
12
12
|
MOFILE = $(DOMAIN).mo
|
data/locale/gemspec.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
# Matches
|
1
|
+
# Matches foreman_host_extra_validator.gemspec
|
2
2
|
_('This plugin adds extra validations to a host.')
|
@@ -1,31 +1,42 @@
|
|
1
1
|
require 'test_plugin_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class ForemanHostExtraValidatorTest < ActiveSupport::TestCase
|
4
4
|
setup do
|
5
|
-
Setting::
|
5
|
+
Setting::ForemanHostExtraValidator.load_defaults
|
6
6
|
disable_orchestration
|
7
|
-
User.current =
|
7
|
+
User.current = FactoryBot.build(:user, :admin)
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
10
|
+
context 'with validation regex' do
|
11
|
+
setup do
|
12
|
+
Setting[:host_name_validation_regex] = '^[0-9]+$'
|
13
|
+
@host = FactoryBot.build(:host)
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
test 'host should validate from settings' do
|
17
|
+
@host.name = '054354'
|
18
|
+
assert_valid @host
|
19
|
+
end
|
20
|
+
|
21
|
+
test 'host should not validate when host name does not match regex' do
|
22
|
+
@host.name = 'invalidhostname'
|
23
|
+
refute_valid @host
|
24
|
+
assert_includes @host.errors[:name], "must match regex /#{Setting[:host_name_validation_regex]}/"
|
25
|
+
end
|
26
|
+
|
27
|
+
test 'host should validate from hostgroup parameter' do
|
28
|
+
hostgroup = FactoryBot.create(:hostgroup)
|
29
|
+
@host.hostgroup = hostgroup
|
30
|
+
FactoryBot.create(:hostgroup_parameter, :name => 'host_name_validation_regex', :value => '^[a-z]+$', :hostgroup => hostgroup)
|
31
|
+
|
32
|
+
assert_equal '^[a-z]+$', @host.send(:validate_name_regex)
|
33
|
+
@host.hostname = 'abcdef'
|
34
|
+
assert_valid @host
|
35
|
+
|
36
|
+
@host.hostname = '1234'
|
37
|
+
refute_valid @host
|
38
|
+
assert_includes @host.errors[:name], "must match regex /^[a-z]+$/"
|
39
|
+
end
|
23
40
|
|
24
|
-
test 'host should not validate when host name does not match regex' do
|
25
|
-
regex = '^[0-9]+$'
|
26
|
-
Setting[:host_name_validation_regex] = regex
|
27
|
-
host = Host.new name: 'invalidhostname'
|
28
|
-
refute host.valid?
|
29
|
-
assert_includes host.errors[:name], "must match regex /#{regex}/"
|
30
41
|
end
|
31
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_host_extra_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Timo Goebel
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -49,7 +49,7 @@ files:
|
|
49
49
|
- README.md
|
50
50
|
- Rakefile
|
51
51
|
- app/models/concerns/foreman_host_extra_validator/host_extensions.rb
|
52
|
-
-
|
52
|
+
- db/migrate/20220923181701_fix_extra_validation_settings_category_to_dsl.rb
|
53
53
|
- lib/foreman_host_extra_validator.rb
|
54
54
|
- lib/foreman_host_extra_validator/engine.rb
|
55
55
|
- lib/foreman_host_extra_validator/version.rb
|
@@ -61,10 +61,11 @@ files:
|
|
61
61
|
- locale/gemspec.rb
|
62
62
|
- test/test_plugin_helper.rb
|
63
63
|
- test/unit/foreman_host_extra_validator_test.rb
|
64
|
-
homepage: https://github.com/
|
65
|
-
licenses:
|
64
|
+
homepage: https://github.com/theforeman/foreman_host_extra_validator
|
65
|
+
licenses:
|
66
|
+
- GPL-3.0
|
66
67
|
metadata: {}
|
67
|
-
post_install_message:
|
68
|
+
post_install_message:
|
68
69
|
rdoc_options: []
|
69
70
|
require_paths:
|
70
71
|
- lib
|
@@ -79,12 +80,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
80
|
- !ruby/object:Gem::Version
|
80
81
|
version: '0'
|
81
82
|
requirements: []
|
82
|
-
|
83
|
-
|
84
|
-
signing_key:
|
83
|
+
rubygems_version: 3.1.6
|
84
|
+
signing_key:
|
85
85
|
specification_version: 4
|
86
86
|
summary: This plugin adds extra validations to a host.
|
87
87
|
test_files:
|
88
88
|
- test/test_plugin_helper.rb
|
89
89
|
- test/unit/foreman_host_extra_validator_test.rb
|
90
|
-
has_rdoc:
|
@@ -1,16 +0,0 @@
|
|
1
|
-
class Setting
|
2
|
-
class ForemanHostExtraValidator < ::Setting
|
3
|
-
def self.load_defaults
|
4
|
-
# Check the table exists
|
5
|
-
return unless super
|
6
|
-
|
7
|
-
self.transaction do
|
8
|
-
[
|
9
|
-
self.set('host_name_validation_regex', _('Default regex the name of a host is validated against'), '^[a-zA-Z0-9-_]+$')
|
10
|
-
].compact.each { |s| self.create! s.update(:category => 'Setting::ForemanHostExtraValidator') }
|
11
|
-
end
|
12
|
-
|
13
|
-
true
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|