Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit c59d340c authored by Laurent VENIER's avatar Laurent VENIER :speech_balloon:
Browse files

Merge branch 'http_headers_api_integration' into 'main'

Add HTTP Headers API integration for mapping

See merge request !11
parents 85a64e75 63d0eca8
No related branches found
No related tags found
1 merge request!11Add HTTP Headers API integration for mapping
Pipeline #66958 passed
This diff is collapsed.
......@@ -2,7 +2,7 @@ from setuptools import find_packages, setup
setup(
name='netbox-rps-plugin',
version='0.6.0',
version='0.7.0',
description='A Netbox plugin to add RPS resources',
install_requires=[],
packages=find_packages('./src'),
......
......@@ -5,7 +5,7 @@ class NetBoxRpsConfig(PluginConfig):
name = 'netbox_rps_plugin'
verbose_name = 'NetBox RPS'
description = 'A Netbox plugin to add RPS resources'
version = '0.6.0'
version = '0.7.0'
author = "Vincent Simonin"
author_email = "vincent.simonin@ext.ec.europa.eu"
base_url = 'rps'
......
......@@ -2,44 +2,60 @@ from rest_framework import serializers
from ..models import Mapping, HttpHeader
from netbox.api.serializers import NetBoxModelSerializer, WritableNestedSerializer
class HttpHeaderSerializer(NetBoxModelSerializer):
class NestedMappingSerializer(WritableNestedSerializer):
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_rps_plugin-api:httpheader-detail'
view_name='plugins-api:netbox_rps_plugin-api:mapping-detail'
)
class Meta:
model = HttpHeader
fields = ('id', 'name', 'value', 'apply_to')
model = Mapping
fields = ('id', 'url', 'display')
class NestedHttpHeaderSerializer(WritableNestedSerializer):
class HttpHeaderSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_rps_plugin-api:httpheader-detail'
)
mapping = NestedMappingSerializer()
class Meta:
model = HttpHeader
fields = ('id', 'name', 'value', 'apply_to')
fields = ('id', 'url', 'name', 'value', 'apply_to', 'mapping', 'custom_fields', 'created', 'last_updated', 'tags')
class NestedMappingSerializer(WritableNestedSerializer):
class NestedHttpHeaderSerializer(WritableNestedSerializer):
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_rps_plugin-api:mapping-detail'
view_name='plugins-api:netbox_rps_plugin-api:httpheader-detail'
)
class Meta:
model = Mapping
fields = ('id', 'url', 'display')
model = HttpHeader
fields = ('id', 'url', 'name', 'value', 'apply_to')
class MappingSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_rps_plugin-api:mapping-detail'
)
#http_headers = NestedHttpHeaderSerializer()
http_headers = NestedHttpHeaderSerializer(many=True, read_only=True)
class Meta:
model = Mapping
fields = (
'id', 'url', 'display', 'source', 'target', 'authentication', 'testingpage', 'webdav', 'Comment', 'custom_fields', 'created',
'last_updated', 'tags'
'id',
'url',
'display',
'source',
'target',
'authentication',
'testingpage',
'webdav',
'Comment',
'custom_fields',
'created',
'last_updated',
'tags',
'http_headers'
)
......@@ -5,5 +5,6 @@ app_name = 'netbox_rps_plugin'
router = NetBoxRouter()
router.register('mapping', views.MappingViewSet)
router.register('http_header', views.HttpHeaderViewSet)
urlpatterns = router.urls
from netbox.api.viewsets import NetBoxModelViewSet
from .. import filtersets, models
from .serializers import MappingSerializer
from utilities.utils import count_related
from .serializers import MappingSerializer, HttpHeaderSerializer
from django.db.models import Count, OuterRef, Subquery
class MappingViewSet(NetBoxModelViewSet):
queryset = models.Mapping.objects.all()
queryset = models.Mapping.objects.prefetch_related('http_headers', 'tags').all()
serializer_class = MappingSerializer
filterset_class = filtersets.MappingFilterSet
http_method_names = ['get', 'post', 'patch', 'delete']
class HttpHeaderViewSet(NetBoxModelViewSet):
queryset = models.HttpHeader.objects.prefetch_related('mapping','tags').all()
serializer_class = HttpHeaderSerializer
http_method_names = ['get', 'post', 'patch', 'delete']
import django.contrib.postgres.fields
from django.db import migrations, models
import django.db.models.deletion
import taggit.managers
import utilities.json
class Migration(migrations.Migration):
initial = True
dependencies = [
('netbox_rps_plugin', '0001_initial')
]
operations = [
migrations.CreateModel(
name='HttpHeader',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
('created', models.DateTimeField(auto_now_add=True, null=True)),
('last_updated', models.DateTimeField(auto_now=True, null=True)),
('custom_field_data', models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder)),
('name', models.CharField(blank=True, max_length=120)),
('value', models.CharField(blank=True, max_length=120)),
('apply_to', models.CharField(max_length=30)),
('mapping', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='http_headers', to='netbox_rps_plugin.mapping')),
('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')),
],
options={
'ordering': ('name'),
},
),
]
......@@ -19,7 +19,7 @@ class AuthenticationChoices(ChoiceSet):
class ApplyToChoices(ChoiceSet):
key = 'HHttpHeader.applyTo'
key = 'HttpHeader.applyTo'
DEFAULT_VALUE = 'request'
......@@ -59,7 +59,6 @@ class Mapping(NetBoxModel):
webdav = models.BooleanField(
default=False,
)
Comment = models.CharField(
max_length=500,
blank=True
......@@ -78,8 +77,8 @@ class Mapping(NetBoxModel):
return AuthenticationChoices.colors.get(self.authentication)
class HttpHeader(models.Model):
mapping = models.ForeignKey(Mapping, on_delete=models.CASCADE)
class HttpHeader(NetBoxModel):
mapping = models.ForeignKey(Mapping, on_delete=models.CASCADE, related_name='http_headers')
name = models.CharField(
max_length=120,
blank=False,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment