14132 api / graphql

This commit is contained in:
Arthur 2023-10-31 10:21:02 -07:00
parent e0b10c984b
commit f650f88806
4 changed files with 44 additions and 7 deletions

View File

@ -39,6 +39,7 @@ __all__ = (
'CustomFieldSerializer',
'CustomLinkSerializer',
'DashboardSerializer',
'EventRuleSerializer',
'ExportTemplateSerializer',
'ImageAttachmentSerializer',
'JournalEntrySerializer',
@ -58,22 +59,38 @@ __all__ = (
#
# Webhooks
# Event Rules
#
class WebhookSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(view_name='extras-api:webhook-detail')
class EventRuleSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(view_name='extras-api:eventrule-detail')
content_types = ContentTypeField(
queryset=ContentType.objects.filter(FeatureQuery('webhooks').get_query()),
many=True
)
class Meta:
model = Webhook
model = EventRule
fields = [
'id', 'url', 'display', 'content_types', 'name', 'type_create', 'type_update', 'type_delete',
'type_job_start', 'type_job_end', 'payload_url', 'enabled', 'http_method', 'http_content_type',
'additional_headers', 'body_template', 'secret', 'conditions', 'ssl_verification', 'ca_file_path',
'type_job_start', 'type_job_end', 'enabled', 'conditions', 'event_type',
'custom_fields', 'tags', 'created', 'last_updated',
]
#
# Webhooks
#
class WebhookSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(view_name='extras-api:webhook-detail')
class Meta:
model = Webhook
fields = [
'id', 'url', 'display',
'payload_url', 'http_method', 'http_content_type',
'additional_headers', 'body_template', 'secret', 'ssl_verification', 'ca_file_path',
'custom_fields', 'tags', 'created', 'last_updated',
]

View File

@ -7,6 +7,7 @@ from . import views
router = NetBoxRouter()
router.APIRootView = views.ExtrasRootView
router.register('event-rules', views.EventRuleViewSet)
router.register('webhooks', views.WebhookViewSet)
router.register('custom-fields', views.CustomFieldViewSet)
router.register('custom-field-choice-sets', views.CustomFieldChoiceSetViewSet)

View File

@ -37,6 +37,17 @@ class ExtrasRootView(APIRootView):
return 'Extras'
#
# EventRules
#
class EventRuleViewSet(NetBoxModelViewSet):
metadata_class = ContentTypeMetadata
queryset = EventRule.objects.all()
serializer_class = serializers.EventRuleSerializer
filterset_class = filtersets.EventRuleFilterSet
#
# Webhooks
#

View File

@ -8,6 +8,7 @@ __all__ = (
'CustomFieldChoiceSetType',
'CustomFieldType',
'CustomLinkType',
'EventRuleType',
'ExportTemplateType',
'ImageAttachmentType',
'JournalEntryType',
@ -110,5 +111,12 @@ class WebhookType(OrganizationalObjectType):
class Meta:
model = models.Webhook
exclude = ('content_types', )
filterset_class = filtersets.WebhookFilterSet
class EventRuleType(OrganizationalObjectType):
class Meta:
model = models.EventRule
exclude = ('content_types', )
filterset_class = filtersets.EventRuleFilterSet