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 Instance ,
812 IPAddress ,
913 IPv6Pool ,
1014 IPv6Range ,
1115 NetworkTransferPrice ,
1216 Region ,
1317)
18+ from linode_api4 .objects .base import _flatten_request_body_recursive
19+ from linode_api4 .util import drop_null_keys
1420
1521
1622class NetworkingGroup (Group ):
@@ -33,7 +39,15 @@ def firewalls(self, *filters):
3339 """
3440 return self .client ._get_and_filter (Firewall , * filters )
3541
36- def firewall_create (self , label , rules , ** kwargs ):
42+ def firewall_create (
43+ self ,
44+ label : str ,
45+ rules : Dict [str , Any ],
46+ devices : Optional [
47+ Union [FirewallCreateDevicesOptions , Dict [str , Any ]]
48+ ] = None ,
49+ ** kwargs ,
50+ ):
3751 """
3852 Creates a new Firewall, either in the given Region or
3953 attached to the given Instance.
@@ -44,6 +58,8 @@ def firewall_create(self, label, rules, **kwargs):
4458 :type label: str
4559 :param rules: The rules to apply to the new Firewall. For more information on Firewall rules, see our `Firewalls Documentation`_.
4660 :type rules: dict
61+ :param devices: Represents devices to create created alongside a Linode Firewall.
62+ :type devices: Optional[Union[FirewallCreateDevicesOptions, Dict[str, Any]]]
4763
4864 :returns: The new Firewall.
4965 :rtype: Firewall
@@ -81,10 +97,14 @@ def firewall_create(self, label, rules, **kwargs):
8197 params = {
8298 "label" : label ,
8399 "rules" : rules ,
100+ "devices" : devices ,
84101 }
85102 params .update (kwargs )
86103
87- result = self .client .post ("/networking/firewalls" , data = params )
104+ result = self .client .post (
105+ "/networking/firewalls" ,
106+ data = drop_null_keys (_flatten_request_body_recursive (params )),
107+ )
88108
89109 if not "id" in result :
90110 raise UnexpectedResponseError (
@@ -94,6 +114,25 @@ def firewall_create(self, label, rules, **kwargs):
94114 f = Firewall (self .client , result ["id" ], result )
95115 return f
96116
117+ def firewall_settings (self ) -> FirewallSettings :
118+ """
119+ Returns an object representing the Linode Firewall settings for the current user.
120+
121+ API Documentation: Not yet available.
122+
123+ :returns: An object representing the Linode Firewall settings for the current user.
124+ :rtype: FirewallSettings
125+ """
126+ result = self .client .get ("/networking/firewalls/settings" )
127+
128+ if "default_firewall_ids" not in result :
129+ raise UnexpectedResponseError (
130+ "Unexpected response when getting firewall settings!" ,
131+ json = result ,
132+ )
133+
134+ return FirewallSettings (self .client , None , result )
135+
97136 def ips (self , * filters ):
98137 """
99138 Returns a list of IP addresses on this account, excluding private addresses.
0 commit comments