service module

Copyright 2023 Sophos Ltd. All rights reserved. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

class service.Service(api_client)[source]

Bases: object

Class for working with Service(s).

create(name, service_type, service_list, debug)[source]

Create a TCP or UDP service

Parameters:
  • name (str) – Service name.

  • service_type (str) – Service type. Valid values are TCPorUDP, IP, ICMP, or ICMPv6.

  • service_list (list) – List of dictionaries. For type TCPorUDP, src_port(str, optional) default=1:65535, dst_port(str), and protocol(str). For type IP, protocol(str). For type ICMP and ICMPv6, icmp_type (str) and icmp_code (str).

  • debug (bool, optional) – Enable debug mode. Defaults to False.

Returns:

XML response converted to Python dictionary

Return type:

dict

get(name, operator='=', dst_proto=None, dst_port=None)[source]

Get Service(s)

Parameters:
  • name (str, optional) – Get Service by name. Defaults to None.

  • operator (str, optional) – Operator for search. Default is “=”. Valid operators: =, !=, like.

  • dst_proto (str, optional) – Specify TCP or UDP

  • dst_port (str, optional) – Specify dest TCP or UDP port. Use : to specify ranges (ex. 67:68)

Returns:

XML response converted to Python dictionary

Return type:

dict

update(name, service_type, service_list, action, debug)[source]

Add or remove a service entry to/from a service

Parameters:
  • name (str) – Service name.

  • service_type (str) – Service type. Valid values are TCPorUDP, IP, ICMP, or ICMPv6.

  • service_list (list) – List of dictionaries. For type TCPorUDP, src_port(str, optional) default=1:65535, dst_port(str), and protocol(str). For type IP, protocol(str). For type ICMP and ICMPv6, icmp_type (str) and icmp_code (str).

  • action (str) – Options are ‘add’, ‘remove’ or ‘replace’. Defaults to ‘add’.

  • debug (bool, optional) – Enable debug mode. Defaults to False.

Returns:

XML response converted to Python dictionary

Return type:

dict

class service.ServiceGroup(api_client)[source]

Bases: object

Class for working with Service Group(s).

create(name, service_list, description, debug)[source]

Create Service Group object.

Parameters:
  • name (str) – Name of the object.

  • service_list (list, optional) – List containing Service(s) to associate the Services Group.

  • description (str) – Description.

  • debug (bool, optional) – Turn on debugging. Defaults to False.

Returns:

XML response converted to Python dictionary.

Return type:

dict

get(name, operator='=')[source]

Get Service Group object(s)

Parameters:
  • name (str, optional) – Service Group name. Returns all objects if not specified.

  • operator (str, optional) – Operator for search. Default is “=”. Valid operators: =, !=, like.

update(name, service_list, description, action, debug)[source]

Add or remove a Service from an Service Group.

Parameters:
  • name (str) – Service Group name.

  • description (str) – Service Group description.

  • service_list (str) – List of Service(s) to be added to or removed from the Service Group.

  • action (str) – Options are ‘add’, ‘remove’ or ‘replace’. Specify None to disable updating Service Group List. Defaults to ‘add’.

  • debug (bool, optional) – Enable debug mode. Defaults to False.

Returns:

XML response converted to Python dictionary

Return type:

dict