Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added authentication to spyre #87

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Spyre
Secure Spyre
=========

Spyre is a Web Application Framework for providing a simple user interface for Python data projects.
Expand All @@ -12,11 +12,11 @@ Spyre runs on the minimalist python web framework, **[cherrypy]**, with **[jinja
Installation
----
```bash
$ pip install dataspyre
$ pip install git+https://github.com/Dana-Farber/spyre
```


The Simplest of Examples
The Simplest of Examples, with User Authentication (Login)
----
Here's a very simple spyre example that shows the primary components of a spyre app
```python
Expand All @@ -28,7 +28,7 @@ class SimpleApp(server.App):
"type": "text",
"key": "words",
"label": "write words here",
"value": "hello world",
"value": "hello world",
"action_id": "simple_html_output"
}]

Expand All @@ -41,8 +41,17 @@ class SimpleApp(server.App):
words = params["words"]
return "Here's what you wrote in the textbox: <b>%s</b>" % words

USERS={"alice":"secret"}

from cherrypy.lib import auth_digest #must import this to compute ha1 digest
digest_auth = {'/': {'tools.auth_digest.on': True,
'tools.auth_digest.realm': 'wonderland',
'tools.auth_digest.get_ha1': auth_digest.get_ha1_dict_plain(USERS),
'tools.auth_digest.key': 'a565c27146791cfb',
}}

app = SimpleApp()
app.launch()
app.launch(config=digest_auth)
```

The SimpleApp class inherits server.App which includes a few methods that you can override to generate outputs. In this case we want our app to display HTML (just text for now) so we'll overide the getHTML method. This method should return a string.
Expand Down
7 changes: 5 additions & 2 deletions spyre/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from cherrypy.lib.static import serve_file
from cherrypy.lib.static import serve_fileobj

from cherrypy.lib import auth_digest

try:
import StringIO as io # python2
except Exception:
Expand Down Expand Up @@ -478,14 +480,15 @@ def getCustomHead(self):
"""
return ""

def launch(self, host="local", port=8080, prefix='/'):
def launch(self, host="local", port=8080, prefix='/', config=None):
"""launch"""
self.prefix = prefix
webapp = self.getRoot()
if host != "local":
cherrypy.server.socket_host = '0.0.0.0'
cherrypy.server.socket_port = port
cherrypy.tree.mount(webapp, prefix)
cherrypy.quickstart(webapp)
cherrypy.quickstart(webapp, config=config)

def launch_in_notebook(self, port=9095, width=900, height=600):
"""launch the app within an iframe in ipython notebook"""
Expand Down