Repository: koladev32/drf-simple-apikey (language: python)

Issue:
Add a script to generate a Fernet key
If the developer has to set the Fernet key, he needs to use the `shell`, import the cryptography package and make calls to generate a key. We can add a utility to handle that, a Django command. 

```shell
django-admin generate fernetkey
```


Discussion / hints:

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d72b21e..f9842fa 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,4 +22,5 @@ Changelog
 - Add authentication backend (#12) 
 - Add default permissions classes (#13)
 - Add creation date field on ApiKey (#14)
-- Add package for linting, coverage and syntax checker (#18) 
\ No newline at end of file
+- Add package for linting, coverage and syntax checker (#18)
+- Add a script to generate a Fernet key (#21)
\ No newline at end of file
diff --git a/README.md b/README.md
index 7f335a8..d8369d8 100644
--- a/README.md
+++ b/README.md
@@ -3,3 +3,18 @@
 Simple API Key is an API Key authentication plugin for REST API built with [Django Rest Framework](https://www.django-rest-framework.org/). 
 
 For the full documentation, visit https://djangorestframework-simple-apikey.readthedocs.io/en/latest/.
+
+## Generate a Fernet Key
+We've made it easier for you by creating a custom Django command to quickly generate a fernet key, which is a *crucial component* in the authentication system. Make sure to keep the key secure and store it somewhere safely (ie: environment variable). 
+
+**Important ⛔️** : You should treat the `FERNET_KEY` security at the same level as the Django `SECRET_KEY`. 🫡
+
+To generate the fernet key use the following command:
+
+```python
+python manage.py generate_fernet_key
+```
+or 
+```python
+django-admin generate_fernet_key
+```
diff --git a/rest_framework_simple_api_key/management/__init__.py b/rest_framework_simple_api_key/management/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/rest_framework_simple_api_key/management/commands/__init__.py b/rest_framework_simple_api_key/management/commands/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/rest_framework_simple_api_key/management/commands/generate_fernet_key.py b/rest_framework_simple_api_key/management/commands/generate_fernet_key.py
new file mode 100644
index 0000000..0d04619
--- /dev/null
+++ b/rest_framework_simple_api_key/management/commands/generate_fernet_key.py
@@ -0,0 +1,11 @@
+from cryptography.fernet import Fernet
+
+from django.core.management.base import BaseCommand
+
+
+class Command(BaseCommand):
+    help = "Displays the value of a Fernet key in the shell"
+
+    def handle(self, *args, **options):
+        key = Fernet.generate_key().decode()
+        self.stdout.write(self.style.SUCCESS(key))


Test patch:
diff --git a/tests/test_custom_django_command.py b/tests/test_custom_django_command.py
new file mode 100644
index 0000000..5ad3d8d
--- /dev/null
+++ b/tests/test_custom_django_command.py
@@ -0,0 +1,18 @@
+import pytest
+
+from io import StringIO
+
+from django.core.management import call_command
+
+
+def test_command_generate_fernet_key():
+    out = StringIO()
+    args = []
+    opts = {}
+
+    call_command('generate_fernet_key', *args, **opts, stdout=out)
+
+    message = out.getvalue()
+
+    assert message is not None
+    assert type(message) is str