-
Notifications
You must be signed in to change notification settings - Fork 897
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
Improving physical infrastructure provider hostname validation #16220
Conversation
755887e
to
9262d71
Compare
Hm we shouldn't accept |
I agree with that, actually the protocol and path parts are ignored on the connection validation on the UI, so i've try to extend the behavior of the connection validation to the entity validation. The protocol part is just used to know if is an ip address or a DNS name. Look:
|
app/models/ext_management_system.rb
Outdated
errors.add(:hostname, N_("has to be unique per provider type")) if existing_hostnames.include?(hostname.downcase.gsub(/\/$/, '')) | ||
end | ||
|
||
def hostname_format_valid? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this body more cleaner, remove some white lines.
a44efe2
to
14fb252
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I think my question is why didn't putting anything but an IP/hostname fail provider validation anyway when it tried to connect? Is a URI a valid entry for the LXCA provider? |
@agrare if I understand correctly your question: the test fails only if put an IP address and adds a path after it, but if it is a hostname the validation doesn't fails if has some path after it |
@douglasgabriel I'm wondering why it doesn't fail when we try to connect to the provider? |
@douglasgabriel This type of validation should be checked with the validate button. We have a button to validade, the save button just should save. |
app/models/ext_management_system.rb
Outdated
|
||
serialize :options | ||
|
||
def hostname_uniqueness_valid? | ||
return unless hostname_required? | ||
return unless hostname.present? # Presence is checked elsewhere | ||
# check uniqueness per provider type | ||
existing_hostnames = (self.class.all - [self]).map(&:hostname).compact.map { |hostname| hostname.downcase.gsub(/\/$/, '') } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be done with an ActiveRecord built-in.
app/models/ext_management_system.rb
Outdated
uri = URI.parse(URI.encode(hostname.gsub(/\/$/, ''))) # disregarding the slash at the end of the address | ||
return unless uri.scheme # If has no protocol before hostname, any format is valid | ||
error_msg = "is in a wrong format. Please, remove the path after IP address." | ||
errors.add(:hostname, N_(error_msg)) unless uri.path.to_s.empty? # If the IP address has path after it, the format is invalid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mzazrivec Will this work with the automated string finder for i18n?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope.
This would work:
error_msg = N_("is in a wrong format ...")
errors.add(:hostname, _(error_msg))
Or even simpler:
error_msg = _("is in a wrong format ...")
errors.add(:hostname, error_msg)
I added a comment also related to this post here. |
- for available fields in report definition - adding as keys to hash with results (this hash is passed to report engine)
14fb252
to
79d3b56
Compare
79d3b56
to
da46e47
Compare
Checked commits douglasgabriel/manageiq@a92c6b4~...da46e47 with ruby 2.3.3, rubocop 0.47.1, haml-lint 0.20.0, and yamllint 1.10.0 app/models/customization_script.rb
lib/utils/regex_util.rb
|
Once the hostname format is validated, there is no need to remove the slash at the end of the hostname, so i'm replacing this PR with this other #16714 |
This PR is able to: