1+ from typing import Any , Dict , Optional , Union
2+
13from linode_api4 .errors import UnexpectedResponseError
24from linode_api4 .groups import Group
35from linode_api4 .objects import (
46 VLAN ,
57 Base ,
68 Firewall ,
9+ FirewallCreateDevicesOptions ,
10+ FirewallSettings ,
711 FirewallTemplate ,
812 Instance ,
913 IPAddress ,
1216 NetworkTransferPrice ,
1317 Region ,
1418)
19+ from linode_api4 .objects .base import _flatten_request_body_recursive
20+ from linode_api4 .util import drop_null_keys
1521
1622
1723class NetworkingGroup (Group ):
@@ -34,7 +40,15 @@ def firewalls(self, *filters):
3440 """
3541 return self .client ._get_and_filter (Firewall , * filters )
3642
37- def firewall_create (self , label , rules , ** kwargs ):
43+ def firewall_create (
44+ self ,
45+ label : str ,
46+ rules : Dict [str , Any ],
47+ devices : Optional [
48+ Union [FirewallCreateDevicesOptions , Dict [str , Any ]]
49+ ] = None ,
50+ ** kwargs ,
51+ ):
3852 """
3953 Creates a new Firewall, either in the given Region or
4054 attached to the given Instance.
@@ -45,6 +59,8 @@ def firewall_create(self, label, rules, **kwargs):
4559 :type label: str
4660 :param rules: The rules to apply to the new Firewall. For more information on Firewall rules, see our `Firewalls Documentation`_.
4761 :type rules: dict
62+ :param devices: Represents devices to create created alongside a Linode Firewall.
63+ :type devices: Optional[Union[FirewallCreateDevicesOptions, Dict[str, Any]]]
4864
4965 :returns: The new Firewall.
5066 :rtype: Firewall
@@ -82,10 +98,14 @@ def firewall_create(self, label, rules, **kwargs):
8298 params = {
8399 "label" : label ,
84100 "rules" : rules ,
101+ "devices" : devices ,
85102 }
86103 params .update (kwargs )
87104
88- result = self .client .post ("/networking/firewalls" , data = params )
105+ result = self .client .post (
106+ "/networking/firewalls" ,
107+ data = drop_null_keys (_flatten_request_body_recursive (params )),
108+ )
89109
90110 if not "id" in result :
91111 raise UnexpectedResponseError (
@@ -112,6 +132,24 @@ def firewall_templates(self, *filters):
112132 """
113133 return self .client ._get_and_filter (FirewallTemplate , * filters )
114134
135+ def firewall_settings (self ) -> FirewallSettings :
136+ """
137+ Returns an object representing the Linode Firewall settings for the current user.
138+ API Documentation: Not yet available.
139+ NOTE: This feature may not currently be available to all users.
140+ :returns: An object representing the Linode Firewall settings for the current user.
141+ :rtype: FirewallSettings
142+ """
143+ result = self .client .get ("/networking/firewalls/settings" )
144+
145+ if "default_firewall_ids" not in result :
146+ raise UnexpectedResponseError (
147+ "Unexpected response when getting firewall settings!" ,
148+ json = result ,
149+ )
150+
151+ return FirewallSettings (self .client , None , result )
152+
115153 def ips (self , * filters ):
116154 """
117155 Returns a list of IP addresses on this account, excluding private addresses.
0 commit comments