Skip to content

Commit 0180cee

Browse files
committed
management commands for cli pragma key
1 parent ed257ad commit 0180cee

File tree

5 files changed

+37
-0
lines changed

5 files changed

+37
-0
lines changed

sqlcipher/management/__init__.py

Whitespace-only changes.

sqlcipher/management/commands/__init__.py

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
from __future__ import print_function
4+
from django.conf import settings
5+
from getpass import getpass
6+
7+
8+
class PromptForPragmaKeyMixin:
9+
"""""
10+
This is a universal command that you can have other management commands
11+
inherit from in case they need database access.
12+
"""
13+
14+
def handle(self, *args, **options):
15+
if not hasattr(settings, 'PRAGMA_KEY') or not settings.PRAGMA_KEY:
16+
print("There is no SQL Cipher key defined, it's unsafe to store in your settings. Please input your key")
17+
key = getpass("Key: ")
18+
settings.PRAGMA_KEY = key
19+
super(PromptForPragmaKeyMixin, self).handle(*args, **options)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
from django.core.management.commands.migrate import Command as BaseCommand
3+
4+
from ._mixins import PromptForPragmaKeyMixin
5+
6+
7+
class Command(PromptForPragmaKeyMixin, BaseCommand):
8+
"""
9+
Before migrating, we need to know the pragma key to access the database. If
10+
it does not exist, retrieve it from command line input.
11+
"""
12+
pass
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.core.management.commands.runserver import Command as RunserverCommand
2+
3+
from ._mixins import PromptForPragmaKeyMixin
4+
5+
class Command(PromptForPragmaKeyMixin, RunserverCommand):
6+
pass

0 commit comments

Comments
 (0)