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

Skip to content
Snippets Groups Projects
Verified Commit ad1add33 authored by Vincent SIMONIN's avatar Vincent SIMONIN
Browse files

:sparkles: Add new mapping property `protocol`

parent 5d75e15e
No related branches found
No related tags found
1 merge request!53✨ Add new mapping property `protocol`
Pipeline #113031 passed
Showing with 225 additions and 11 deletions
......@@ -123,6 +123,7 @@ class MappingSerializer(NetBoxModelSerializer):
"proxy_cache",
"proxy_read_timeout",
"client_max_body_size",
"protocol",
"sorry_page",
"custom_fields",
"created",
......
......@@ -17,6 +17,7 @@ class MappingFilterSet(NetBoxModelFilterSet):
"target",
"Comment",
"webdav",
"protocol",
"testingpage",
"gzip_proxied",
"keepalive_requests",
......@@ -24,7 +25,7 @@ class MappingFilterSet(NetBoxModelFilterSet):
"proxy_cache",
"proxy_read_timeout",
"client_max_body_size",
"sorry_page"
"sorry_page",
)
# pylint: disable=W0613
......
......@@ -12,6 +12,7 @@ from utilities.forms import BOOLEAN_WITH_BLANK_CHOICES, add_blank_choice
from .models import (
Mapping,
AuthenticationChoices,
ProtocolChoices,
HttpHeader,
ApplyToChoices,
SamlConfig,
......@@ -29,6 +30,7 @@ class MappingForm(NetBoxModelForm):
"target",
"authentication",
"webdav",
"protocol",
"testingpage",
"gzip_proxied",
"keepalive_requests",
......@@ -55,6 +57,7 @@ class MappingForm(NetBoxModelForm):
"proxy_read_timeout": " Proxy read timeout (s)",
"client_max_body_size": "Client max body size (MB)",
"sorry_page": "Sorry Page URL",
"protocol": "Protocol",
}
......@@ -75,6 +78,10 @@ class MappingFilterForm(NetBoxModelFilterSetForm):
webdav = forms.BooleanField(
required=False, widget=forms.Select(choices=BOOLEAN_WITH_BLANK_CHOICES)
)
protocol = forms.MultipleChoiceField(
choices=ProtocolChoices,
required=False,
)
testingpage = forms.CharField(
max_length=120, min_length=1, required=False, label="Testing URL"
)
......
"""Migration File"""
# pylint: disable=C0103
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
"""Migration Class"""
dependencies = [
("netbox_rps_plugin", "0009_sorry_page"),
]
operations = [
migrations.AlterModelOptions(
name="httpheader",
options={"ordering": ["name"]},
),
migrations.AlterModelOptions(
name="mapping",
options={"ordering": ("source", "target")},
),
migrations.RemoveConstraint(
model_name="httpheader",
name="netbox_rps_plugin_httpheader_unique_mapping_name_apply_to",
),
migrations.AddField(
model_name="mapping",
name="protocol",
field=models.CharField(default="http_https", max_length=32),
),
migrations.AlterField(
model_name="httpheader",
name="apply_to",
field=models.CharField(default="request", max_length=30),
),
migrations.AlterField(
model_name="httpheader",
name="name",
field=models.CharField(max_length=120),
),
migrations.AlterField(
model_name="mapping",
name="authentication",
field=models.CharField(default="none", max_length=30),
),
migrations.AlterField(
model_name="mapping",
name="client_max_body_size",
field=models.IntegerField(
default=1,
validators=[
django.core.validators.MinValueValidator(1),
django.core.validators.MaxValueValidator(255),
],
),
),
migrations.AlterField(
model_name="mapping",
name="keepalive_requests",
field=models.IntegerField(
default=1000,
validators=[
django.core.validators.MinValueValidator(100),
django.core.validators.MaxValueValidator(5000),
],
),
),
migrations.AlterField(
model_name="mapping",
name="keepalive_timeout",
field=models.IntegerField(
default=75,
validators=[
django.core.validators.MinValueValidator(1),
django.core.validators.MaxValueValidator(300),
],
),
),
migrations.AlterField(
model_name="mapping",
name="proxy_read_timeout",
field=models.IntegerField(
default=60,
validators=[
django.core.validators.MinValueValidator(1),
django.core.validators.MaxValueValidator(300),
],
),
),
migrations.AlterField(
model_name="mapping",
name="source",
field=models.CharField(
max_length=2000,
unique=True,
validators=[
django.core.validators.URLValidator(message="It must be a url")
],
),
),
migrations.AlterField(
model_name="mapping",
name="target",
field=models.CharField(
max_length=2000,
validators=[
django.core.validators.URLValidator(message="It must be a url")
],
),
),
migrations.AlterField(
model_name="mapping",
name="testingpage",
field=models.CharField(
blank=True,
max_length=2000,
null=True,
validators=[
django.core.validators.URLValidator(message="It must be a url")
],
),
),
migrations.AlterField(
model_name="samlconfig",
name="acs_url",
field=models.CharField(
max_length=2000,
validators=[
django.core.validators.URLValidator(message="It must be a url")
],
),
),
migrations.AlterField(
model_name="samlconfig",
name="logout_url",
field=models.CharField(
max_length=2000,
validators=[
django.core.validators.URLValidator(message="It must be a url")
],
),
),
migrations.AlterField(
model_name="samlconfig",
name="mapping",
field=models.OneToOneField(
db_column="mapping_id",
on_delete=django.db.models.deletion.CASCADE,
related_name="saml_config",
to="netbox_rps_plugin.mapping",
),
),
migrations.AlterUniqueTogether(
name="httpheader",
unique_together={("mapping", "name", "apply_to")},
),
]
......@@ -38,6 +38,19 @@ class ApplyToChoices(ChoiceSet):
]
class ProtocolChoices(ChoiceSet):
"""Protocol choices definition class"""
key = "Mapping.protocol"
DEFAULT_VALUE = "http_https"
CHOICES = [
("http_https", "HTTP / HTTPS", "dark"),
("websocket", "Websocket", "blue"),
]
class Mapping(NetBoxModel):
"""Mapping definition class"""
......@@ -92,6 +105,13 @@ class Mapping(NetBoxModel):
validators=[URLValidator(message="It must be a url")],
default=DEFAULT_SORRY_PAGE,
)
protocol = models.CharField(
max_length=32,
choices=ProtocolChoices,
default=ProtocolChoices.DEFAULT_VALUE,
blank=False,
verbose_name="Protocol",
)
class Meta:
ordering = ("source", "target")
......
......@@ -10,19 +10,16 @@ class MappingIndex(SearchIndex):
model = Mapping
fields = (
('source', 120),
('target', 120),
('authentication', 30),
('Comment', 500),
("source", 120),
("target", 120),
("authentication", 30),
("Comment", 500),
)
@register_search
class HttpHeaderIndex(SearchIndex):
"""Mapping search definition class"""
model = HttpHeader
fields = (
('name', 120),
('value', 256),
('apply_to', 8)
)
fields = (("name", 120), ("value", 256), ("apply_to", 8))
......@@ -27,6 +27,7 @@ class MappingTable(NetBoxTable):
"authentication",
"testingpage",
"webdav",
"protocol",
"Comment",
"gzip_proxied",
"keepalive_requests",
......@@ -45,6 +46,7 @@ class MappingTable(NetBoxTable):
"target",
"authentication",
"webdav",
"protocol",
"gzip_proxied",
"keepalive_requests",
"keepalive_timeout",
......
......@@ -56,7 +56,7 @@
</tr>
<tr>
<th scope="row">Authentication</th>
<td>{{ object.authentication }}</td>
<td>{{ object.get_authentication_display|placeholder }}</td>
</tr>
<tr>
<th scope="row">Testing page</th>
......@@ -66,6 +66,10 @@
<th scope="row">Webdav</th>
<td>{{ object.webdav|yesno }}</td>
</tr>
<tr>
<th scope="row">Protocol</th>
<td>{{ object.get_protocol_display|placeholder }}</td>
</tr>
<tr>
<th scope="row">Comment</th>
<td>
......
......@@ -34,6 +34,28 @@ class TestMappingCreation(Base):
self.mapping_id = json.loads(response.content)["id"]
def test_that_properties_mapping_default_value_is_set(self) -> None:
"""Test that properties mapping default value is set"""
response = requests.post(
url=f"http://{HOST}:{PORT}/api/plugins/rps/mapping/",
json={
"source": "https://truc00.com/api",
"target": "http://10.10.10.10:1800/api",
},
headers={"Authorization": f"Token {API_KEY}"},
timeout=5,
)
self.assertEqual(response.status_code, 201)
self.mapping_id = json.loads(response.content)["id"]
content = json.loads(response.content)
self.assertEqual(content["authentication"], "none")
self.assertEqual(content["protocol"], "http_https")
if __name__ == "__main__":
unittest.main()
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