~notmyname/swift/audit_fixes

« back to all changes in this revision

Viewing changes to bin/swift-auth-update-reseller-prefixes

  • Committer: gholt
  • Date: 2010-09-16 01:44:54 UTC
  • mto: This revision was merged to the branch mainline in revision 74.
  • Revision ID: gholt@rackspace.com-20100916014454-krxashhxmk0rgm5k
Notify if reseller_prefix does not match what is in auth.db

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
from os.path import basename
 
18
from sys import argv, exit
 
19
 
 
20
from swift.common.db import get_db_connection
 
21
 
 
22
 
 
23
if __name__ == '__main__':
 
24
    app = basename(argv[0])
 
25
    if len(argv) != 3:
 
26
        exit('''
 
27
Syntax : %s <auth.db> <new_prefix>
 
28
Example: %s /etc/swift/auth.db AUTH'''.strip() % (app, app))
 
29
    db = argv[1]
 
30
    new_prefix = argv[2].rstrip('_')
 
31
    print 'Updating %s' % db
 
32
    conn = get_db_connection(db)
 
33
    rows = conn.execute('SELECT url, cfaccount FROM account').fetchall()
 
34
    for row in rows:
 
35
        old_prefix = ''
 
36
        uuid = row[1]
 
37
        if '_' in row[1]:
 
38
            old_prefix, uuid = row[1].split('_', 1)
 
39
        new_cfaccount = '%s_%s' % (new_prefix, uuid)
 
40
        new_url = row[0].replace(row[1], new_cfaccount)
 
41
        print '%s ->\n%s' % (row[0], new_url)
 
42
        print '%s ->\n%s' % (row[1], new_cfaccount)
 
43
        print
 
44
        conn.execute('''UPDATE account SET url = ?, cfaccount = ?
 
45
                        WHERE url = ? AND cfaccount = ?''',
 
46
                     (new_url, new_cfaccount, row[0], row[1]))
 
47
    conn.commit()
 
48
    print 'Updated %s rows.' % len(rows)