view savane/backend/migrate_sshkeys.py @ 332:7234fcf49cc0

De-static-fy part of the track fields definition + data structure improvements
author Sylvain Beucler <beuc@beuc.net>
date Sun, 22 Aug 2010 16:53:15 +0200
parents 20584264d28c
children
line wrap: on
line source

# Migrate users' SSH keys from old Savane to new Savane
# Copyright (C) 2009  Jonathan Gonzalez
#
# This file is part of Savane.
#
# Savane is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# Savane is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Moves the keys stored at users.authorized_keys to a new table user.sshkeys


from savane.svmain.models import ExtendedUser, SshKey

sv_users = ExtendedUser.objects.all()
for sv_user in sv_users:
    keys = sv_user.sshkey_set.all()
    if keys is not None and len( keys ) == 1:
        keys = (keys[0].ssh_key or '').split('###')
        sv_user.sshkey_set.all().delete()
        for key in keys:
            if len(key) > 0:
                try:
                    ssh_key = SshKey(ssh_key=key)
                    sv_user.sshkey_set.add(ssh_key)
                    remove = True
                except:
                    print "User: %s Failed" % sv_user.username