2
# Copyright (c) 2010 OpenStack, LLC.
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
8
# http://www.apache.org/licenses/LICENSE-2.0
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14
# See the License for the specific language governing permissions and
15
# limitations under the License.
18
from optparse import OptionParser
19
from os.path import basename
20
from sys import argv, exit
21
from urlparse import urlparse
23
from swift.common.bufferedhttp import http_connect_raw as http_connect
26
if __name__ == '__main__':
27
gettext.install('swift', unicode=1)
28
parser = OptionParser(usage='Usage: %prog [options]')
29
parser.add_option('-A', '--admin-url', dest='admin_url',
30
default='http://127.0.0.1:8080/auth/', help='The URL to the auth '
31
'subsystem (default: http://127.0.0.1:8080/auth/')
32
parser.add_option('-U', '--admin-user', dest='admin_user',
33
default='.super_admin', help='The user with admin rights to add users '
34
'(default: .super_admin).')
35
parser.add_option('-K', '--admin-key', dest='admin_key',
36
help='The key for the user with admin rights to add users.')
40
(options, args) = parser.parse_args(args)
42
parser.parse_args(['-h'])
43
parsed = urlparse(options.admin_url)
44
if parsed.scheme not in ('http', 'https'):
45
raise Exception('Cannot handle protocol scheme %s for url %s' %
46
(parsed.scheme, repr(options.admin_url)))
49
elif parsed.path[-1] != '/':
51
path = '%sv2/.prep' % parsed.path
52
headers = {'X-Auth-Admin-User': options.admin_user,
53
'X-Auth-Admin-Key': options.admin_key}
54
conn = http_connect(parsed.hostname, parsed.port, 'POST', path, headers,
55
ssl=(parsed.scheme == 'https'))
56
resp = conn.getresponse()
57
if resp.status // 100 != 2:
58
print 'Auth subsystem prep failed: %s %s' % (resp.status, resp.reason)