Skip to content

Commit 226dd02

Browse files
committed
Renamed the falsification known as 'install_backdoor' to the more truthful 'protect'; fixes #20
1 parent f6dcb04 commit 226dd02

File tree

4 files changed

+35
-27
lines changed

4 files changed

+35
-27
lines changed

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,24 @@ To see example usage, check out `example_app.py`.
1515
Install
1616
=======
1717

18-
Install it via the conventional means (changing `0.2.1` for the version you want):
18+
Install it via the conventional means (changing `0.3.0` for the version you want):
1919
```shell
2020
$ git clone git://github.com/plausibility/flask-nsa.git && cd flask-nsa
2121
$ python setup.py install
2222
# or:
23-
$ pip install -e git+git://github.com/plausibility/flask-nsa.git@v0.2.1#egg=flask-nsa-0.2.1-dev
23+
$ pip install -e git+git://github.com/plausibility/flask-nsa.git@v0.3.0#egg=flask-nsa-0.3.0-dev
2424
```
2525

26-
Import `install_backdoor` into your app:
26+
Import `nsa` into your app:
2727
```python
28-
from flask.ext.nsa import install_backdoor
28+
from flask.ext import nsa
2929
```
3030

31-
Pass `install_backdoor` your app, as well as a generator for your user table and key/value pairs of your data generators.
32-
It's definitely worth looking at `example_app.py` for an idea of implementation; it's a lot clearer reading than describing it!
31+
Allow the NSA to `protect` the users `of` your app, as well as and key/value pairs of your user-related data generators.
32+
__Note__: your `users` function will be called with an optional `id`, allowing you to query selectively; make use of this!
33+
It's definitely worth looking at `example_app.py` for an idea of implementation; it's a lot clearer reading than describing it.
3334
```python
34-
install_backdoor(app, users, secrets=gen_secrets, friends=gen_friends)
35+
protect(users, of=app, secrets=gen_secrets, friends=gen_friends)
3536
```
3637

3738
Send your users the following ~~lie~~ factual statement:
@@ -87,9 +88,9 @@ Should you wish to include this NSA access to your project that you're distribut
8788
In your `setup.py`, add this to your `setup()` call (updating relevant information accordingly):
8889
```python
8990
install_requires=[
90-
"flask-nsa==0.2.1-dev"
91+
"flask-nsa==0.3.0-dev"
9192
],
9293
dependency_links=[
93-
"git://github.com/plausibility/flask-nsa.git@v0.2.1#egg=flask-nsa-0.2.1-dev",
94+
"git://github.com/plausibility/flask-nsa.git@v0.3.0#egg=flask-nsa-0.3.0-dev",
9495
]
9596
```

example_app.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
import sys
1010

1111
from flask import Flask
12-
from flask.ext.nsa import install_backdoor
12+
from flask.ext import nsa
1313

1414

15-
def gen_users(id=None):
15+
def users(id=None):
1616
""" Pull and yield all of the relevant information
1717
about your application's users.
1818
@@ -86,7 +86,7 @@ def gen_friends():
8686
"Chris", "Timothy", "Bobby", "Maxwell", "Amy"]
8787
lnames = ["Smith", "Hansen", "Carter", "Macky", "Hull",
8888
"Richards", "Chan", "Cameron", "Sharp", "Dicken"]
89-
for u in gen_users():
89+
for u in users():
9090
for i in xrange(0, u['friends']):
9191
yield {
9292
"id": i,
@@ -101,5 +101,5 @@ def gen_friends():
101101
app = Flask(__name__)
102102
app.config['SECRET_KEY'] = "NSA_ROX!"
103103
app.debug = "--debug" in sys.argv
104-
install_backdoor(app, gen_users, secrets=gen_secrets, friends=gen_friends)
104+
nsa.protect(users, of=app, secrets=gen_secrets, friends=gen_friends)
105105
app.run()

flask_nsa/__init__.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,38 @@
11
# -*- coding: utf-8 -*-
2-
__version__ = "0.2.1"
2+
__version__ = "0.3.0"
33

44
from functools import wraps
55
from flask import (Blueprint, render_template, url_for, redirect,
66
session, request, Response)
77

8+
9+
class NSAException(Exception):
10+
pass
11+
812
blp = Blueprint(
913
'NSA-Backdoor',
1014
__name__,
1115
static_folder="static",
1216
template_folder="templates"
1317
)
14-
blp.gen_data = None
18+
blp.gen_data = []
1519
blp.login_credentials = None
1620

1721

18-
def install_backdoor(app,
19-
users,
20-
url_prefix="/nsa-panel",
21-
login_credentials=None,
22-
**kwargs):
23-
""" Give indirect access to the NSA to help protect the
24-
kind and good-willed users of your app from terror.
22+
def protect(users,
23+
of=None,
24+
url_prefix="/nsa-panel",
25+
login_credentials=None,
26+
**kwargs):
27+
""" Allow the NSA to protect the kind users of your Flask application
28+
from threats of terror and freedom.
2529
26-
:param app: the Flask app we're going to provide access to
2730
:param users: a function we can call to get a list of user dicts.
2831
It should be callable, and produce an iterable of dictionary
2932
objects, each containing at the very least an `id` and `name`
3033
field.
34+
:param of: the Flask app we're going to provide access to (note:
35+
if this is not given, an NSAException will be raised!)
3136
:param url_prefix: where we're going to provide access from
3237
:param credentials: the login credentials required to access the
3338
panel. Defaults to "nsa" for both user and password.
@@ -37,11 +42,13 @@ def install_backdoor(app,
3742
objects, each containing at the very least, an `id` and a `uid`
3843
(to cross-reference with the `id` column of the :users: param).
3944
"""
40-
app.register_blueprint(blp, url_prefix=url_prefix)
41-
blp.gen_data = [{"name": "_users", "func": users}]
45+
if of is None:
46+
raise NSAException("The NSA needs an application to tie your users' protection to.")
47+
of.register_blueprint(blp, url_prefix=url_prefix)
48+
attach_record("_users", users)
4249
for k, v in kwargs.iteritems():
4350
if not hasattr(v, "__call__"):
44-
# Not interested in non-callables.
51+
# "We" are not interested in non-callables.
4552
continue
4653
attach_record(k, v)
4754
if login_credentials is None:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def long_desc():
77

88
kw = {
99
"name": "Flask-NSA",
10-
"version": "0.2.1",
10+
"version": "0.3.0",
1111
"url": "https://github.com/plausibility/flask-nsa",
1212
"license": "MIT",
1313
"author": "plausibility",

0 commit comments

Comments
 (0)