Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
1,530 additions
and
849 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,4 @@ The server depends on the Python [cryptography](https://cryptography.io/en/lates | |
|
||
## License | ||
|
||
MPL. | ||
MPL2. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
### | ||
# app configuration | ||
# http://docs.pylonsproject.org/projects/pyramid/en/1.5-branch/narr/environment.html | ||
### | ||
|
||
[app:main] | ||
use = egg:devmgr | ||
|
||
pyramid.reload_templates = true | ||
pyramid.debug_authorization = false | ||
pyramid.debug_notfound = false | ||
pyramid.debug_routematch = false | ||
pyramid.default_locale_name = en | ||
pyramid.includes = | ||
pyramid_debugtoolbar | ||
|
||
# By default, the toolbar only appears for clients from IP addresses | ||
# '127.0.0.1' and '::1'. | ||
# debugtoolbar.hosts = 127.0.0.1 ::1 | ||
|
||
db_uri = sqlite:////tmp/devmgr.db | ||
oauth_server_url = http://127.0.0.1:9010 | ||
|
||
### | ||
# wsgi server configuration | ||
### | ||
|
||
[server:main] | ||
use = egg:waitress#main | ||
host = 0.0.0.0 | ||
port = 6543 | ||
|
||
### | ||
# logging configuration | ||
# http://docs.pylonsproject.org/projects/pyramid/en/1.5-branch/narr/logging.html | ||
### | ||
|
||
[loggers] | ||
keys = root, devmgr | ||
|
||
[handlers] | ||
keys = console | ||
|
||
[formatters] | ||
keys = generic | ||
|
||
[logger_root] | ||
level = INFO | ||
handlers = console | ||
|
||
[logger_devmgr] | ||
level = DEBUG | ||
handlers = | ||
qualname = devmgr | ||
|
||
[handler_console] | ||
class = StreamHandler | ||
args = (sys.stderr,) | ||
level = NOTSET | ||
formatter = generic | ||
|
||
[formatter_generic] | ||
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
import logging | ||
|
||
__version__ = '0.0.1' | ||
log = logging.getLogger('devmgr') | ||
__version__ = '0.1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import fxa.oauth | ||
import pyramid.renderers | ||
from pyramid.authorization import ACLAuthorizationPolicy | ||
from pyramid.config import Configurator | ||
from pyramid.events import NewRequest | ||
from sqlalchemy import create_engine | ||
from sqlalchemy.orm import sessionmaker, scoped_session | ||
|
||
from devmgr.db import Base | ||
from devmgr.resources import make_root | ||
from devmgr.security import DevMgrAuthenticationPolicy, verify_auth | ||
|
||
|
||
def db(request): | ||
maker = request.registry.dbmaker | ||
session = maker() | ||
|
||
def cleanup(request): | ||
if request.exception is not None: | ||
session.rollback() | ||
else: | ||
session.commit() | ||
session.close() | ||
request.add_finished_callback(cleanup) | ||
return session | ||
|
||
|
||
def make_app(global_config, db_uri="sqlite:////tmp/devmgr.db", **settings): | ||
# Security policies | ||
authentication_policy = DevMgrAuthenticationPolicy() | ||
authorization_policy = ACLAuthorizationPolicy() | ||
|
||
config = Configurator( | ||
settings=settings, | ||
root_factory=make_root, | ||
authentication_policy=authentication_policy, | ||
authorization_policy=authorization_policy, | ||
) | ||
config.add_subscriber(verify_auth, NewRequest) | ||
config.add_request_method(db, reify=True) | ||
|
||
config.registry.fxa_oauth = fxa.oauth.Client( | ||
server_url=settings["oauth_server_url"], | ||
) | ||
|
||
db_engine = create_engine(db_uri) | ||
session_factory = sessionmaker(bind=db_engine) | ||
config.registry.dbmaker = scoped_session(session_factory) | ||
Base.metadata.create_all(db_engine) | ||
|
||
json_renderer = pyramid.renderers.JSON() | ||
config.add_renderer(None, json_renderer) | ||
config.include('devmgr.views.include_views') | ||
return config.make_wsgi_app() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import uuid | ||
|
||
from sqlalchemy import Column, String, Integer, ForeignKey | ||
from sqlalchemy.ext.declarative import declarative_base | ||
from sqlalchemy.orm import relationship | ||
from sqlalchemy.orm.collections import attribute_mapped_collection | ||
|
||
|
||
def new_uuid(): | ||
return str(uuid.uuid4()) | ||
|
||
|
||
Base = declarative_base() | ||
|
||
|
||
class Device(Base): | ||
__tablename__ = 'devices' | ||
|
||
uuid = Column(String, primary_key=True, default=new_uuid) | ||
account_id = Column(String, index=True, nullable=False) | ||
name = Column(String, nullable=False) | ||
endpoint = Column(String) | ||
tokens = relationship( | ||
"Token", collection_class=attribute_mapped_collection('token_hash'), | ||
cascade="all, delete-orphan" | ||
) | ||
|
||
def __init__(self, **kwargs): | ||
for key, val in kwargs.items(): | ||
setattr(self, key, val) | ||
|
||
def to_json(self): | ||
return dict(uuid=self.uuid, name=self.name, endpoint=self.endpoint) | ||
|
||
|
||
class Token(Base): | ||
__tablename__ = 'tokens' | ||
|
||
token_hash = Column(String, primary_key=True) | ||
device_uuid = Column(Integer, ForeignKey('devices.uuid')) | ||
|
||
def __init__(self, token_hash): | ||
self.token_hash = token_hash |
Oops, something went wrong.