Skip to content

Commit

Permalink
Sets the firewalld service state according to the profile
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Oct 31, 2023
1 parent 79bf7fe commit ec9ebce
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/lib/y2firewall/clients/auto.rb
Expand Up @@ -79,10 +79,10 @@ def summary
# @return [Boolean]
def import(profile, merge = !Yast::Mode.config)
self.class.profile = profile
# It does not need to be merged with current config but could be modified
# by the AutoYaST confirm dialog.
update_service_state(profile)
return false if merge && !read(force: false)

# Obtains the default from the control file (settings) if not present.
enable if profile.fetch("enable_firewall", settings.enable_firewall)
start if profile.fetch("start_firewall", false)
autoyast.import(profile)
check_profile_for_errors
Expand Down Expand Up @@ -240,16 +240,25 @@ def settings
::Installation::SecuritySettings.instance
end

# Set that the firewall has to be enabled when writing
def enable
self.class.enable = true
# It sets which should be the firewalld service state according to the profile
# or to the product defaults settings
#
# @param profile [Hash] firewall profile section to be imported
def update_service_state(profile)
return unless self.class.enable.nil?

state = profile.fetch("enable_firewall", settings.enable_firewall)

log.info("Firewall should be enabled: #{state}")
state ? settings.enable_firewall! : settings.disable_firewall! if Yast::Mode.auto
state
end

# Whether the firewalld service has to be enable or disable when writing
#
# @return [Boolean] true if has to be enabled; false otherwise
def enable?
!!self.class.enable
!!(Yast::Mode.auto ? settings.enable_firewall : self.class.enable)
end

# Set that the firewall has to be started when writing
Expand Down

0 comments on commit ec9ebce

Please sign in to comment.