Drastically restructured the compression and crypto features

Converted the crypto and compression plugins to core features, and
added the utility variables and functions to the Config class in
``config.py``. Added helper functions in PappySession class in
``pappy.py`` to enable the user to pass in an encrypted project archive.
Next moving to testing and debugging!
This commit is contained in:
onizenso 2016-03-24 20:48:40 +00:00
parent 6a79209224
commit 5be69b205d
5 changed files with 355 additions and 4 deletions

View file

@ -98,6 +98,51 @@ class PappyConfig(object):
The dictionary from ~/.pappy/global_config.json. It contains settings for
Pappy that are specific to the current computer. Avoid putting settings here,
especially if it involves specific projects.
.. data: archive
Project archive compressed as a ``tar.bz2`` archive if libraries available on the system,
otherwise falls back to zip archive.
:Default: 'project.archive'
.. data: crypt_dir
Temporary working directory to unpack an encrypted project archive. Directory
will contain copies of normal startup files, e.g. conifg.json, cmdhistory, etc.
On exiting pappy, entire directory will be compressed into an archive and encrypted.
Compressed as a tar.bz2 archive if libraries available on the system,
otherwise falls back to zip.
:Default: 'crypt'
.. data: crypt_file
Encrypted archive of the temporary working directory ``crypt_dir``. Compressed as a
tar.bz2 archive if libraries available on the system, otherwise falls back to zip.
:Default: 'project.crypt'
.. data: crypt_mode
Boolean value to determine whether project is being decrypted or encrypted, during
start-up and tear-down respectively.
.. data: salt
Nonce value used for key derivation. Generated by reading 16 bytes
from /dev/urandom.
:Default: ``os.urandom(16)``
.. data: salt_file
Clear-text file containing the salt generated for key derivation. A new salt
will be generated each time the project is encrypted. After successfully
decrypting the project file (``project.crypt``), the salt file (``project.salt``)
will be deleted.
:Default: ``project.salt``
"""
def __init__(self):
@ -125,6 +170,13 @@ class PappyConfig(object):
self.config_dict = {}
self.global_config_dict = {}
self.archive = 'project.archive'
self.crypt_dir = os.path.join(os.getcwd(), 'crypt')
self.crypt_file = 'project.crypt'
self.crypt_mode = None
self.salt = os.urandom(16)
self.salt_file = 'project.salt'
def get_default_config(self):
default_config_file = os.path.join(os.path.dirname(os.path.realpath(__file__)),
@ -133,6 +185,15 @@ class PappyConfig(object):
settings = json.load(f)
return settings
def get_project_files(self):
file_glob = glob.glob('*')
pp = os.path.join(os.getcwd())
project_files = [pp+f for f in file_glob if os.path.isfile(pp+f)]
project_files.remove(self.salt_file)
project_files.remove(self.crypt_file)
return project_files
@staticmethod
def _parse_proxy_login(conf):
proxy = {}