Skip to content

Commit

Permalink
[FEATURE] Added Admin UI and REST APIs
Browse files Browse the repository at this point in the history
Completed extension of sandman that generates Flask views to provide
REST APIs and Admin UI.

Included password handling for accessing the API and UI.

Implements: 2
closes #2
  • Loading branch information
shad7 committed Mar 28, 2015
1 parent a6d611d commit 1f6a208
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 37 deletions.
3 changes: 2 additions & 1 deletion doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ Running SeedboxManager from crontab::

Starting Admin UI and REST API::

dbadmin sqlite:////home/USER/.seedbox/torrent.db >> /home/USER/seedbox/etc/seedbox/admin.log 2>&1
dbadmin passwd --password <your_password>
dbadmin run sqlite:////home/USER/.seedbox/torrent.db >> /home/USER/seedbox/etc/seedbox/admin.log 2>&1


General Information
Expand Down
14 changes: 9 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
click
pbr
twine

futures
oslo.config
lockfile
pbr
rarfile>=2.6
sandman
six>=1.4.1
sqlalchemy==0.9.8
sqlalchemy-migrate
stevedore>=0.10
twine
stevedore>=1.3.0
xworkflows

click
sandman
passlib

84 changes: 54 additions & 30 deletions seedbox/db/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,56 @@
not available via sandmanctl
"""
import logging
import os

import click
from sandman import app
from sandman.model import activate
from oslo.config import cfg
from passlib.hash import sha256_crypt
import sandman
from sandman import model

from seedbox import options
from seedbox import version


def print_version(ctx, value):
"""Print the current version of sandman and exit.
options.initialize([])

:param ctx: application context
:param value:
"""
if not value:
return
click.echo('SeedboxManager v%s' % (version.version_string()))
ctx.exit()

def load_passfile():
pwfile = cfg.CONF.find_file('.admin_pass')
if not pwfile:
pwfile = os.path.join(cfg.CONF.config_dir, '.admin_pass')
return pwfile


@sandman.auth.verify_password
def verify_password(username, password):
pw = None
with open(load_passfile(), 'r') as fd:
pw = fd.read()
return sha256_crypt.verify(password, pw)


@sandman.app.before_request
@sandman.auth.login_required
def before_request():
pass


@click.command()
@click.group()
def cli():
pass


@cli.command('passwd')
@click.password_option()
def save_password(password):
"""Set admin password for accessing admin UI"""
with open(load_passfile(), 'w') as fd:
fd.write(sha256_crypt.encrypt(password))


@cli.command()
@click.option('--generate-pks/--no-generate-pks', default=False,
help='Have sandman generate primary keys for tables without one')
@click.option('--show-pks/--no-show-pks', default=False,
Expand All @@ -35,31 +64,26 @@ def print_version(ctx, value):
help='Port of database server to connect to')
@click.option('--debug', default=False,
help='Enable debug output from webserver')
@click.option('--version', is_flag=True,
callback=print_version, expose_value=False, is_eager=True)
@click.version_option(version=version.version_string(),
message='SeedboxManager v%(version)s')
@click.argument('URI', metavar='<URI>')
def run(generate_pks, show_pks, host, port, debug, uri):
"""Connect sandman to <URI> and start the API server/admin
:param generate_pks: Have sandman generate primary keys for tables
without one
:param show_pks: Have sandman show primary key columns in the admin view
:param host: Hostname of database server to connect to
:param port: Port of database server to connect to
:param debug: Enable debug output from webserver
:param uri: database uri interface.
"""Start the admin UI for managing data
<URI> is the database connection uri
ex. sqlite:////path/to/file
"""
app.config['SQLALCHEMY_DATABASE_URI'] = uri
app.config['SANDMAN_GENERATE_PKS'] = generate_pks
app.config['SANDMAN_SHOW_PKS'] = show_pks
app.config['SERVER_HOST'] = host
app.config['SERVER_PORT'] = port
activate(name='SeedboxManager Admin', browser=False)
sandman.app.config['SQLALCHEMY_DATABASE_URI'] = uri
sandman.app.config['SANDMAN_GENERATE_PKS'] = generate_pks
sandman.app.config['SANDMAN_SHOW_PKS'] = show_pks
sandman.app.config['SERVER_HOST'] = host
sandman.app.config['SERVER_PORT'] = port
model.activate(name='SeedboxManager Admin', browser=False)

# set logging to dump output if in debug mode
reqlogger = logging.getLogger('werkzeug')
reqlogger.setLevel(logging.ERROR)
if debug:
reqlogger.setLevel(logging.DEBUG)

app.run(host=host, port=int(port), debug=debug)
sandman.app.run(host=host, port=int(port), debug=debug)
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ data_files =
[entry_points]
console_scripts =
seedmgr = seedbox.cli:main
dbadmin = seedbox.db.admin:run
dbadmin = seedbox.db.admin:cli

seedbox.tasks =
filecopy = seedbox.tasks.filecopy:CopyFile
Expand Down

0 comments on commit 1f6a208

Please sign in to comment.