~david-goetz/swift/db_double_quar

« back to all changes in this revision

Viewing changes to bin/swift-auth-to-swauth

  • Committer: Tarmac
  • Author(s): gholt
  • Date: 2011-03-15 15:52:34 UTC
  • mfrom: (241.2.2 swauthonly)
  • Revision ID: tarmac-20110315155234-hdy60f7s6dln140k
Remove DevAuth

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
# Copyright (c) 2010 OpenStack, LLC.
3
 
#
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
7
 
#
8
 
#    http://www.apache.org/licenses/LICENSE-2.0
9
 
#
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
13
 
# implied.
14
 
# See the License for the specific language governing permissions and
15
 
# limitations under the License.
16
 
 
17
 
import gettext
18
 
from subprocess import call
19
 
from sys import argv, exit
20
 
 
21
 
import sqlite3
22
 
 
23
 
 
24
 
if __name__ == '__main__':
25
 
    gettext.install('swift', unicode=1)
26
 
    if len(argv) != 2:
27
 
        exit('Syntax: %s <path_to_auth.db>' % argv[0])
28
 
    _junk, auth_db = argv
29
 
    conn = sqlite3.connect(auth_db)
30
 
    try:
31
 
        listing = conn.execute('SELECT account, cfaccount, user, password, '
32
 
                               'admin, reseller_admin FROM account')
33
 
    except sqlite3.OperationalError, err:
34
 
        listing = conn.execute('SELECT account, cfaccount, user, password, '
35
 
                               '"f", "f" FROM account')
36
 
    for account, cfaccount, user, password, admin, reseller_admin in listing:
37
 
        cmd = ['swauth-add-user', '-K', '<your_swauth_key>', '-s',
38
 
               cfaccount.split('_', 1)[1]]
39
 
        if admin == 't':
40
 
            cmd.append('-a')
41
 
        if reseller_admin == 't':
42
 
            cmd.append('-r')
43
 
        cmd.extend([account, user, password])
44
 
        print ' '.join(cmd)