git: 53edd11f9dac - main - security/py-netbox-secretstore: Backport patches and deprecate

From: Kai Knoblich <kai_at_FreeBSD.org>
Date: Thu, 11 May 2023 04:02:27 UTC
The branch main has been updated by kai:

URL: https://cgit.FreeBSD.org/ports/commit/?id=53edd11f9dac25ba3053108406373e6a0550f551

commit 53edd11f9dac25ba3053108406373e6a0550f551
Author:     Kai Knoblich <kai@FreeBSD.org>
AuthorDate: 2023-05-11 03:40:40 +0000
Commit:     Kai Knoblich <kai@FreeBSD.org>
CommitDate: 2023-05-11 03:42:04 +0000

    security/py-netbox-secretstore: Backport patches and deprecate
    
    * Backport a patch of the upstream repository that fixes an issue with
      bulk updates for M2M (= many-to-many) operations.
    
    * Add patches from the py-netbox-secrets repository as well which are
      required to migrate to the py-netbox-secrets plugin.
    
    * Also give some advice how to migrate to the py-netbox-secrets plugin.
    
    * Deprecate and set and an expiration date because upstream no longer
      maintains py-netbox-secretstore which is in its current state not
      compatible with newer releases of NetBox.
    
    * Bump PORTREVISION due package change and to give users a heads-up that
      the plugin is deprecated.
    
    MFH:            2023Q2 (in 3 weeks)
---
 security/py-netbox-secretstore/Makefile            |  5 +-
 ...lter__secret__custom__field__data__and__more.py | 45 ++++++++++++++----
 .../patch-netbox__secretstore_models_secrets.py    | 51 +++++++++++++++++++++
 .../files/patch-netbox__secretstore_views.py       | 33 ++++++++++++++
 .../py-netbox-secretstore/files/pkg-message.in     | 53 ++++++++++++++++++++++
 5 files changed, 176 insertions(+), 11 deletions(-)

diff --git a/security/py-netbox-secretstore/Makefile b/security/py-netbox-secretstore/Makefile
index 6aeed0a86090..aad6bdf31053 100644
--- a/security/py-netbox-secretstore/Makefile
+++ b/security/py-netbox-secretstore/Makefile
@@ -1,6 +1,6 @@
 PORTNAME=	netbox-secretstore
 DISTVERSION=	1.4.1
-PORTREVISION=	1
+PORTREVISION=	2
 CATEGORIES=	security python
 MASTER_SITES=	PYPI
 PKGNAMEPREFIX=	${PYTHON_PKGNAMEPREFIX}
@@ -12,6 +12,9 @@ WWW=		https://github.com/dansheps/netbox-secretstore
 LICENSE=	APACHE20
 LICENSE_FILE=	${WRKSRC}/LICENSE.txt
 
+DEPRECATED=	No longer maintained by upstream, not compatible with NetBox 3.5, please migrate to security/py-netbox-secrets
+EXPIRATION_DATE=	2023-08-15
+
 RUN_DEPENDS=	${PYTHON_PKGNAMEPREFIX}importlib-metadata>0:devel/py-importlib-metadata@${PY_FLAVOR} \
 		${PYTHON_PKGNAMEPREFIX}pycryptodome>0:security/py-pycryptodome@${PY_FLAVOR}
 
diff --git a/security/py-netbox-secretstore/files/patch-netbox__secretstore_migrations_0006__alter__secret__custom__field__data__and__more.py b/security/py-netbox-secretstore/files/patch-netbox__secretstore_migrations_0006__alter__secret__custom__field__data__and__more.py
index ba6e41dd0b31..4da31820f74e 100644
--- a/security/py-netbox-secretstore/files/patch-netbox__secretstore_migrations_0006__alter__secret__custom__field__data__and__more.py
+++ b/security/py-netbox-secretstore/files/patch-netbox__secretstore_migrations_0006__alter__secret__custom__field__data__and__more.py
@@ -6,30 +6,55 @@ Obtained from:
 
 https://github.com/DanSheps/netbox-secretstore/commit/9c3f69e5af6f5e8d6af11f5c8ea41433ef51145c
 
