diff --git a/README b/README index 562cc74..09f2810 100644 --- a/README +++ b/README @@ -38,12 +38,26 @@ Quick Install set log_name = swauth super_admin_key = swauthkey -4) Restart your proxy server ``swift-init proxy reload``. +4) Restart your proxy server ``swift-init proxy reload`` -5) Initialize the Swauth backing store in Swift ``swauth-prep -K swauthkey``. +5) Initialize the Swauth backing store in Swift ``swauth-prep -K swauthkey`` 6) Add an account/user ``swauth-add-user -A http://127.0.0.1:8080/auth/ -K - swauthkey -a test tester testing``. + swauthkey -a test tester testing`` -7) Ensure it works ``st -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K - testing stat -v``. +7) Ensure it works ``swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K + testing stat -v`` + + +Web Admin Install +----------------- + +1) If you installed from packages, you'll need to cd to the webadmin directory + the package installed. This is ``/usr/share/doc/python-swauth/webadmin`` + with the Lucid packages. If you installed from source, you'll need to cd to + the webadmin directory in the source directory. + +2) Upload the Web Admin files with ``swift -A http://127.0.0.1:8080/auth/v1.0 + -U .super_admin:.super_admin -K swauthkey upload .webadmin .`` + +3) Open ``http://127.0.0.1:8080/auth/`` in your browser. diff --git a/doc/source/index.rst b/doc/source/index.rst index 099055c..34a61cb 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -45,15 +45,28 @@ Quick Install set log_name = swauth super_admin_key = swauthkey -4) Restart your proxy server ``swift-init proxy reload``. +4) Restart your proxy server ``swift-init proxy reload`` -5) Initialize the Swauth backing store in Swift ``swauth-prep -K swauthkey``. +5) Initialize the Swauth backing store in Swift ``swauth-prep -K swauthkey`` 6) Add an account/user ``swauth-add-user -A http://127.0.0.1:8080/auth/ -K - swauthkey -a test tester testing``. + swauthkey -a test tester testing`` -7) Ensure it works ``st -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K - testing stat -v``. +7) Ensure it works ``swift -A http://127.0.0.1:8080/auth/v1.0 -U test:tester -K + testing stat -v`` + +Web Admin Install +----------------- + +1) If you installed from packages, you'll need to cd to the webadmin directory + the package installed. This is ``/usr/share/doc/python-swauth/webadmin`` + with the Lucid packages. If you installed from source, you'll need to cd to + the webadmin directory in the source directory. + +2) Upload the Web Admin files with ``swift -A http://127.0.0.1:8080/auth/v1.0 + -U .super_admin:.super_admin -K swauthkey upload .webadmin .`` + +3) Open ``http://127.0.0.1:8080/auth/`` in your browser. Contents -------- diff --git a/swauth/middleware.py b/swauth/middleware.py index b790aeb..26884a7 100644 --- a/swauth/middleware.py +++ b/swauth/middleware.py @@ -30,8 +30,8 @@ from eventlet.timeout import Timeout from eventlet import TimeoutError from webob import Response, Request from webob.exc import HTTPAccepted, HTTPBadRequest, HTTPConflict, \ - HTTPCreated, HTTPForbidden, HTTPNoContent, HTTPNotFound, \ - HTTPServiceUnavailable, HTTPUnauthorized + HTTPCreated, HTTPForbidden, HTTPMethodNotAllowed, HTTPMovedPermanently, \ + HTTPNoContent, HTTPNotFound, HTTPServiceUnavailable, HTTPUnauthorized from swift.common.bufferedhttp import http_connect_raw as http_connect from swift.common.middleware.acl import clean_acl, parse_acl, referrer_allowed @@ -167,9 +167,12 @@ class Swauth(object): """ if 'HTTP_X_CF_TRANS_ID' not in env: env['HTTP_X_CF_TRANS_ID'] = 'tx' + str(uuid4()) - if not self.swauth_remote and \ - env.get('PATH_INFO', '').startswith(self.auth_prefix): - return self.handle(env, start_response) + if not self.swauth_remote: + if env.get('PATH_INFO', '') == self.auth_prefix[:-1]: + return HTTPMovedPermanently(add_slash=True)(env, + start_response) + elif env.get('PATH_INFO', '').startswith(self.auth_prefix): + return self.handle(env, start_response) s3 = env.get('HTTP_AUTHORIZATION') token = env.get('HTTP_X_AUTH_TOKEN', env.get('HTTP_X_STORAGE_TOKEN')) if s3 or (token and token.startswith(self.reseller_prefix)): @@ -424,7 +427,7 @@ class Swauth(object): handler = None try: version, account, user, _junk = split_path(req.path_info, - minsegs=1, maxsegs=4, rest_with_last=True) + minsegs=0, maxsegs=4, rest_with_last=True) except ValueError: return HTTPNotFound(request=req) if version in ('v1', 'v1.0', 'auth'): @@ -460,12 +463,23 @@ class Swauth(object): handler = self.handle_prep elif user == '.services': handler = self.handle_set_services + else: + handler = self.handle_webadmin if not handler: req.response = HTTPBadRequest(request=req) else: req.response = handler(req) return req.response + def handle_webadmin(self, req): + if req.method not in ('GET', 'HEAD'): + return HTTPMethodNotAllowed(request=req) + subpath = req.path[len(self.auth_prefix):] or 'index.html' + path = quote('/v1/%s/.webadmin/%s' % (self.auth_account, subpath)) + req.response = self.make_request(req.environ, req.method, + path).get_response(self.app) + return req.response + def handle_prep(self, req): """ Handles the POST v2/.prep call for preparing the backing store Swift diff --git a/webadmin/index.html b/webadmin/index.html new file mode 100644 index 0000000..cbc7c8a --- /dev/null +++ b/webadmin/index.html @@ -0,0 +1,552 @@ + + + + + + +
+
+
Swauth
+
+
+
+
+ +