libbe.command.serve

Define the Serve serving BE Storage over HTTP.

See Also

libbe.storage.http : the associated client

class libbe.command.serve.AdminApp(app, users=None, url='^admin/?', *args, **kwargs)

WSGI middleware for managing users (changing passwords, usernames, etc.).

Methods

admin(environ, start_response)
data_get_boolean(data, key[, default, source])
data_get_id(data[, key, default, source])
data_get_string(data, key[, default, source])
error(environ, start_response, error, message) Make it easy to call start_response for errors.
is_head(environ)
log_request(environ[, status, bytes])
ok_response(environ, start_response, content)
post_data(environ)
query_data(environ)
admin(environ, start_response)
class libbe.command.serve.AuthenticationApp(app, realm, setting='be-auth', users=None, *args, **kwargs)

WSGI middleware for handling user authentication.

Methods

authenticate(environ) Handle user-authentication sent in the “Authorization” header.
authfunc(environ, username, password)
error(environ, start_response, error, message) Make it easy to call start_response for errors.
log_request(environ[, status, bytes])
authenticate(environ)

Handle user-authentication sent in the “Authorization” header.

This function implements Basic authentication as described in HTTP/1.0 specification [R1] . Do not use this module unless you are using SSL, as it transmits unencrypted passwords.

[R1]http://www.w3.org/Protocols/HTTP/1.0/draft-ietf-http-spec.html#BasicAA

Notes

Code based on authkit/authenticate/basic.py (c) 2005 Clark C. Evans. Released under the MIT License: http://www.opensource.org/licenses/mit-license.php

Examples

>>> users = Users()
>>> users.add_user(User('Aladdin', 'Big Al', password='open sesame'))
>>> app = AuthenticationApp(app=None, realm='Dummy Realm', users=users)
>>> app.authenticate({'HTTP_AUTHORIZATION':'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='})
'Aladdin'
>>> app.authenticate({'HTTP_AUTHORIZATION':'Basic AAAAAAAAAAAAAAAAAAAAAAAAAA=='})
authfunc(environ, username, password)
class libbe.command.serve.ExceptionApp(app, *args, **kwargs)

Some servers (e.g. cherrypy) eat app-raised exceptions.

Work around that by logging tracebacks by hand.

Methods

error(environ, start_response, error, message) Make it easy to call start_response for errors.
log_request(environ[, status, bytes])
class libbe.command.serve.Serve(*args, **kwargs)

Command wrapper around ServerApp.

Methods

cleanup()
complete([argument, fragment])
help(*args)
run([options, args])
usage()
name = 'serve'
class libbe.command.serve.ServerApp(storage, *args, **kwargs)

WSGI server for a BE Storage instance over HTTP.

RESTful WSGI request handler for serving the libbe.storage.http.HTTP backend with GET, POST, and HEAD commands. For more information on authentication and REST, see John Calcote’s Open Sourcery article

This serves files from a connected storage instance, usually a VCS-based repository located on the local machine.

Notes

The GET and HEAD requests are identical except that the HEAD request omits the actual content of the file.

Methods

add(environ, start_response)
ancestors(environ, start_response)
changed(environ, start_response)
check_login(environ)
children(environ, start_response)
commit(environ, start_response)
data_get_boolean(data, key[, default, source])
data_get_id(data[, key, default, source])
data_get_string(data, key[, default, source])
error(environ, start_response, error, message) Make it easy to call start_response for errors.
exists(environ, start_response)
get(environ, start_response)
is_head(environ)
log_request(environ[, status, bytes])
ok_response(environ, start_response, content)
post_data(environ)
query_data(environ)
remove(environ, start_response)
revision_id(environ, start_response)
set(environ, start_response)
version(environ, start_response)
add(environ, start_response)
ancestors(environ, start_response)
changed(environ, start_response)
check_login(environ)
children(environ, start_response)
commit(environ, start_response)
exists(environ, start_response)
get(environ, start_response)
remove(environ, start_response)
revision_id(environ, start_response)
server_version = 'BE-server/1.0.1'
set(environ, start_response)
version(environ, start_response)
class libbe.command.serve.UppercaseHeaderApp(app, *args, **kwargs)

WSGI middleware that uppercases incoming HTTP headers.

From PEP 333, The start_response() Callable :

A reminder for server/gateway authors: HTTP header names are case-insensitive, so be sure to take that into consideration when examining application-supplied headers!

Methods

