Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
EldarAliiev committed Jan 3, 2018
0 parents commit 46b6959
Show file tree
Hide file tree
Showing 13 changed files with 343 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[run]
branch = True

[report]
precision = 2

[html]
directory = reports/coverage
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
__pycache__/
*.py[cod]
*.egg
*.egg-info
/.git/
/.tox/
/.cache/
.coverage
/reports/
/.idea/
/env/
/sdist/
/build/
/dist/
6 changes: 6 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[MASTER]
ignore=tests

[REPORTS]
output-format = text
reports = yes
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
dist: trusty
sudo: required
language: python
python:
- "3.4"
- "3.5"
- "3.6"
addons:
apt:
packages:
- gnupg2
install: pip install tox-travis Flask python-gnupg python-coveralls
script: tox
after_success:
- coveralls
notifications:
email: false
6 changes: 6 additions & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Flask-GnuPG is written and maintained by Eldar Aliiev.

Contributors
````````````

- Eldar Aliiev <[email protected]> `@EldarAliiev <https://github.com/EldarAliiev>`_
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Eldar Aliiev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include README.rst AUTHORS.rst LICENSE .coveragerc .pylintrc
recursive-include tests *.py
89 changes: 89 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
Flask-GnuPG
==============

.. image:: https://img.shields.io/pypi/v/flask-gnupg.svg
:target: https://pypi.python.org/pypi/flask-gnupg

.. image:: https://img.shields.io/pypi/l/flask-gnupg.svg
:target: https://raw.githubusercontent.com/EldarAliiev/flask-gnupg/master/LICENSE

.. image:: https://img.shields.io/pypi/pyversions/flask-gnupg.svg
:target: https://pypi.python.org/pypi/flask-gnupg

.. image:: https://img.shields.io/pypi/wheel/flask-gnupg.svg
:target: https://pypi.python.org/pypi/flask-gnupg

.. image:: https://img.shields.io/pypi/status/flask-gnupg.svg
:target: https://pypi.python.org/pypi/flask-gnupg

.. image:: https://travis-ci.org/EldarAliiev/flask-gnupg.svg?branch=master
:target: https://travis-ci.org/EldarAliiev/flask-gnupg

.. image:: https://coveralls.io/repos/github/EldarAliiev/flask-gnupg/badge.svg?branch=master
:target: https://coveralls.io/github/EldarAliiev/flask-gnupg?branch=master

.. image:: https://img.shields.io/github/contributors/EldarAliiev/flask-gnupg.svg
:target: https://github.com/EldarAliiev/flask-gnupg/graphs/contributors



Flask extension for work with GnuPG based on python-gnupg.

https://github.com/EldarAliiev/flask-gnupg

Install:
--------

.. code-block:: bash
$ git clone https://github.com/EldarAliiev/flask-gnupg.git
$ cd flask-gnupg
$ python setup.py install
or with pip:

.. code-block:: bash
$ pip install Flask-GnuPG
Usage example:
--------------

Set up configuration in your Flask application:

* **GPG_HOME_DIR** : default **'~/.gnupg'**
* **GPG_BINARY** : default **'gpg2'**
* **GPG_KEYRING** : default **None**
* **GPG_SECRET_KEYRING** : default **None**
* **GPG_KEY_ID** : default **''**
* **GPG_PASSPHRASE** : default **''**

Create the application and initialize GnuPG instance:

.. code-block:: python
from flask import Flask
from flask_gnupg import GnuPG
app = Flask(__name__)
gpg = GnuPG(app)
Or you can set up GnuPG instance later:

.. code-block:: python
gpg = GnuPG()
app = Flask(__name__)
gpg.init_app(app)
Then you can use GnuPG engine in your views:

