-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
53b5cb5
commit 75c5357
Showing
22 changed files
with
402 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Generated by Django 4.2.7 on 2023-12-03 20:00 | ||
|
||
from django.db import migrations, models | ||
import taggit.managers | ||
import utilities.json | ||
import validity.models.base | ||
import validity.utils.dbfields | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
|
||
|
||
def create_cf(apps, schema_editor): | ||
ContentType = apps.get_model("contenttypes", "ContentType") | ||
CustomField = apps.get_model("extras", "CustomField") | ||
KeyBundle = apps.get_model("validity", "KeyBundle") | ||
Device = apps.get_model("dcim", "Device") | ||
DeviceType = apps.get_model("dcim", "DeviceType") | ||
Manufacturer = apps.get_model("dcim", "Manufacturer") | ||
db_alias = schema_editor.connection.alias | ||
|
||
cf = CustomField.objects.using(db_alias).create( | ||
name="keybundle", | ||
label=_("Key Bundle"), | ||
description=_("Required by Validity. Defines properties of device connection"), | ||
type="object", | ||
object_type=ContentType.objects.get_for_model(KeyBundle), | ||
required=False, | ||
) | ||
cf.content_types.set([ | ||
ContentType.objects.get_for_model(Device), | ||
ContentType.objects.get_for_model(DeviceType), | ||
ContentType.objects.get_for_model(Manufacturer), | ||
]) | ||
|
||
|
||
def delete_cf(apps, schema_editor): | ||
CustomField = apps.get_model("extras", "CustomField") | ||
db_alias = schema_editor.connection.alias | ||
CustomField.objects.using(db_alias).filter(name="keybundle").delete() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("extras", "0098_webhook_custom_field_data_webhook_tags"), | ||
("validity", "0006_script_change"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="KeyBundle", | ||
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(max_length=255)), | ||
("connection_type", models.CharField(max_length=50)), | ||
("public_credentials", models.JSONField(default=dict)), | ||
("private_credentials", validity.utils.dbfields.EncryptedDictField()), | ||
("tags", taggit.managers.TaggableManager(through="extras.TaggedItem", to="extras.Tag")), | ||
], | ||
options={ | ||
"abstract": False, | ||
}, | ||
bases=(validity.models.base.URLMixin, models.Model), | ||
), | ||
migrations.RunPython(create_cf, delete_cf) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from dcim.models import Device | ||
from django.db import models | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from validity.choices import ConnectionTypeChoices | ||
from validity.utils.dbfields import EncryptedDictField | ||
from .base import BaseModel | ||
|
||
|
||
class KeyBundle(BaseModel): | ||
name = models.CharField(_("Name"), max_length=255) | ||
connection_type = models.CharField(_("Connection Type"), max_length=50, choices=ConnectionTypeChoices.choices) | ||
public_credentials = models.JSONField(_("Public Credentials"), default=dict, blank=True) | ||
private_credentials = EncryptedDictField(_("Private Credentials"), blank=True) | ||
|
||
@property | ||
def credentials(self): | ||
return self.public_credentials | self.private_credentials.decrypted | ||
|
||
def get_connection_type_color(self): | ||
return ConnectionTypeChoices.colors.get(self.connection_type) | ||
|
||
@property | ||
def bound_devices(self) -> models.QuerySet[Device]: | ||
from .device import VDevice | ||
|
||
return VDevice.objects.annotate_keybundle_id().filter(keybundle_id=self.pk) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.