Class: Y2Firewall::Firewalld::ServiceReader

Inherits:
Object
  • Object
show all
Includes:
Yast::Logger
Defined in:
library/network/src/lib/y2firewall/firewalld/service_reader.rb

Overview

Class to help parsing firewall-cmd --info-service=service output

Instance Method Summary collapse

Instance Method Details

#read(name) ⇒ Array<Y2Firewall::Firewalld::Service>


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'library/network/src/lib/y2firewall/firewalld/service_reader.rb', line 32

def read(name)
  info = Y2Firewall::Firewalld.instance.api.info_service(name)
  raise(Service::NotFound, name) if $CHILD_STATUS.exitstatus == 101

  service = Service.new(name: name)

  info.each do |line|
    next if line.lstrip.empty?
    next if line.start_with?(/#{name}/)

    attribute, value = line.split(":\s")
    attribute = attribute.lstrip.tr("-", "_")
    attribute = "short" if attribute == "summary"
    next unless service.respond_to?("#{attribute}=")

    if service.attributes.include?(attribute.to_sym)
      service.public_send("#{attribute}=", value.to_s)
    else
      service.public_send("#{attribute}=", value.to_s.split)
    end
  end

  service.untouched!
  service
end