Merge "Use account_autocreate for tempauth."

This commit is contained in:
Jenkins 2011-10-07 18:30:37 +00:00 committed by Gerrit Code Review
commit 30e71fa175
2 changed files with 6 additions and 21 deletions

View File

@ -270,6 +270,7 @@ Sample configuration files are provided with all defaults in line-by-line commen
[app:proxy-server] [app:proxy-server]
use = egg:swift#proxy use = egg:swift#proxy
allow_account_management = true allow_account_management = true
account_autocreate = true
[filter:tempauth] [filter:tempauth]
use = egg:swift#tempauth use = egg:swift#tempauth

View File

@ -40,6 +40,11 @@ class TempAuth(object):
[pipeline:main] [pipeline:main]
pipeline = catch_errors cache tempauth proxy-server pipeline = catch_errors cache tempauth proxy-server
Set account auto creation to true in proxy-server.conf::
[app:proxy-server]
account_autocreate = true
And add a tempauth filter section, such as:: And add a tempauth filter section, such as::
[filter:tempauth] [filter:tempauth]
@ -94,7 +99,6 @@ class TempAuth(object):
groups = values groups = values
self.users[conf_key.split('_', 1)[1].replace('_', ':')] = { self.users[conf_key.split('_', 1)[1].replace('_', ':')] = {
'key': key, 'url': url, 'groups': values} 'key': key, 'url': url, 'groups': values}
self.created_accounts = False
def __call__(self, env, start_response): def __call__(self, env, start_response):
""" """
@ -116,26 +120,6 @@ class TempAuth(object):
will be routed through the internal auth request handler (self.handle). will be routed through the internal auth request handler (self.handle).
This is to handle granting tokens, etc. This is to handle granting tokens, etc.
""" """
# Ensure the accounts we handle have been created
if not self.created_accounts and self.users:
newenv = {'REQUEST_METHOD': 'HEAD', 'HTTP_USER_AGENT': 'TempAuth'}
for name in ('swift.cache', 'HTTP_X_TRANS_ID'):
if name in env:
newenv[name] = env[name]
for key, value in self.users.iteritems():
account_id = value['url'].rsplit('/', 1)[-1]
newenv['REQUEST_METHOD'] = 'HEAD'
resp = Request.blank('/v1/' + account_id,
environ=newenv).get_response(self.app)
if resp.status_int // 100 != 2:
newenv['REQUEST_METHOD'] = 'PUT'
resp = Request.blank('/v1/' + account_id,
environ=newenv).get_response(self.app)
if resp.status_int // 100 != 2:
raise Exception('Could not create account %s for user '
'%s' % (account_id, key))
self.created_accounts = True
if env.get('PATH_INFO', '').startswith(self.auth_prefix): if env.get('PATH_INFO', '').startswith(self.auth_prefix):
return self.handle(env, start_response) return self.handle(env, start_response)
s3 = env.get('HTTP_AUTHORIZATION') s3 = env.get('HTTP_AUTHORIZATION')