---- netbox_secretstore/migrations/0006_alter_secret_custom_field_data_and_more.py.orig	2023-03-16 06:29:56 UTC
+From: Abhimanyu Saharan <desk.abhimanyu@gmail.com>
+Date: Wed, 12 Apr 2023 21:01:43 +0530
+Subject: [PATCH] fix migrations
+
+Obtained from:
+
+https://github.com/Onemind-Services-LLC/netbox-secretstore/commit/248330409413f1858daf13902fd1b409053fd846.patch
+
+--- netbox_secretstore/migrations/0006_alter_secret_custom_field_data_and_more.py.orig	2023-05-08 17:51:21 UTC
 +++ netbox_secretstore/migrations/0006_alter_secret_custom_field_data_and_more.py
-@@ -0,0 +1,24 @@
-+# Generated by Django 4.1.4 on 2023-01-24 19:50
+@@ -0,0 +1,41 @@
++# Generated by Django 4.1.7 on 2023-04-12 15:31
 +
++from django.conf import settings
 +from django.db import migrations, models
++import django.db.models.deletion
 +import utilities.json
 +
 +
 +class Migration(migrations.Migration):
 +
 +    dependencies = [
-+        ('netbox_secretstore', '0005_alter_secret_created_alter_secret_id_and_more'),
++        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
++        ("netbox_secretstore", "0005_alter_secret_created_alter_secret_id_and_more"),
 +    ]
 +
 +    operations = [
 +        migrations.AlterField(
-+            model_name='secret',
-+            name='custom_field_data',
-+            field=models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder),
++            model_name="secret",
++            name="custom_field_data",
++            field=models.JSONField(
++                blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder
++            ),
++        ),
++        migrations.AlterField(
++            model_name="secretrole",
++            name="custom_field_data",
++            field=models.JSONField(
++                blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder
++            ),
 +        ),
 +        migrations.AlterField(
-+            model_name='secretrole',
-+            name='custom_field_data',
-+            field=models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder),
++            model_name="userkey",
++            name="user",
++            field=models.OneToOneField(
++                editable=False,
++                on_delete=django.db.models.deletion.CASCADE,
++                related_name="user_key_secretstore",
++                to=settings.AUTH_USER_MODEL,
++            ),
 +        ),
 +    ]
diff --git a/security/py-netbox-secretstore/files/patch-netbox__secretstore_models_secrets.py b/security/py-netbox-secretstore/files/patch-netbox__secretstore_models_secrets.py
new file mode 100644
index 000000000000..af682f8b802a
--- /dev/null
+++ b/security/py-netbox-secretstore/files/patch-netbox__secretstore_models_secrets.py
@@ -0,0 +1,51 @@
+From: Abhimanyu Saharan <desk.abhimanyu@gmail.com>
+Date: Wed, 12 Apr 2023 21:01:43 +0530
+Subject: [PATCH] fix migrations
+
+Obtained from:
+
+https://github.com/Onemind-Services-LLC/netbox-secretstore/commit/248330409413f1858daf13902fd1b409053fd846.patch
+
+--- netbox_secretstore/models/secrets.py.orig	2022-12-31 01:50:00 UTC
++++ netbox_secretstore/models/secrets.py
+@@ -21,6 +21,7 @@ from netbox_secretstore.utils import encrypt_master_ke
+ from netbox_secretstore.hashers import SecretValidationHasher
+ from netbox_secretstore.querysets import UserKeyQuerySet
+ from netbox_secretstore.utils import encrypt_master_key, decrypt_master_key, generate_random_key
++from taggit.managers import TaggableManager
+ 
+ 
+ __all__ = (
+@@ -47,7 +48,7 @@ class UserKey(models.Model):
+     user = models.OneToOneField(
+         to=User,
+         on_delete=models.CASCADE,
+-        related_name='user_key',
++        related_name='user_key_secretstore',
+         editable=False
+     )
+     public_key = models.TextField(
+@@ -256,6 +257,11 @@ class SecretRole(OrganizationalModel):
+         blank=True,
+     )
+ 
++    tags = TaggableManager(
++        through='extras.TaggedItem',
++        related_name='netbox_secretstore_secretroles'
++    )
++
+     objects = RestrictedQuerySet.as_manager()
+ 
+     csv_headers = ['name', 'slug', 'description']
+@@ -312,6 +318,11 @@ class Secret(NetBoxModel):
+     hash = models.CharField(
+         max_length=128,
+         editable=False
++    )
++
++    tags = TaggableManager(
++        through='extras.TaggedItem',
++        related_name='netbox_secretstore_secret'
+     )
+ 
+     objects = RestrictedQuerySet.as_manager()
diff --git a/security/py-netbox-secretstore/files/patch-netbox__secretstore_views.py b/security/py-netbox-secretstore/files/patch-netbox__secretstore_views.py
new file mode 100644
index 000000000000..b9f12b55e322
--- /dev/null
+++ b/security/py-netbox-secretstore/files/patch-netbox__secretstore_views.py
@@ -0,0 +1,33 @@
+From: Daniel Sheppard <dans@dansheps.com>
+Date: Tue, 11 Apr 2023 08:34:04 -0500
+Subject: [PATCH] #12087 - Fix Bulk Edit update when M2M operations are present.
+
+Obtained from:
+
+https://github.com/DanSheps/netbox-secretstore/commit/7ad1ba639aa077c45bcac05dc025132c6bd9139e.patch
+
+--- netbox_secretstore/views.py.orig	2022-12-31 01:50:00 UTC
++++ netbox_secretstore/views.py
+@@ -156,15 +156,15 @@ class SecretEditView(ObjectEditView):
+                     secret.plaintext = str(form.cleaned_data['plaintext'])
+                     secret.encrypt(master_key)
+ 
+-            secret.save()
+-            form.save_m2m()
++                    secret.save()
++                    form.save_m2m()
+ 
+-            msg = '{} secret'.format('Created' if not form.instance.pk else 'Modified')
+-            logger.info(f"{msg} {secret} (PK: {secret.pk})")
+-            msg = f'{msg} <a href="{secret.get_absolute_url()}">{escape(secret)}</a>'
+-            messages.success(request, mark_safe(msg))
++                    msg = '{} secret'.format('Created' if not form.instance.pk else 'Modified')
++                    logger.info(f"{msg} {secret} (PK: {secret.pk})")
++                    msg = f'{msg} <a href="{secret.get_absolute_url()}">{escape(secret)}</a>'
++                    messages.success(request, mark_safe(msg))
+ 
+-            return redirect(self.get_return_url(request, secret))
++                    return redirect(self.get_return_url(request, secret))
+ 
+         else:
+             logger.debug("Form validation failed")
diff --git a/security/py-netbox-secretstore/files/pkg-message.in b/security/py-netbox-secretstore/files/pkg-message.in
index 4957b1933eb1..5e2a87dc3ef3 100644
--- a/security/py-netbox-secretstore/files/pkg-message.in
+++ b/security/py-netbox-secretstore/files/pkg-message.in
@@ -54,4 +54,57 @@ EOD
 3. Restart WSGI/httpd environment (supervisord/apache/nginx/etc.)
 EOD
 }
