djangosecure
============

Secure Django settings (Works with other Python scripts)

This module creates a cryptokey outside the django project directory,
encrypts with that cryptokey your django sensible settings and stores
the encrypted values.

You can use it at your project settings.py file \* Note: Before running
the django site with gunicorn or similar for the first time, you must
run somme manage command to be prompt for the sensible settings \*
Developed for Linux/Python2.7, Python3.5

Install
=======

``pip install djangosecure``

Examples
========

SECRET\_KEY
-----------

::

    import djangosecure

    SECRET_KEY_FILE_PATH = '/some/path/to/store/file.secret'
    SECRET_KEY = djangosecure.get_secret_key(SECRET_KEY_FILE_PATH)

-  Note: If the secret key file path does not exist it will try to
   create it,
-  Note: The secret file will be automatically created the first time
   you call get\_secret\_key()
-  Note: You can do something like:

::

    import os
    PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    SECRET_FILE = os.path.join(PROJECT_DIR, '.secret.txt')
    SECRET_KEY = djangosecure.get_secret_key(SECRET_FILE)

DATABASES
---------

The first time you run python manage.py runserver you will be prompted
for your database settings. They will be saved encrypted with the
generated cryptokey generated by django-secure module.

You can have as many database configurations, change the parameter to
change the configuration and running ``python manage.py runserver`` you
will be prompted again for the new settings

::

    import djangosecure


    DATABASES = {
        'default': djangosecure.get_database('production', path='your/database/config/path.cfg'),
    }

S3 IAM Settings
---------------

In your settings.py include:

::

    from djangosecure import get_s3_config

    # S3 Config
    S3_CFG = /path/to/s3_config_file.cfg
    AWS_STORAGE_BUCKET_NAME = 'bucket_name'
    AWS_ACCESS_KEY_ID = get_s3_config(AWS_STORAGE_BUCKET_NAME, 'S3_access_IAM_Key_Id', S3_CFG)
    AWS_SECRET_ACCESS_KEY = get_s3_config(AWS_STORAGE_BUCKET_NAME, 'S3_access_IAM_Secret_Key', S3_CFG)
    AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME

-  Note: File and path are automatically created at first call

Hidden setting
--------------

To encrypt any other setting use hidde\_setting, for example

::

    from djangosecure import hidden_setting
    CELERY_BROKER = 'amqp://{0}:{1}@localhost//'.format(
        hidden_setting('celery', 'broker_username', config_file="config/file/path/here.cfg"),
        hidden_setting('celery', 'broker_password')
        )

-  Note: File and path are automatically created at first call
