Commit 093b17ad authored by Maude Le Jeune's avatar Maude Le Jeune
Browse files

+ doc of new functions (pipe index + auth)

parent 9b407d47
...@@ -5,12 +5,34 @@ ...@@ -5,12 +5,34 @@
import cherrypy import cherrypy
import sqlite3 import sqlite3
def read_access(func): def read_access(func):
""" Decorator to set read only access to a web page (cherrypy web function)
Parameters
----------
func: web function
"""
return cherrypy.tools.digest_auth(realm="pipeweb",users=lambda: get_credentials(1))(func) return cherrypy.tools.digest_auth(realm="pipeweb",users=lambda: get_credentials(1))(func)
def write_access(func): def write_access(func):
""" Decorator to set read only accessto a web page (cherrypy web function)
Parameters
----------
func: web function
"""
return cherrypy.tools.digest_auth(realm="pipeweb",users=lambda: get_credentials(2))(func) return cherrypy.tools.digest_auth(realm="pipeweb",users=lambda: get_credentials(2))(func)
def get_credentials(access_level=1): def get_credentials(access_level=1):
""" Get users/passwd from pipe data base.
Parameters
----------
access_level: int, 1 for read-only or 2 for read-write access
Returns
-------
dictionnary of user and passwd
"""
db_file = cherrypy.request.app.root.which_sqlfile(cherrypy.request.path_info) db_file = cherrypy.request.app.root.which_sqlfile(cherrypy.request.path_info)
try: try:
conn = sqlite3.connect(db_file,check_same_thread=True) conn = sqlite3.connect(db_file,check_same_thread=True)
...@@ -28,6 +50,12 @@ def get_credentials(access_level=1): ...@@ -28,6 +50,12 @@ def get_credentials(access_level=1):
return dic return dic
def acl_setup(db_file): def acl_setup(db_file):
""" Set user/passwd table in pipe database.
Parameters
----------
db_file: string, pipe data base file
"""
conn = sqlite3.connect(db_file,check_same_thread=True) conn = sqlite3.connect(db_file,check_same_thread=True)
with conn: with conn:
if not conn.execute('select tbl_name from sqlite_master where tbl_name == "users"').fetchone(): if not conn.execute('select tbl_name from sqlite_master where tbl_name == "users"').fetchone():
...@@ -35,6 +63,15 @@ def acl_setup(db_file): ...@@ -35,6 +63,15 @@ def acl_setup(db_file):
conn.close() conn.close()
def add_user(db_file, user, passwd, access_level=1): def add_user(db_file, user, passwd, access_level=1):
""" Add user entry to data base.
Parameters
----------
db_file: string, pipe data base file
user: string, user name
passwd: string, user password
access_level: int, 1 for read-only or 2 for read-write access
"""
conn = sqlite3.connect(db_file,check_same_thread=True) conn = sqlite3.connect(db_file,check_same_thread=True)
acl_setup(db_file) acl_setup(db_file)
with conn: with conn:
...@@ -42,6 +79,13 @@ def add_user(db_file, user, passwd, access_level=1): ...@@ -42,6 +79,13 @@ def add_user(db_file, user, passwd, access_level=1):
conn.close() conn.close()
def del_user(db_file, user): def del_user(db_file, user):
""" Delete user entry from data base.
Parameters
----------
db_file: string, pipe data base file
user: string, user name
"""
conn = sqlite3.connect(db_file,check_same_thread=True) conn = sqlite3.connect(db_file,check_same_thread=True)
with conn: with conn:
conn.execute('delete from users where user = ?' % user) conn.execute('delete from users where user = ?' % user)
......
...@@ -275,6 +275,11 @@ def start(config, config_file): ...@@ -275,6 +275,11 @@ def start(config, config_file):
"""Start the web server in daemon mode. """Start the web server in daemon mode.
Store the PID in the file specified in config. Store the PID in the file specified in config.
Parameters
----------
config: dict where internal config is stored
config_file: string, user config file
""" """
from cherrypy.process.plugins import Daemonizer, PIDFile from cherrypy.process.plugins import Daemonizer, PIDFile
cherrypy.config.update(config) cherrypy.config.update(config)
...@@ -290,9 +295,14 @@ def stop(config, config_file): ...@@ -290,9 +295,14 @@ def stop(config, config_file):
"""Stop the web server by sending the TERM signal to the daemon process. """Stop the web server by sending the TERM signal to the daemon process.
Look for the PID in the file specified in config. Look for the PID in the file specified in config.
Parameters
----------
config: dict, where internal config is stored
config_file: string, user config file
""" """
import signal import signal
cherrypy.config.update(config_file) cherrypy.config.update(config)
cherrypy.config.update(config_file) cherrypy.config.update(config_file)
pidf = open(config['global']['server.pidfile']) pidf = open(config['global']['server.pidfile'])
pid = int(pidf.read()) pid = int(pidf.read())
...@@ -303,6 +313,12 @@ def update_config(pipename, pipepath, config_file): ...@@ -303,6 +313,12 @@ def update_config(pipename, pipepath, config_file):
""" Add a new Pipeline entry to the config file. """ Add a new Pipeline entry to the config file.
If the config file does not exist, create a new one. If the config file does not exist, create a new one.
Parameters
----------
pipename: string, pipe short name
pipepath: string, pipe instance root path
config_file: string, user config file
""" """
import ConfigParser import ConfigParser
c = ConfigParser.ConfigParser() c = ConfigParser.ConfigParser()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment