mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 09:16:10 -06:00
Replace auth & git branch fields with general-purpose parameters
This commit is contained in:
parent
9eafac8ade
commit
78c31a2c36
@ -31,10 +31,9 @@ class DataSourceSerializer(NetBoxModelSerializer):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = DataSource
|
model = DataSource
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display', 'name', 'type', 'url', 'enabled', 'status', 'description', 'git_branch',
|
'id', 'url', 'display', 'name', 'type', 'url', 'enabled', 'status', 'description', 'parameters',
|
||||||
'ignore_rules', 'username', 'password', 'created', 'last_updated', 'file_count',
|
'ignore_rules', 'created', 'last_updated', 'file_count',
|
||||||
]
|
]
|
||||||
extra_kwargs = {'password': {'write_only': True}}
|
|
||||||
|
|
||||||
|
|
||||||
class DataFileSerializer(NetBoxModelSerializer):
|
class DataFileSerializer(NetBoxModelSerializer):
|
||||||
|
@ -16,7 +16,7 @@ class DataSourceFilterSet(ChangeLoggedModelFilterSet):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = DataSource
|
model = DataSource
|
||||||
fields = ('id', 'name', 'type', 'enabled', 'status', 'git_branch', 'username')
|
fields = ('id', 'name', 'type', 'enabled', 'status')
|
||||||
|
|
||||||
def search(self, queryset, name, value):
|
def search(self, queryset, name, value):
|
||||||
if not value.strip():
|
if not value.strip():
|
||||||
|
@ -29,29 +29,18 @@ class DataSourceBulkEditForm(NetBoxModelBulkEditForm):
|
|||||||
max_length=200,
|
max_length=200,
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
git_branch = forms.CharField(
|
parameters = forms.JSONField(
|
||||||
max_length=100,
|
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
ignore_rules = forms.CharField(
|
ignore_rules = forms.CharField(
|
||||||
required=False,
|
required=False,
|
||||||
widget=forms.Textarea()
|
widget=forms.Textarea()
|
||||||
)
|
)
|
||||||
username = forms.CharField(
|
|
||||||
max_length=100,
|
|
||||||
required=False
|
|
||||||
)
|
|
||||||
password = forms.CharField(
|
|
||||||
max_length=100,
|
|
||||||
required=False,
|
|
||||||
widget=forms.PasswordInput()
|
|
||||||
)
|
|
||||||
|
|
||||||
model = DataSource
|
model = DataSource
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
(None, ('type', 'enabled', 'description', 'git_branch', 'ignore_rules')),
|
(None, ('type', 'enabled', 'description', 'parameters', 'ignore_rules')),
|
||||||
('Authentication', ('username', 'password')),
|
|
||||||
)
|
)
|
||||||
nullable_fields = (
|
nullable_fields = (
|
||||||
'description', 'description', 'git_branch', 'ignore_rules', 'username', 'password',
|
'description', 'description', 'parameters', 'parameters', 'ignore_rules',
|
||||||
)
|
)
|
||||||
|
@ -11,5 +11,5 @@ class DataSourceImportForm(NetBoxModelImportForm):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = DataSource
|
model = DataSource
|
||||||
fields = (
|
fields = (
|
||||||
'name', 'type', 'url', 'enabled', 'description', 'git_branch', 'ignore_rules', 'username', 'password',
|
'name', 'type', 'url', 'enabled', 'description', 'parameters', 'ignore_rules',
|
||||||
)
|
)
|
||||||
|
@ -18,20 +18,21 @@ class DataSourceFilterForm(NetBoxModelFilterSetForm):
|
|||||||
model = DataSource
|
model = DataSource
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
(None, ('q', 'filter_id')),
|
(None, ('q', 'filter_id')),
|
||||||
('Data Source', ('type', 'git_branch')),
|
('Data Source', ('type', 'status')),
|
||||||
('Authentication', ('username',)),
|
|
||||||
)
|
)
|
||||||
type = MultipleChoiceField(
|
type = MultipleChoiceField(
|
||||||
choices=DataSourceTypeChoices,
|
choices=DataSourceTypeChoices,
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
git_branch = forms.CharField(
|
status = MultipleChoiceField(
|
||||||
max_length=100,
|
choices=DataSourceStatusChoices,
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
username = forms.CharField(
|
enabled = forms.NullBooleanField(
|
||||||
max_length=100,
|
required=False,
|
||||||
required=False
|
widget=StaticSelect(
|
||||||
|
choices=BOOLEAN_WITH_BLANK_CHOICES
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -46,25 +47,3 @@ class DataFileFilterForm(NetBoxModelFilterSetForm):
|
|||||||
required=False,
|
required=False,
|
||||||
label=_('Data source')
|
label=_('Data source')
|
||||||
)
|
)
|
||||||
type = MultipleChoiceField(
|
|
||||||
choices=DataSourceTypeChoices,
|
|
||||||
required=False
|
|
||||||
)
|
|
||||||
enabled = forms.NullBooleanField(
|
|
||||||
required=False,
|
|
||||||
widget=StaticSelect(
|
|
||||||
choices=BOOLEAN_WITH_BLANK_CHOICES
|
|
||||||
)
|
|
||||||
)
|
|
||||||
status = MultipleChoiceField(
|
|
||||||
choices=DataSourceStatusChoices,
|
|
||||||
required=False
|
|
||||||
)
|
|
||||||
git_branch = forms.CharField(
|
|
||||||
max_length=100,
|
|
||||||
required=False
|
|
||||||
)
|
|
||||||
username = forms.CharField(
|
|
||||||
max_length=100,
|
|
||||||
required=False
|
|
||||||
)
|
|
||||||
|
@ -9,14 +9,13 @@ __all__ = (
|
|||||||
class DataSourceForm(NetBoxModelForm):
|
class DataSourceForm(NetBoxModelForm):
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
('Source', ('name', 'type', 'url', 'enabled', 'description')),
|
('Source', ('name', 'type', 'url', 'enabled', 'description')),
|
||||||
('Git', ('git_branch',)),
|
('Backend', ('parameters', 'ignore_rules')),
|
||||||
('Authentication', ('username', 'password')),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = DataSource
|
model = DataSource
|
||||||
fields = [
|
fields = [
|
||||||
'name', 'type', 'url', 'enabled', 'description', 'git_branch', 'ignore_rules', 'username', 'password',
|
'name', 'type', 'url', 'enabled', 'description', 'parameters', 'ignore_rules',
|
||||||
]
|
]
|
||||||
widgets = {
|
widgets = {
|
||||||
'type': StaticSelect(),
|
'type': StaticSelect(),
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
# Generated by Django 4.1.5 on 2023-01-30 21:49
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('core', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='datasource',
|
||||||
|
name='git_branch',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='datasource',
|
||||||
|
name='password',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='datasource',
|
||||||
|
name='username',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='datasource',
|
||||||
|
name='parameters',
|
||||||
|
field=models.JSONField(blank=True, null=True),
|
||||||
|
),
|
||||||
|
]
|
@ -58,22 +58,13 @@ class DataSource(ChangeLoggedModel):
|
|||||||
max_length=200,
|
max_length=200,
|
||||||
blank=True
|
blank=True
|
||||||
)
|
)
|
||||||
git_branch = models.CharField(
|
|
||||||
max_length=100,
|
|
||||||
blank=True,
|
|
||||||
help_text=_("Branch to check out for git sources (if not using the default)")
|
|
||||||
)
|
|
||||||
ignore_rules = models.TextField(
|
ignore_rules = models.TextField(
|
||||||
blank=True,
|
blank=True,
|
||||||
help_text=_("Patterns (one per line) matching files to ignore when syncing")
|
help_text=_("Patterns (one per line) matching files to ignore when syncing")
|
||||||
)
|
)
|
||||||
username = models.CharField(
|
parameters = models.JSONField(
|
||||||
max_length=100,
|
blank=True,
|
||||||
blank=True
|
null=True
|
||||||
)
|
|
||||||
password = models.CharField(
|
|
||||||
max_length=100,
|
|
||||||
blank=True
|
|
||||||
)
|
)
|
||||||
last_synced = models.DateTimeField(
|
last_synced = models.DateTimeField(
|
||||||
blank=True,
|
blank=True,
|
||||||
@ -137,8 +128,9 @@ class DataSource(ChangeLoggedModel):
|
|||||||
DataSourceTypeChoices.LOCAL: LocalBakend,
|
DataSourceTypeChoices.LOCAL: LocalBakend,
|
||||||
DataSourceTypeChoices.GIT: GitBackend,
|
DataSourceTypeChoices.GIT: GitBackend,
|
||||||
}.get(self.type)
|
}.get(self.type)
|
||||||
|
backend_params = self.parameters or {}
|
||||||
|
|
||||||
return backend_cls(self.url)
|
return backend_cls(self.url, **backend_params)
|
||||||
|
|
||||||
def sync(self):
|
def sync(self):
|
||||||
"""
|
"""
|
||||||
|
@ -23,7 +23,7 @@ class DataSourceTable(NetBoxTable):
|
|||||||
class Meta(NetBoxTable.Meta):
|
class Meta(NetBoxTable.Meta):
|
||||||
model = DataSource
|
model = DataSource
|
||||||
fields = (
|
fields = (
|
||||||
'pk', 'id', 'name', 'type', 'status', 'enabled', 'url', 'description', 'git_branch', 'username', 'created',
|
'pk', 'id', 'name', 'type', 'status', 'enabled', 'url', 'description', 'parameters', 'created',
|
||||||
'last_updated', 'file_count',
|
'last_updated', 'file_count',
|
||||||
)
|
)
|
||||||
default_columns = ('pk', 'name', 'type', 'status', 'enabled', 'description', 'file_count')
|
default_columns = ('pk', 'name', 'type', 'status', 'enabled', 'description', 'file_count')
|
||||||
|
@ -58,19 +58,6 @@
|
|||||||
<a href="{{ object.url }}">{{ object.url }}</a>
|
<a href="{{ object.url }}">{{ object.url }}</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
|
||||||
<th scope="row">Git branch</th>
|
|
||||||
<td>{{ object.git_branch|placeholder }}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Ignore rules</th>
|
|
||||||
<td>
|
|
||||||
{% if object.ignore_rules %}
|
|
||||||
<pre>{{ object.ignore_rules }}</pre>
|
|
||||||
{% else %}
|
|
||||||
{{ ''|placeholder }}
|
|
||||||
{% endif %}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">File count</th>
|
<th scope="row">File count</th>
|
||||||
<td>{{ object.datafiles.count }}</td>
|
<td>{{ object.datafiles.count }}</td>
|
||||||
@ -82,16 +69,26 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col col-md-6">
|
<div class="col col-md-6">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h5 class="card-header">Authentication</h5>
|
<h5 class="card-header">Backend</h5>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<table class="table table-hover attr-table">
|
<table class="table table-hover attr-table">
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Username</th>
|
<th scope="row">Parameters</th>
|
||||||
<td>{{ object.username|placeholder }}</td>
|
<td>
|
||||||
|
{% if object.parameters %}
|
||||||
|
<pre>{{ object.parameters }}</pre>
|
||||||
|
{% else %}
|
||||||
|
{{ ''|placeholder }}
|
||||||
|
{% endif %}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Password</th>
|
<th scope="row">Ignore rules</th>
|
||||||
<td>{% if object.password %}********{% else %}{{ ''|placeholder }}{% endif %}</td>
|
<td>
|
||||||
|
{% if object.ignore_rules %}
|
||||||
|
<pre>{{ object.ignore_rules }}</pre>
|
||||||
|
{% else %}
|
||||||
|
{{ ''|placeholder }}
|
||||||
|
{% endif %}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user