Skip to content

Commit

Permalink
Merge pull request #16714 from douglasgabriel/ipr_hostname_validation
Browse files Browse the repository at this point in the history
Adding hostname format validation
(cherry picked from commit 9d63cd7)
  • Loading branch information
bdunne authored and simaishi committed Jan 9, 2018
1 parent 58916b2 commit ba99cb7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ gem "manageiq-messaging", :require => false, :git =
gem "manageiq-network_discovery", "~>0.1.2", :require => false
gem "memoist", "~>0.15.0", :require => false
gem "mime-types", "~>2.6.1", :path => "mime-types-redirector"
gem "more_core_extensions", "~>3.3"
gem "more_core_extensions", "~>3.5"
gem "nakayoshi_fork", "~>0.0.3" # provides a more CoW friendly fork (GC a few times before fork)
gem "net-ldap", "~>0.14.0", :require => false
gem "net-ping", "~>1.7.4", :require => false
Expand Down
7 changes: 6 additions & 1 deletion app/models/ext_management_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def self.supported_types_and_descriptions_hash

validates :name, :presence => true, :uniqueness => {:scope => [:tenant_id]}
validates :hostname, :presence => true, :if => :hostname_required?
validate :hostname_uniqueness_valid?, :if => :hostname_required?
validate :hostname_uniqueness_valid?, :hostname_format_valid?, :if => :hostname_required?

scope :with_eligible_manager_types, ->(eligible_types) { where(:type => eligible_types) }

Expand All @@ -92,6 +92,11 @@ def hostname_uniqueness_valid?
errors.add(:hostname, N_("has to be unique per provider type")) if existing_hostnames.include?(hostname.downcase)
end

def hostname_format_valid?
return if hostname.ipaddress? || hostname.hostname?
errors.add(:hostname, _("format is invalid."))
end

include NewWithTypeStiMixin
include UuidMixin
include EmsRefresh::Manager
Expand Down

0 comments on commit ba99cb7

Please sign in to comment.