Skip to content

Commit 7836172

Browse files
committed
ACLP Logs - Extend Stream API with lke_audit_logs_type, reorder tests
1 parent 29fe847 commit 7836172

4 files changed

Lines changed: 284 additions & 203 deletions

File tree

linode_api4/groups/monitor.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from linode_api4.objects.monitor import (
2222
AkamaiObjectStorageLogsDestinationDetails,
2323
CustomHTTPSLogsDestinationDetails,
24+
LogsStreamDetails,
2425
)
2526

2627
__all__ = [
@@ -475,34 +476,49 @@ def stream_create(
475476
label: str,
476477
type: Union[LogsStreamType, str],
477478
status: Optional[Union[LogsStreamStatus, str]] = None,
479+
details: Optional[LogsStreamDetails] = None,
478480
) -> LogsStream:
479481
"""
480-
Creates a new :any:`LogsStream` for logs on this account with
481-
the given label, type, and object storage details. For example::
482+
Creates a new :any:`LogsStream` for logs on this account. For example::
482483
483484
client = LinodeClient(TOKEN)
484485
486+
# audit_logs stream (no details required)
485487
new_stream = client.monitor.stream_create(
486-
destinations= [1234],
488+
destinations=[1234],
487489
label="Linode_services",
488490
status="active",
489491
type="audit_logs"
490-
)
492+
)
493+
494+
# lke_audit_logs stream with specific clusters
495+
lke_stream = client.monitor.stream_create(
496+
destinations=[1234],
497+
label="LKE_audit_stream",
498+
type="lke_audit_logs",
499+
details=LogsStreamDetails(
500+
cluster_ids=[1111, 2222],
501+
is_auto_add_all_clusters_enabled=False,
502+
)
503+
)
491504
492505
API Documentation: https://techdocs.akamai.com/linode-api/reference/post-stream
493506
494-
:param destinations: List of unique identifiers for the sync points that will receive logs data.
507+
:param destinations: The unique identifier for the sync point that will receive logs data.
495508
Run the List destinations operation and store the id values for each applicable destination.
496509
At the moment only single destination is supported.
497510
:type destinations: list[int]
498511
:param label: The name of the stream. This is used for display purposes in Akamai Cloud Manager.
499512
:type label: str
500-
:param type: The type of stream. Set this to ``audit_logs`` for logs consisting of all the control plane
501-
operations for the services in your Linodes.
502-
:type type: str
513+
:param type: The type of stream``audit_logs`` for Linode control plane logs,
514+
or ``lke_audit_logs`` for LKE enterprise cluster audit logs.
515+
:type type: str or LogsStreamType
503516
:param status: (Optional) The availability status of the stream. Possible values are: ``active``, ``inactive``.
504517
Defaults to ``active``.
505518
:type status: str
519+
:param details: (Optional) Additional stream details. Only applicable for
520+
``lke_audit_logs`` streams. Omit for ``audit_logs`` streams.
521+
:type details: LogsStreamDetails
506522
507523
:returns: The newly created logs stream.
508524
:rtype: LogsStream
@@ -517,6 +533,9 @@ def stream_create(
517533
if status is not None:
518534
params["status"] = status
519535

536+
if details is not None:
537+
params["details"] = details.dict
538+
520539
result = self.client.post("/monitor/streams", data=params)
521540

522541
if "id" not in result:

linode_api4/objects/monitor.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"LogsStreamHistory",
3232
"LogsStreamType",
3333
"LogsStreamStatus",
34+
"LogsStreamDetails",
3435
"LogsStreamDestination",
3536
]
3637

@@ -753,6 +754,34 @@ class LogsStreamStatus(StrEnum):
753754

754755
class LogsStreamType(StrEnum):
755756
audit_logs = "audit_logs"
757+
lke_audit_logs = "lke_audit_logs"
758+
759+
760+
@dataclass
761+
class LogsStreamDetails(JSONObject):
762+
"""
763+
Additional details for a logs stream.
764+
765+
This object only applies to streams with a ``type`` of ``lke_audit_logs``.
766+
Leave it out of requests that use a ``type`` of ``audit_logs``.
767+
768+
.. note::
769+
When updating a stream, any existing settings need to be included to
770+
maintain them. For example, if you're adding new ``cluster_ids`` to the
771+
stream, you also need to include any existing ones to maintain them.
772+
Run the Get a stream operation to review the existing ``details``
773+
settings for a stream before submitting an update.
774+
775+
Fields:
776+
- cluster_ids: List of LKE enterprise cluster IDs to include in the stream.
777+
Cannot be used when ``is_auto_add_all_clusters_enabled`` is ``True``.
778+
- is_auto_add_all_clusters_enabled: When ``True``, newly added LKE enterprise
779+
clusters on the account are automatically
780+
included in the stream.
781+
"""
782+
783+
cluster_ids: Optional[List[int]] = None
784+
is_auto_add_all_clusters_enabled: bool = False
756785

757786

758787
@dataclass
@@ -794,6 +823,7 @@ class LogsStreamHistory(Base):
794823
"created": Property(is_datetime=True),
795824
"created_by": Property(),
796825
"destinations": Property(json_object=LogsStreamDestination),
826+
"details": Property(json_object=LogsStreamDetails),
797827
"id": Property(identifier=True),
798828
"label": Property(),
799829
"status": Property(),
@@ -817,6 +847,7 @@ class LogsStream(Base):
817847
"created": Property(is_datetime=True),
818848
"created_by": Property(),
819849
"destinations": Property(json_object=LogsStreamDestination),
850+
"details": Property(mutable=True, json_object=LogsStreamDetails),
820851
"id": Property(identifier=True),
821852
"label": Property(mutable=True),
822853
"status": Property(mutable=True),
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"id": 3,
3+
"label": "my-lke-audit-logs-stream",
4+
"type": "lke_audit_logs",
5+
"status": "active",
6+
"destinations": [
7+
{
8+
"id": 1,
9+
"label": "my-logs-destination",
10+
"type": "akamai_object_storage",
11+
"details": {
12+
"access_key_id": "1ABCD23EFG4HIJKLMNO5",
13+
"bucket_name": "primary-bucket",
14+
"host": "primary-bucket.us-east-1.linodeobjects.com",
15+
"path": "audit-logs"
16+
}
17+
}
18+
],
19+
"details": {
20+
"cluster_ids": [1234, 5678],
21+
"is_auto_add_all_clusters_enabled": false
22+
},
23+
"created": "2024-09-01T12:00:00",
24+
"updated": "2024-09-01T12:00:00",
25+
"created_by": "tester",
26+
"updated_by": "tester",
27+
"version": 1
28+
}
29+

0 commit comments

Comments
 (0)