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

Add a list of interfaces #81

Merged
merged 23 commits into from Sep 20, 2018
Merged

Add a list of interfaces #81

merged 23 commits into from Sep 20, 2018

Conversation

imobachgs
Copy link
Contributor

@imobachgs imobachgs commented Sep 17, 2018

This PR implements support to assign interfaces to firewall zones.

change-zone-interface

@coveralls
Copy link

coveralls commented Sep 17, 2018

Coverage Status

Coverage increased (+1.5%) to 13.598% when pulling a8395d0 on features/interfaces-list into 894d95f on new-ui.

# or creates a new zone.
#
# @param zone [String] zone name
def select_row(zone_name)
Copy link
Contributor

Choose a reason for hiding this comment

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

As we were discussing we should try to generalize the current. But for now we should at least fix the comments and param name as it will used not only for zones but also for interfaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just a leftover. Anyway, I will try to extract it.

self.row_id = nil
end

# List of candidate nodes to go back after opening a zone view in the tree
Copy link
Contributor

Choose a reason for hiding this comment

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

Same than above

@teclator
Copy link
Contributor

Just some minor comments.

# Singleton class to keep the position of the user in the UI and other similar
# information that needs to be rememberd across UI redraws to give the user a
# sense of continuity.
class UIState
Copy link
Member

Choose a reason for hiding this comment

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

Something like this is also used in the Partitioner. Is it easy or hard to extract the generic part?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's true. I took the adapted code from @teclator (thanks!) and I will try to extract the common pieces and move it to yast2.

end

class << self
# Singleton instance
Copy link
Member

Choose a reason for hiding this comment

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

Why not use the stdlib https://devdocs.io/ruby~2.5/singleton ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not know, this code comes from yast2-storage-ng. But I do not see a good reason.


module Y2Firewall
module Widgets
# A table with all {Y2Firewall::Firewalld::Zone}s.
Copy link
Member

Choose a reason for hiding this comment

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

not zones, interfaces

DEFAULT_ZONE_NAME = "default".freeze

# @!attribute [r] interfaces
# @return [Array<Hash>] Interfaces
Copy link
Member

Choose a reason for hiding this comment

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

When a Hash is really an ad-hoc class, like it is here for the interface, I like to make a subclass of Hash just for documentation purposes, like here:
declaration: https://github.com/yast/yast-yast2/blob/e4ab10035ba30f739175009344872c4062c26db6/library/systemd/src/lib/yast2/systemd/unit_prop_map.rb#L8
reference: https://github.com/yast/yast-yast2/blob/e4ab10035ba30f739175009344872c4062c26db6/library/systemd/src/lib/yast2/systemd/socket.rb#L70

So I think we should declare Y2Firewall::Firewalld::Interface

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. @teclator please, could you adapt known_interfaces to work with proper objects while I am extracting the popup and the UIState classes?

Copy link
Contributor

Choose a reason for hiding this comment

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

# @macro seeAbstractWidget
def init
interface = Y2Firewall::UIState.instance.row_id
if interface && interfaces.map(&:name).include?(interface.to_s)
Copy link
Contributor

Choose a reason for hiding this comment

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

np: why the id is not used?

interfaces.map(&:id).include?(interface)

def items
interfaces.map do |iface|
[
iface.name.to_sym,
Copy link
Contributor

Choose a reason for hiding this comment

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

iface.id?

end

def selected_interface
interfaces.find { |i| i.name == value.to_s }
Copy link
Contributor

Choose a reason for hiding this comment

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

Same than above

return if new_zone && new_zone.interfaces.include?(interface.name)

old_zone = interface.zone
old_zone.remove_interface(interface.name) if old_zone
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a change zone method could be added to the interface object (for SP1 🙄 )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it would be nice :)

@teclator
Copy link
Contributor

LGTM

@imobachgs imobachgs merged commit fb7cefc into new-ui Sep 20, 2018
@imobachgs imobachgs deleted the features/interfaces-list branch September 20, 2018 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants