Skip to content

Commit 20fdf94

Browse files
committed
webhook channel sdk support
1 parent 1e6dfc1 commit 20fdf94

5 files changed

Lines changed: 32 additions & 31 deletions

File tree

‎linode_api4/groups/monitor.py‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@
2020
)
2121
from linode_api4.objects.monitor import (
2222
AkamaiObjectStorageLogsDestinationDetails,
23-
BasicAuthenticationDetails,
2423
ChannelDetails,
25-
CustomHeader,
2624
CustomHTTPSLogsDestinationDetails,
27-
DestinationAuthentication,
28-
EmailDetails,
2925
LogsStreamDetails,
3026
WebhookDetails,
3127
)
@@ -235,7 +231,7 @@ def channel_create(
235231
- If ``channel_type`` is "webhook", the following are required:
236232
- ``details.webhook.endpoint_url`` must be provided
237233
- ``details.webhook.authentication.type`` must be specified ("basic" or "none")
238-
- If ``authentication.type`` is "basic", both ``basic_authentication_user`` and
234+
- If ``authentication.type`` is "basic", both ``basic_authentication_user`` and
239235
``basic_authentication_password`` must be provided in ``details.webhook.authentication.details``
240236
- Client Certificate Configuration (Optional but must be complete):
241237
- If ``details.webhook.client_certificate_details`` is provided, all three certificates
@@ -315,7 +311,7 @@ def channel_create(
315311
316312
:raises ValueError: If webhook channel configuration is invalid or missing required fields.
317313
"""
318-
from linode_api4.objects.monitor import ChannelDetails
314+
pass
319315

320316
# Validate webhook channel requirements
321317
if channel_type == "webhook":
@@ -324,7 +320,11 @@ def channel_create(
324320
params = {
325321
"label": label,
326322
"channel_type": channel_type,
327-
"details": details._serialize() if hasattr(details, "_serialize") else details,
323+
"details": (
324+
details._serialize()
325+
if hasattr(details, "_serialize")
326+
else details
327+
),
328328
}
329329

330330
result = self.client.post("/monitor/alert-channels", data=params)
@@ -351,9 +351,9 @@ def verify_webhook(
351351
**Webhook Configuration Requirements:**
352352
- ``endpoint_url`` must be provided
353353
- ``authentication.type`` must be specified ("basic" or "none")
354-
- If ``authentication.type`` is "basic", both ``basic_authentication_user`` and
354+
- If ``authentication.type`` is "basic", both ``basic_authentication_user`` and
355355
``basic_authentication_password`` must be provided
356-
- Client certificates (if used) must include all three: ``client_ca_certificate``,
356+
- Client certificates (if used) must include all three: ``client_ca_certificate``,
357357
``client_certificate``, and ``client_private_key``
358358
359359
API Documentation: https://techdocs.akamai.com/linode-api/reference/post-verify-webhook
@@ -367,13 +367,17 @@ def verify_webhook(
367367
:raises ValueError: If webhook configuration is invalid.
368368
:raises ApiError: If the webhook verification fails.
369369
"""
370-
from linode_api4.objects.monitor import WebhookDetails, ChannelDetails
370+
from linode_api4.objects.monitor import ChannelDetails
371371

372372
# Validate webhook configuration
373373
self._validate_webhook_details(ChannelDetails(webhook=webhook))
374374

375375
data = {
376-
"webhook": webhook._serialize() if hasattr(webhook, "_serialize") else webhook,
376+
"webhook": (
377+
webhook._serialize()
378+
if hasattr(webhook, "_serialize")
379+
else webhook
380+
),
377381
}
378382

379383
result = self.client.post("/monitor/alert-channels/verify", data=data)

‎linode_api4/objects/monitor.py‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ class EmailDetails(JSONObject):
562562
class WebhookDetails(JSONObject):
563563
"""
564564
Represents webhook-specific details for an alert channel.
565-
565+
566566
Fields:
567567
- endpoint_url: The URL where webhook events are sent.
568568
- authentication: Authentication configuration for the webhook endpoint.
@@ -614,11 +614,11 @@ class AlertChannel(Base):
614614
615615
This class maps to the Monitor API's `/monitor/alert-channels` resource
616616
and supports full CRUD operations (create, read, update, delete).
617-
617+
618618
Examples:
619619
# List channels
620620
channels = client.monitor.alert_channels()
621-
621+
622622
# Create email channel
623623
channel = client.monitor.channel_create(
624624
label="Support Email",
@@ -630,7 +630,7 @@ class AlertChannel(Base):
630630
)
631631
)
632632
)
633-
633+
634634
# Create webhook channel
635635
channel = client.monitor.channel_create(
636636
label="Webhook Receiver",
@@ -648,11 +648,11 @@ class AlertChannel(Base):
648648
)
649649
)
650650
)
651-
651+
652652
# Update channel
653653
channel.label = "Updated Label"
654654
channel.save()
655-
655+
656656
# Delete channel
657657
channel.delete()
658658
"""
@@ -673,9 +673,6 @@ class AlertChannel(Base):
673673
}
674674

675675

676-
677-
678-
679676
@dataclass
680677
class LogsDestinationDetailsBase(JSONObject):
681678
"""

‎test/integration/models/monitor/test_monitor.py‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
ChannelDetails,
2525
CustomHeader,
2626
DestinationAuthentication,
27-
EmailDetails,
2827
WebhookDetails,
2928
)
3029

@@ -444,12 +443,12 @@ def test_integration_clone_alert_definition(test_linode_client):
444443
def test_webhook_channel_crud(test_linode_client):
445444
"""
446445
Test webhook channel create, verify, and delete operations.
447-
446+
448447
Creates a webhook channel with basic auth, verifies the configuration,
449448
and then deletes the channel.
450449
"""
451450
client = test_linode_client
452-
451+
453452
# Create webhook channel with basic authentication
454453
webhook = client.monitor.channel_create(
455454
label=f"webhook-test-{get_test_label()}",
@@ -471,14 +470,14 @@ def test_webhook_channel_crud(test_linode_client):
471470
)
472471
),
473472
)
474-
473+
475474
assert isinstance(webhook, AlertChannel)
476475
assert webhook.channel_type == "webhook"
477476
assert webhook.details.webhook.endpoint_url == "https://example.com/webhook"
478477
assert webhook.details.webhook.authentication.type == "basic"
479478
assert webhook.details.webhook.data_compression == "gzip"
480479
assert len(webhook.details.webhook.custom_headers) == 1
481-
480+
482481
# Verify webhook configuration
483482
webhook_config = WebhookDetails(
484483
endpoint_url="https://example.com/webhook",
@@ -490,14 +489,14 @@ def test_webhook_channel_crud(test_linode_client):
490489
),
491490
),
492491
)
493-
492+
494493
is_valid = client.monitor.verify_webhook(webhook_config)
495494
assert is_valid is True
496-
495+
497496
# Delete webhook channel
498497
webhook_id = webhook.id
499498
webhook.delete()
500-
499+
501500
# Verify deletion
502501
with pytest.raises(ApiError):
503502
client.load(AlertChannel, webhook_id)

‎test/unit/groups/monitor_api_test.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,9 @@ def test_create_webhook_channel(self):
386386
webhook_channel.details.webhook.endpoint_url
387387
== "https://example.com/webhook"
388388
)
389-
assert webhook_channel.details.webhook.authentication.type == "basic"
389+
assert (
390+
webhook_channel.details.webhook.authentication.type == "basic"
391+
)
390392

391393
def test_verify_webhook_channel(self):
392394
"""

‎test/unit/objects/monitor_test.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
CustomHeader,
1919
CustomHTTPSLogsDestinationDetails,
2020
DestinationAuthentication,
21-
EmailDetails,
2221
LogsDestinationDetailsBase,
2322
LogsStreamDetails,
2423
LogsStreamType,
@@ -199,7 +198,7 @@ def test_alert_channels(self):
199198
def test_webhook_channel_validation(self):
200199
"""
201200
Test webhook channel validation constraints for create and verify operations.
202-
201+
203202
Validates all constraint checks: endpoint_url, authentication.type,
204203
basic auth credentials, client certificates, and custom headers.
205204
"""

0 commit comments

Comments
 (0)