Repository: SaaShup/netbox-docker-plugin (language: python)

Issue:
Add Image property Digest
varchar(512) nullable

Only updated by api


Discussion / hints:

Fix patch:
diff --git a/netbox_docker_plugin/api/serializers.py b/netbox_docker_plugin/api/serializers.py
index f8984ee..0fc5467 100644
--- a/netbox_docker_plugin/api/serializers.py
+++ b/netbox_docker_plugin/api/serializers.py
@@ -63,6 +63,7 @@ class Meta:
             "version",
             "size",
             "ImageID",
+            "Digest",
         )
 
 
@@ -203,6 +204,7 @@ class Meta:
             "registry",
             "size",
             "ImageID",
+            "Digest",
             "custom_fields",
             "created",
             "last_updated",
diff --git a/netbox_docker_plugin/migrations/0026_image_digest.py b/netbox_docker_plugin/migrations/0026_image_digest.py
new file mode 100644
index 0000000..a052abb
--- /dev/null
+++ b/netbox_docker_plugin/migrations/0026_image_digest.py
@@ -0,0 +1,29 @@
+# pylint: disable=C0103
+"""Migration file"""
+
+import django.core.validators
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+    """Migration file"""
+
+    dependencies = [
+        ("netbox_docker_plugin", "0025_alter_image_version"),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name="image",
+            name="Digest",
+            field=models.CharField(
+                blank=True,
+                max_length=512,
+                null=True,
+                validators=[
+                    django.core.validators.MinLengthValidator(limit_value=1),
+                    django.core.validators.MaxLengthValidator(limit_value=512),
+                ],
+            ),
+        ),
+    ]
diff --git a/netbox_docker_plugin/models/image.py b/netbox_docker_plugin/models/image.py
index 893eb5f..5d2b402 100644
--- a/netbox_docker_plugin/models/image.py
+++ b/netbox_docker_plugin/models/image.py
@@ -53,6 +53,15 @@ class Image(NetBoxModel):
         blank=True,
         null=True,
     )
+    Digest = models.CharField(
+        max_length=512,
+        validators=[
+            MinLengthValidator(limit_value=1),
+            MaxLengthValidator(limit_value=512),
+        ],
+        blank=True,
+        null=True,
+    )
 
     class Meta:
         """Image Model Meta Class"""
diff --git a/netbox_docker_plugin/templates/netbox_docker_plugin/image.html b/netbox_docker_plugin/templates/netbox_docker_plugin/image.html
index f4ac3f3..91fadf8 100644
--- a/netbox_docker_plugin/templates/netbox_docker_plugin/image.html
+++ b/netbox_docker_plugin/templates/netbox_docker_plugin/image.html
@@ -29,6 +29,16 @@ <h5 class="card-header">IMAGE</h5>
             <th scope="row">ImageID</th>
             <td>{{ object.ImageID|placeholder }}</td>
           </tr>
+          <tr>
+            <th scope="row">Digest</th>
+            <td>
+              {% if object.Digest is None %}
+                {{ object.Digest|placeholder }}
+              {% else %}
+                {{ object.Digest|truncatechars:32 }}
+              {% endif %}
+            </td>
+          </tr>
         </table>
       </div>
     </div>


Test patch:
diff --git a/netbox_docker_plugin/tests/image/test_image_api.py b/netbox_docker_plugin/tests/image/test_image_api.py
index 5ea7a16..df5f1de 100644
--- a/netbox_docker_plugin/tests/image/test_image_api.py
+++ b/netbox_docker_plugin/tests/image/test_image_api.py
@@ -19,6 +19,7 @@ class ImageApiTestCase(
 
     model = Image
     brief_fields = [
+        "Digest",
         "ImageID",
         "display",
         "id",