error(environ, start_response, error, message) Make it easy to call start_response for errors.
log_request(environ[, status, bytes])
class libbe.command.serve.User(uname=None, name=None, passhash=None, password=None)

Methods

from_string(string)
hash(password)
set_name(name)
set_password(password)
valid_login(password)
from_string(string)
hash(password)
set_name(name)
set_password(password)
valid_login(password)
class libbe.command.serve.Users(filename=None)

Methods

add_user(user)
clear(() -> None.  Remove all items from D.)
copy(() -> a shallow copy of D)
fromkeys(...) v defaults to None.
get((k[,d]) -> D[k] if k in D, ...)
has_key((k) -> True if D has a key k, else False)
items(() -> list of D’s (key, value) pairs, ...)
iteritems(() -> an iterator over the (key, ...)
iterkeys(() -> an iterator over the keys of D)
itervalues(...)
keys(() -> list of D’s keys)
load()
pop((k[,d]) -> v, ...) If key is not found, d is returned if given, otherwise KeyError is raised
popitem(() -> (k, v), ...) 2-tuple; but raise KeyError if D is empty.
save()
setdefault((k[,d]) -> D.get(k,d), ...)
update(([E, ...) If E present and has a .keys() method, does: for k in E: D[k] = E[k]
valid_login(uname, password)
values(() -> list of D’s values)
viewitems(...)
viewkeys(...)
viewvalues(...)
add_user(user)
load()
save()
valid_login(uname, password)
class libbe.command.serve.WSGI_AppObject(*args, **kwargs)

Useful WSGI utilities for handling data (POST, QUERY) and returning responses.

Methods

data_get_boolean(data, key[, default, source])
data_get_id(data[, key, default, source])
data_get_string(data, key[, default, source])
error(environ, start_response, error, message) Make it easy to call start_response for errors.
is_head(environ)
log_request(environ[, status, bytes])
ok_response(environ, start_response, content)
post_data(environ)
query_data(environ)
data_get_boolean(data, key, default=False, source='query')
data_get_id(data, key='id', default=<class 'libbe.command.serve._HandlerError'>, source='query')
data_get_string(data, key, default=None, source='query')
is_head(environ)
ok_response(environ, start_response, content, content_type='application/octet-stream', headers=[])
post_data(environ)
query_data(environ)
class libbe.command.serve.WSGI_Object(logger=None, log_level=20, log_format=None)

Utility class for WGSI clients and middleware.

For details on WGSI, see PEP 333

Methods

error(environ, start_response, error, message) Make it easy to call start_response for errors.
log_request(environ[, status, bytes])
error(environ, start_response, error, message, headers=[])

Make it easy to call start_response for errors.

log_request(environ, status='-1 OK', bytes=-1)
libbe.command.serve.createCertRequest(pkey, digest='md5', **name)

Create a certificate request.

Returns the certificate request in an X509Req object.

Parameters :

pkey : PKey

The key to associate with the request.

digest : “md5” or ?

Digestion method to use for signing, default is “md5”,

`**name` : :

The name of the subject of the request, possible. Arguments are:

C

Country name

ST

State or province name

L

Locality name

O

Organization name

OU

Organizational unit name

CN

Common name

emailAddress

E-mail address

libbe.command.serve.createCertificate(req, (issuerCert, issuerKey), serial, (notBefore, notAfter), digest='md5')

Generate a certificate given a certificate request.

Returns the signed certificate in an X509 object.

Parameters :

req : :

Certificate reqeust to use

issuerCert : :

The certificate of the issuer

issuerKey : :

The private key of the issuer

serial : :

Serial number for the certificate

notBefore : :

Timestamp (relative to now) when the certificate starts being valid

notAfter : :

Timestamp (relative to now) when the certificate stops being valid

digest : :

Digest method to use for signing, default is md5

libbe.command.serve.createKeyPair(type, bits)

Create a public/private key pair.

Returns the public/private key pair in a PKey object.

Parameters :

type : TYPE_RSA or TYPE_DSA

Key type.

bits : int

Number of bits to use in the key.

libbe.command.serve.get_cert_filenames(server_name, autogenerate=True, logger=None)

Generate private key and certification filenames. get_cert_filenames(server_name) -> (pkey_filename, cert_filename)

libbe.command.serve.make_certs(server_name, logger=None)

Generate private key and certification files.

mk_certs(server_name) -> (pkey_filename, cert_filename)

libbe.command.serve.random_string(length=256)

Table Of Contents

This Page