Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding hostname format validation #16714

Merged
merged 1 commit into from
Jan 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 => File.expand_path("mime-types-redirector", __dir__)
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?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be a good idea to update the Gemfile setting more_core_extensions to '~> 3.5'https://github.com/ManageIQ/manageiq/blob/master/Gemfile#L49

Copy link
Member Author

@douglasgabriel douglasgabriel Jan 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's done 👍

errors.add(:hostname, _("format is invalid."))
end

include NewWithTypeStiMixin
include UuidMixin
include EmsRefresh::Manager
Expand Down