+{ type: upgrade
+  maximum_version: 1.4.2_2
+  message: <<EOD
+Upstream no longer maintains py-netbox-secretstore which it is not compatible
+with NetBox 3.5 or newer.  To ensure compatibility with newer releases of
+NetBox, the py-netbox-secrets plugin should be used instead.
+
+To migrate from security/py-netbox-secretstore to security/py-netbox-secrets
+please do following steps:
+
+ 1. Make a backup.
+
+ 2. Install security/py-netbox-secrets
+
+ 3. Enable both plugins by updating the following line in the netbox
+    configuration (usually %%LOCALBASE%%/share/netbox/netbox/configuration.py):
+
+    PLUGINS = ['netbox_secretstore', 'netbox_secrets']
+
+ 4. Run NetBox migrations:
+
+    # cd %%LOCALBASE%%/share/netbox
+    # python%%PYTHON_VER%% manage.py migrate
+
+ 5. Re-adjust the indices for the netbox-secrets plugin:
+
+    # python%%PYTHON_VER%% manage.py sqlsequencereset netbox_secrets > output.sql
+
+ 6. Run the output of the previous command in the database, e.g.:
+
+    # psql -d NETBOXDB < output.sql
+
+ 7. You can now remove netbox-secretstore from the application by removing it
+    from the PLUGINS line in the netbox configuration:
+
+    PLUGINS = ['netbox_secrets']
+
+ 8. Collect static files of the netbox-secrets plugin:
+
+    # python%%PYTHON_VER%% manage.py collectstatic --no-input
+
+ 9. Restart WSGI/httpd environment (supervisord/apache/nginx/etc.).
+
+10. You may have clean up your database of the old tables manually, e.g.:
+
+    DROP TABLE netbox_secretstore_secret;
+    DROP TABLE netbox_secretstore_secretrole;
+    DROP TABLE netbox_secretstore_sessionkey;
+    DROP TABLE netbox_secretstore_userkey;
+
+11. Uninstall security/py-netbox-secretstore.
+EOD
+}
 ]