Class: Mt::Wall::Model::Service
- Inherits:
-
Data
- Object
- Data
- Mt::Wall::Model::Service
- Defined in:
- lib/mt/wall/model/service.rb
Overview
A protocol/port definition referenced when granting access, e.g. Service.new(name: “https”, protocols: [:tcp], ports: [443]). Compiles into the ‘protocol` / `dst-port` fields of a filter rule.
MULTI-PROTOCOL: a service may carry MORE THAN ONE protocol (e.g. DNS is tcp+udp). A grant using such a service compiles to ONE filter rule PER protocol (RouterOS filter rows match a single protocol each). The legacy singular ‘protocol:` keyword is still accepted and folded into the `protocols` array; the `#protocol` reader returns the first protocol for callers that only need one.
PORTS: stored as the validated spec (Integer / Array / Range / “a-b” or “n” String), so a port RANGE round-trips to RouterOS as a range (‘dst-port=8000-8100`) rather than being exploded into a long list. Empty for portless protocols (e.g. icmp).
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#ports ⇒ Object
readonly
Returns the value of attribute ports.
-
#protocols ⇒ Object
readonly
Returns the value of attribute protocols.
Instance Method Summary collapse
-
#initialize(name:, protocol: nil, protocols: nil, ports: []) ⇒ Service
constructor
A new instance of Service.
-
#protocol ⇒ Symbol?
Backward-compatible single-protocol reader: the first declared protocol.
Constructor Details
#initialize(name:, protocol: nil, protocols: nil, ports: []) ⇒ Service
Returns a new instance of Service.
26 27 28 29 30 31 32 |
# File 'lib/mt/wall/model/service.rb', line 26 def initialize(name:, protocol: nil, protocols: nil, ports: []) list = protocols || protocol # A Range is a single port-spec value — wrap it so Array() does not # explode it into discrete integers (we want `dst-port=8000-8100`). port_list = ports.is_a?(Range) ? [ports] : Array(ports) super(name: name, protocols: Array(list), ports: port_list) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mt/wall/model/service.rb', line 25 Service = Data.define(:name, :protocols, :ports) do def initialize(name:, protocol: nil, protocols: nil, ports: []) list = protocols || protocol # A Range is a single port-spec value — wrap it so Array() does not # explode it into discrete integers (we want `dst-port=8000-8100`). port_list = ports.is_a?(Range) ? [ports] : Array(ports) super(name: name, protocols: Array(list), ports: port_list) end # Backward-compatible single-protocol reader: the first declared protocol. # @return [Symbol, nil] def protocol protocols.first end end |
#ports ⇒ Object (readonly)
Returns the value of attribute ports
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mt/wall/model/service.rb', line 25 Service = Data.define(:name, :protocols, :ports) do def initialize(name:, protocol: nil, protocols: nil, ports: []) list = protocols || protocol # A Range is a single port-spec value — wrap it so Array() does not # explode it into discrete integers (we want `dst-port=8000-8100`). port_list = ports.is_a?(Range) ? [ports] : Array(ports) super(name: name, protocols: Array(list), ports: port_list) end # Backward-compatible single-protocol reader: the first declared protocol. # @return [Symbol, nil] def protocol protocols.first end end |
#protocols ⇒ Object (readonly)
Returns the value of attribute protocols
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mt/wall/model/service.rb', line 25 Service = Data.define(:name, :protocols, :ports) do def initialize(name:, protocol: nil, protocols: nil, ports: []) list = protocols || protocol # A Range is a single port-spec value — wrap it so Array() does not # explode it into discrete integers (we want `dst-port=8000-8100`). port_list = ports.is_a?(Range) ? [ports] : Array(ports) super(name: name, protocols: Array(list), ports: port_list) end # Backward-compatible single-protocol reader: the first declared protocol. # @return [Symbol, nil] def protocol protocols.first end end |
Instance Method Details
#protocol ⇒ Symbol?
Backward-compatible single-protocol reader: the first declared protocol.
36 37 38 |
# File 'lib/mt/wall/model/service.rb', line 36 def protocol protocols.first end |