diff --git a/linode_api4/groups/monitor.py b/linode_api4/groups/monitor.py index 058f73aba..ac5ad8f4f 100644 --- a/linode_api4/groups/monitor.py +++ b/linode_api4/groups/monitor.py @@ -24,6 +24,7 @@ LogsStreamDetails, LogsStreamQuota, TrafficPeakLogsDestinationDetails, + VpnGatewayLogsStreamDetails, ) __all__ = [ @@ -579,7 +580,9 @@ def stream_create( label: str, type: Union[LogsStreamType, str], status: Optional[Union[LogsStreamStatus, str]] = None, - details: Optional[LogsStreamDetails] = None, + details: Optional[ + Union[LogsStreamDetails, VpnGatewayLogsStreamDetails] + ] = None, ) -> LogsStream: """ Creates a new :any:`LogsStream` for logs on this account. For example:: @@ -605,6 +608,16 @@ def stream_create( ) ) + # VPN Gateway IPsec logs for selected gateways + vpn_stream = client.monitor.stream_create( + destinations=[1234], + label="VPN Gateway IPsec stream", + type=LogsStreamType.vpngw_ipsec_logs, + details=VpnGatewayLogsStreamDetails( + vpn_gateway_ids=[50, 60], + ) + ) + API Documentation: https://techdocs.akamai.com/linode-api/reference/post-stream :param destinations: The unique identifier for the sync point that will receive logs data. @@ -613,15 +626,17 @@ def stream_create( :type destinations: list[int] :param label: The name of the stream. This is used for display purposes in Akamai Cloud Manager. :type label: str - :param type: The type of stream — ``audit_logs`` for Linode control plane logs, - or ``lke_audit_logs`` for LKE enterprise cluster audit logs. + :param type: The stream type: ``audit_logs``, ``lke_audit_logs``, + ``vpngw_ipsec_logs``, or ``vpngw_bgp_logs``. :type type: str or LogsStreamType :param status: (Optional) The availability status of the stream. Possible values are: ``active``, ``inactive``. Defaults to ``active``. :type status: str - :param details: (Optional) Additional stream details. Only applicable for - ``lke_audit_logs`` streams. Omit for ``audit_logs`` streams. - :type details: LogsStreamDetails + :param details: Stream details. Required for LKE and VPN Gateway streams. + Use LogsStreamDetails for LKE and + VpnGatewayLogsStreamDetails for VPN Gateway. + Omit for ``audit_logs`` streams. + :type details: LogsStreamDetails or VpnGatewayLogsStreamDetails :returns: The newly created logs stream. :rtype: LogsStream diff --git a/linode_api4/objects/monitor.py b/linode_api4/objects/monitor.py index ed732b3d4..69f67fc31 100644 --- a/linode_api4/objects/monitor.py +++ b/linode_api4/objects/monitor.py @@ -43,6 +43,7 @@ "LogsStreamDetails", "LogsStreamDestination", "LogsStreamQuota", + "VpnGatewayLogsStreamDetails", ] @@ -793,6 +794,8 @@ class LogsStreamStatus(StrEnum): class LogsStreamType(StrEnum): audit_logs = "audit_logs" lke_audit_logs = "lke_audit_logs" + vpngw_ipsec_logs = "vpngw_ipsec_logs" + vpngw_bgp_logs = "vpngw_bgp_logs" @dataclass @@ -821,6 +824,28 @@ class LogsStreamDetails(JSONObject): cluster_ids: Optional[List[int]] = None is_auto_add_all_clusters_enabled: bool = False + @classmethod + def from_json( + cls, json: Dict[str, Any] + ) -> Optional[Union["LogsStreamDetails", "VpnGatewayLogsStreamDetails"]]: + if json is not None and "vpn_gateway_ids" in json: + return VpnGatewayLogsStreamDetails.from_json(json) + + return super().from_json(json) + + +@dataclass +class VpnGatewayLogsStreamDetails(JSONObject): + """ + Details for ``vpngw_ipsec_logs`` and ``vpngw_bgp_logs`` streams. + + :param vpn_gateway_ids: A non-empty list of unique, positive VPN Gateway IDs. + Updating this list replaces all previously selected gateway IDs. + :type vpn_gateway_ids: List[int] + """ + + vpn_gateway_ids: Optional[List[int]] = None + @dataclass class LogsStreamDestination(JSONObject): diff --git a/test/unit/objects/monitor_test.py b/test/unit/objects/monitor_test.py index ed4b63d8b..4eaa43684 100644 --- a/test/unit/objects/monitor_test.py +++ b/test/unit/objects/monitor_test.py @@ -7,6 +7,7 @@ LogsDestinationHistory, LogsStream, LogsStreamDestination, + LogsStreamHistory, MonitorDashboard, MonitorService, ) @@ -21,6 +22,7 @@ LogsStreamType, TrafficPeakDestinationAuthentication, TrafficPeakLogsDestinationDetails, + VpnGatewayLogsStreamDetails, ) @@ -139,7 +141,6 @@ def test_specific_service_details(self): self.assertEqual(data.alert.scope, ["entity"]) def test_metric_definitions(self): - metrics = self.client.monitor.metric_definitions(service_type="dbaas") self.assertEqual( metrics[0].available_aggregate_functions, @@ -158,7 +159,6 @@ def test_metric_definitions(self): ) def test_create_token(self): - with self.mock_post("/monitor/services/dbaas/token") as m: self.client.monitor.create_token( service_type="dbaas", entity_ids=[189690, 188020] @@ -906,3 +906,136 @@ def test_create_audit_logs_stream_omits_details(self): ) self.assertNotIn("details", m.call_data) + + +class VpnGatewayLogsStreamTest(ClientBaseCase): + def test_load_vpn_gateway_stream_details(self): + for stream_type in ( + "vpngw_ipsec_logs", + "vpngw_bgp_logs", + ): + with self.subTest(stream_type=stream_type): + response = { + "id": 5, + "type": stream_type, + "details": { + "vpn_gateway_ids": [50, 60], + }, + } + + stream = LogsStream(self.client, 5, response) + + self.assertIsInstance( + stream.details, VpnGatewayLogsStreamDetails + ) + self.assertEqual(stream.details.vpn_gateway_ids, [50, 60]) + + def test_create_vpn_gateway_stream(self): + for stream_type in ( + LogsStreamType.vpngw_ipsec_logs, + LogsStreamType.vpngw_bgp_logs, + ): + with self.subTest(stream_type=stream_type): + response = { + "id": 5, + "label": "VPN stream", + "type": stream_type.value, + "status": "active", + "details": { + "vpn_gateway_ids": [50, 60], + }, + } + + with self.mock_post(response) as mock: + stream = self.client.monitor.stream_create( + destinations=[1], + label="VPN stream", + type=stream_type, + status="active", + details=VpnGatewayLogsStreamDetails( + vpn_gateway_ids=[50, 60], + ), + ) + + self.assertEqual(mock.call_url, "/monitor/streams") + self.assertEqual( + mock.call_data, + { + "label": "VPN stream", + "type": stream_type.value, + "status": "active", + "destinations": [1], + "details": { + "vpn_gateway_ids": [50, 60], + }, + }, + ) + self.assertIsInstance( + stream.details, VpnGatewayLogsStreamDetails + ) + self.assertEqual(stream.details.vpn_gateway_ids, [50, 60]) + + def test_update_vpn_gateway_stream(self): + for stream_type in ( + "vpngw_ipsec_logs", + "vpngw_bgp_logs", + ): + with self.subTest(stream_type=stream_type): + stream = LogsStream( + self.client, + 5, + { + "id": 5, + "label": "VPN stream", + "type": stream_type, + "status": "active", + "details": { + "vpn_gateway_ids": [50, 60], + }, + }, + ) + + stream.details = VpnGatewayLogsStreamDetails( + vpn_gateway_ids=[50, 70], + ) + + with self.mock_put({}) as mock: + saved = stream.save() + + self.assertTrue(saved) + self.assertEqual(mock.call_url, "/monitor/streams/5") + self.assertEqual( + mock.call_data, + { + "label": "VPN stream", + "status": "active", + "details": { + "vpn_gateway_ids": [50, 70], + }, + }, + ) + + def test_load_vpn_gateway_stream_history_details(self): + for stream_type in ( + "vpngw_ipsec_logs", + "vpngw_bgp_logs", + ): + with self.subTest(stream_type=stream_type): + snapshot = LogsStreamHistory( + self.client, + 5, + { + "id": 5, + "type": stream_type, + "version": 1, + "details": { + "vpn_gateway_ids": [50, 60], + }, + }, + ) + + self.assertEqual(snapshot.version, 1) + self.assertIsInstance( + snapshot.details, VpnGatewayLogsStreamDetails + ) + self.assertEqual(snapshot.details.vpn_gateway_ids, [50, 60])