.. code-block:: python
@app.route('/')
def index():
keys_list = gpg.list_keys()
return keys_list
For details about all allowed methods read the docs of `python-gnupg <http://pythonhosted.org/python-gnupg/>`_ library.
68 changes: 68 additions & 0 deletions flask_gnupg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
Flask-GnuPG
Author: Eldar Aliiev
Email: [email protected]
"""

__author__ = 'Eldar Aliiev'
__copyright__ = 'Copyright 2017, Eldar Aliiev'
__credits__ = ['Eldar Aliiev']
__license__ = 'MIT'
__version__ = '1.0.0'
__maintainer__ = 'Eldar Aliiev'
__email__ = '[email protected]'
__status__ = 'Production/Stable'

import gnupg


class GnuPG(object):
"""
Flask extension for work with GnuPG
"""

def __init__(self, app=None):
"""
Initialize extension
:param app: Flask application
:type app: class
"""
self.app = app
self._gpg = None
if app is not None:
self.init_app(app)

def init_app(self, app):
"""
Initialize default extensions configuration and
setup GnuPG wrapper
:param app: Flask application
:type app: class
"""
app.config.setdefault('GPG_HOME_DIR', '~/.gnupg')
app.config.setdefault('GPG_BINARY', 'gpg2')
app.config.setdefault('GPG_KEYRING', None)
app.config.setdefault('GPG_SECRET_KEYRING', None)
app.config.setdefault('GPG_KEY_ID', '')
app.config.setdefault('GPG_PASSPHRASE', '')

self._gpg = gnupg.GPG(
gpgbinary=app.config['GPG_BINARY'],
gnupghome=app.config['GPG_HOME_DIR'],
keyring=app.config['GPG_KEYRING'],
secret_keyring=app.config['GPG_SECRET_KEYRING']
)

def __getattr__(self, method):
"""
Call GnuPG wrapper method
:param method: Method name
:return: GnuPG wrapper method
:rtype: function
"""
if not hasattr(self._gpg, method):
raise AttributeError('Method "{0:s}" not found in GnuPG wrapper!'.format(method))
return getattr(self._gpg, method)
9 changes: 9 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[bdist_wheel]
universal = 0

[metadata]
description-file = README.rst

[tool:pytest]
pep8ignore = E128 E501
pep8maxlinelength = 100
50 changes: 50 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from setuptools import setup
import flask_gnupg

setup(
name='Flask-GnuPG',
version=flask_gnupg.__version__,
author=flask_gnupg.__author__,
author_email=flask_gnupg.__email__,
maintainer=flask_gnupg.__author__,
maintainer_email=flask_gnupg.__email__,
url='https://github.com/EldarAliiev/flask-gnupg',
download_url='https://github.com/EldarAliiev/flask-gnupg/archive/master.zip',
license=flask_gnupg.__license__,
description='Flask extension for work with GnuPG',
long_description=open('README.rst').read(),
py_modules=['flask_gnupg'],
python_requires='>=3.4',
install_requires=[
'Flask>=0.12.2',
'python-gnupg>=0.4.1',
],
tests_require=[
'tox',
],
classifiers=[
'Development Status :: 5 - Production/Stable',
'Natural Language :: English',
'License :: OSI Approved :: %s License' % flask_gnupg.__license__,
'Operating System :: OS Independent',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
'Topic :: Software Development :: Libraries :: Python Modules',
],
keywords=[
'Flask',
'GnuPG',
'PGP',
],
test_suite='tests',
zip_safe=False,
include_package_data=True
)
32 changes: 32 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

import unittest
from flask import Flask
from flask_gnupg import GnuPG


class TestGnuPG(unittest.TestCase):

TESTING = True

def setUp(self):
self.app = Flask(__name__)
self.app.config.from_object(self)
self.assertTrue(self.app.testing)
self.gpg = GnuPG(self.app)
self.ctx = self.app.test_request_context()
self.ctx.push()

def tearDown(self):
self.ctx.pop()

def test_version(self):
self.assertIsInstance(self.gpg.version, tuple)

def test_list_keys(self):
self.assertIsInstance(self.gpg.list_keys(), list)

def test_invalid_method(self):
with self.assertRaises(AttributeError):
self.gpg.unknown_method()
21 changes: 21 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[tox]
envlist = py3,pylint

[testenv]
passenv = *
deps = Flask
python-gnupg
pytest
pytest-cov
pytest-pep8
python-coveralls
commands = python setup.py install
py.test --cov-report=term-missing --pep8 --cov=flask_gnupg tests.py
setenv =
PYTHONDONTWRITEBYTECODE = 1

[testenv:pylint]
deps = Flask
python-gnupg
pylint
commands = /bin/bash -c "pylint --rcfile=.pylintrc flask_gnupg.py | tee reports/pylint.out"

0 comments on commit 46b6959

Please sign in to comment.