Spiff Guard
------------
This library is part of the Spiff platform.

Spiff Guard is a library implementing generic access lists for Python.


Contact
--------
Mailing List: http://groups.google.com/group/spiff-devel/


Dependencies
-------------
- sqlalchemy


Usage
------
See some example code below. Complete API documentation can be found here:

  http://spiff.debain.org/static/docs/spiff_guard/index.html

If you need more help, please drop by our mailing list and let us know what
you are looking for.

##############################
from sqlalchemy import create_engine
from Guard      import *

# Connect to the database.
db    = create_engine('mysql://user:pass@localhost/guard_name')
guard = DB(db)
guard.install()
guard.register_type([Action, Resource, ResourceGroup])
 
# Create actions "View" and "Write".
view  = Action("View")
write = Action("Write")
guard.add_action(view)
guard.add_action(write)
 
# Create an access control object for the website.
website = ResourceGroup("My Website")
guard.add_resource(website)
 
# Create an access control object for users and groups.
group = ResourceGroup("Users")
user  = Resource("Some Guy")
guard.add_resource(None, group)
guard.add_resource(group, user)
 
# Assign permissions.
guard.grant(group, view, website)
guard.grant(user, write, website)
 
# Done! Checking permissions is now as easy as this:
if guard.has_permission(user, view, website):
     print 'Yep, that is permitted!'
else:
     print 'Sorry, dude, permission denied!'
     
# Alternate way that does not require the object instance:
if guard.has_permission_from_id(user.get_id(),
                                view.get_id(),
                                website.get_id()):
     print 'Yep, that is permitted!'
else:
     print 'Sorry, dude, permission denied!'
##############################
