Module: Y2Firewall::Firewalld::Api::Services

Included in:
Y2Firewall::Firewalld::Api
Defined in:
library/network/src/lib/y2firewall/firewalld/api/services.rb

Overview

This module contains specific API methods for handling services definition and configuration.

Instance Method Summary collapse

Instance Method Details

#add_service_port(service, port, permanent: permanent?) ) ⇒ Boolean

Returns True if port was removed from service.

Parameters:

  • service (String)

    The firewall firewall

  • port (String)

    The firewall port

  • permanent (Boolean) (defaults to: permanent?) )

    if true and firewalld is running it modifies the permanent configuration

Returns:

  • (Boolean)

    True if port was removed from service


150
151
152
# File 'library/network/src/lib/y2firewall/firewalld/api/services.rb', line 150

def add_service_port(service, port, permanent: permanent?)
  modify_command("--service=#{service}", "--add-port=#{port}", permanent: permanent)
end

#create_service(service) ⇒ Boolean

Creates a new service definition for the given service name

Parameters:

  • service (String)

    The firewall service

Returns:

  • (Boolean)

    true if the new service was created


34
35
36
# File 'library/network/src/lib/y2firewall/firewalld/api/services.rb', line 34

def create_service(service)
  modify_command("--new-service=#{service}", permanent: !offline?)
end

#delete_service(service) ⇒ Boolean

Remove the service definition for the given service name

Parameters:

  • service (String)

    The firewall service

Returns:

  • (Boolean)

    true if the service was deleted


42
43
44
# File 'library/network/src/lib/y2firewall/firewalld/api/services.rb', line 42

def delete_service(service)
  modify_command("--delete-service=#{service}", permanent: !offline?)
end

#info_service(service, permanent: permanent?) ) ⇒ Array<String>

Show all the service declaration (name, description, ports, protocols and modules)

Parameters:

  • service (String)

    The firewall service name

  • permanent (Boolean) (defaults to: permanent?) )

    if true and firewalld is running it reads the permanent configuration

Returns:

  • (Array<String>)

    list of all information for the given service


60
61
62
# File 'library/network/src/lib/y2firewall/firewalld/api/services.rb', line 60

def info_service(service, permanent: permanent?)
  string_command("--info-service=#{service}", "--verbose", permanent: permanent).split("\n")
end

#modify_service_description(service, long_description) ⇒ Object

Modify the long description of the service

Parameters:

  • service (String)

    The firewall service

  • long_description (String)

    the new service description


96
97
98
99
# File 'library/network/src/lib/y2firewall/firewalld/api/services.rb', line 96

def modify_service_description(service, long_description)
  modify_command("--service=#{service}", "--set-description=#{long_description}",
    permanent: !offline?)
end

#modify_service_short(service, short_description) ⇒ Object

Modify the full name or short description of the service

Parameters:

  • service (String)

    The firewall service

  • short_description (String)

    the new service name or description


79
80
81
82
# File 'library/network/src/lib/y2firewall/firewalld/api/services.rb', line 79

def modify_service_short(service, short_description)
  modify_command("--service=#{service}", "--set-short=#{short_description}",
    permanent: !offline?)
end

#remove_service_port(service, port, permanent: permanent?) ) ⇒ Boolean

Returns True if port was removed from service.

Parameters:

  • service (String)

    The firewall service

  • port (String)

    The firewall port

  • permanent (Boolean) (defaults to: permanent?) )

    if true and firewalld is running it modifies the permanent configuration

Returns:

  • (Boolean)

    True if port was removed from service


141
142
143
# File 'library/network/src/lib/y2firewall/firewalld/api/services.rb', line 141

def remove_service_port(service, port, permanent: permanent?)
  modify_command("--service=#{service}", "--remove-port=#{port}", permanent: permanent)
end

#service_description(service, permanent: permanent?) ) ⇒ String

Returns Description for service.

Parameters:

  • service (String)

    the firewall service

  • permanent (Boolean) (defaults to: permanent?) )

    if true and firewalld is running it reads the permanent configuration

Returns:

  • (String)

    Description for service


88
89
90
# File 'library/network/src/lib/y2firewall/firewalld/api/services.rb', line 88

def service_description(service, permanent: permanent?)
  string_command("--service=#{service}", "--get-description", permanent: permanent)
end

#service_modules(service, permanent: permanent?) ) ⇒ Array<String>

Returns The firewall service modules.

Parameters:

  • service (String)

    The firewall service

  • permanent (Boolean) (defaults to: permanent?) )

    if true and firewalld is running it reads the permanent configuration

Returns:

  • (Array<String>)

    The firewall service modules


132
133
134
# File 'library/network/src/lib/y2firewall/firewalld/api/services.rb', line 132

def service_modules(service, permanent: permanent?)
  string_command("--service=#{service}", "--get-modules", permanent: permanent).split(" ")
end

#service_ports(service, permanent: permanent?) ) ⇒ Array<String>

Return the list of ports allowed by the given service

Parameters:

  • service (String)

    The firewall service

  • permanent (Boolean) (defaults to: permanent?) )

    if true and firewalld is running it reads the permanent configuration

Returns:

  • (Array<String>)

    The firewall service ports


116
117
118
# File 'library/network/src/lib/y2firewall/firewalld/api/services.rb', line 116

def service_ports(service, permanent: permanent?)
  string_command("--service=#{service}", "--get-ports", permanent: permanent).split(" ")
end

#service_protocols(service, permanent: permanent?) ) ⇒ Array<String>

Returns The firewall service protocols.

Parameters:

  • service (String)

    The firewall service

  • permanent (Boolean) (defaults to: permanent?) )

    if true and firewalld is running it reads the permanent configuration

Returns:

  • (Array<String>)

    The firewall service protocols


124
125
126
# File 'library/network/src/lib/y2firewall/firewalld/api/services.rb', line 124

def service_protocols(service, permanent: permanent?)
  string_command("--service=#{service}", "--get-protocols", permanent: permanent).split(" ")
end

#service_short(service, permanent: permanent?) ) ⇒ String

Full name or short description of the service

Parameters:

  • service (String)

    The firewall service

  • permanent (Boolean) (defaults to: permanent?) )

    if true and firewalld is running it reads the permanent configuration

Returns:

  • (String)

    Short description for service


70
71
72
73
# File 'library/network/src/lib/y2firewall/firewalld/api/services.rb', line 70

def service_short(service, permanent: permanent?)
  # these may not exist on early firewalld releases
  string_command("--service=#{service}", "--get-short", permanent: permanent)
end

#service_supported?(service) ⇒ Boolean

Returns whether the service definition for the service name given is present or not.

Parameters:

  • service (String)

    The firewall service

Returns:

  • (Boolean)

    True if service definition exists


106
107
108
# File 'library/network/src/lib/y2firewall/firewalld/api/services.rb', line 106

def service_supported?(service)
  services.include?(service)
end

#servicesArray<String>

Return the list of availale firewalld services

Returns:

  • (Array<String>)

    List of firewall services


49
50
51
# File 'library/network/src/lib/y2firewall/firewalld/api/services.rb', line 49

def services
  string_command("--get-services").split(" ")
end