Skip to content

Commit

Permalink
adding hostname format validation
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasgabriel committed Dec 22, 2017
1 parent 2d95d40 commit ba0b230
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 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,12 @@ 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?
error_msg = N_("is in a wrong format.")
errors.add(:hostname, _(error_msg))
end

include NewWithTypeStiMixin
include UuidMixin
include EmsRefresh::Manager
Expand Down

0 comments on commit ba0b230

Please sign in to comment.