X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fclient%2Fsfaresetgids.py;h=d4d46f6ad6808b00b169d5006499b4cce2e716ea;hb=834c2d04d922f2ac5d67b5b45b4aac69435ae3e7;hp=c493601749e699e0782b5ee7e9c54c1636dfe581;hpb=8c0bf91e46675c699393dc209794ade4733ef3da;p=sfa.git diff --git a/sfa/client/sfaresetgids.py b/sfa/client/sfaresetgids.py index c4936017..d4d46f6a 100644 --- a/sfa/client/sfaresetgids.py +++ b/sfa/client/sfaresetgids.py @@ -1,3 +1,5 @@ +#!/usr/bin/python + from __future__ import print_function from argparse import ArgumentParser @@ -6,6 +8,8 @@ from sfa.util.config import Config from sfa.storage.alchemy import alchemy from sfa.storage.model import RegRecord from sfa.trust.hierarchy import Hierarchy +from sfa.trust.certificate import convert_public_key, Keypair +from sfa.util.xrn import hrn_to_urn """ WARNING : This script is not exactly thoroughly tested @@ -75,11 +79,13 @@ class SfaResetGids: recreate only for entities not present in SFA_DATA_DIR """ - count_auths, count_users = 0, 0 + count_auths, count_users, count_slices = 0, 0, 0 hierarchy = Hierarchy() for record in self.records: - ########## not an autority nor a user : ignored - if 'authority' not in record.type and 'user' not in record.type: + print(record.hrn) + ########## not an autority nor a user nor a slice: ignored + # Just wondering what other type it could be... + if record.type not in ['authority', 'user', 'slice']: message = '' if record.gid: message = '[GID cleared]' @@ -96,33 +102,49 @@ class SfaResetGids: ########## user : rebuild a gid from pubkey and email if record.type == 'user': hrn = str(record.hrn) + urn = hrn_to_urn(hrn, str(record.type)) gid = record.get_gid_object() uuid = gid.get_uuid() pub = gid.get_pubkey() email = gid.get_email() print("pub {} uuid {}... email {}".format(pub, str(uuid)[:6], email)) - new_gid = hierarchy.create_gid(hrn, uuid, pub, email=email) + new_gid = hierarchy.create_gid(urn, uuid, pub, email=email) new_gid_str = new_gid.save_to_string() record.gid = new_gid_str print("NEW {} {} [{}]".format(record.type, record.hrn, email)) count_users += 1 continue ########## authorities - if policy in ('all', 'safe'): - redo = True - else: - redo = not hierarchy.auth_exists(record.hrn) - if not redo: - print("IGN (existing) {}".format(record.hrn)) - else: + if record.type == 'authority': + if policy in ('all', 'safe'): + redo = True + else: + redo = not hierarchy.auth_exists(record.hrn) + if not redo: + print("IGN (existing) {}".format(record.hrn)) + else: + print("NEW {} {}".format(record.type, record.hrn)) + # because we have it sorted we should not need create_parents + gid = hierarchy.create_auth(str(record.hrn)) + record.gid = gid + count_auths += 1 + ########## slices + if record.type == 'slice': + hrn = str(record.hrn) + urn = hrn_to_urn(hrn, str(record.type)) + gid = record.get_gid_object() + uuid = gid.get_uuid() + pub = gid.get_pubkey() + print("pub {} uuid {}...".format(pub, str(uuid)[:6])) + new_gid = hierarchy.create_gid(urn, uuid, pub) + new_gid_str = new_gid.save_to_string() + record.gid = new_gid_str print("NEW {} {}".format(record.type, record.hrn)) - # because we have it sorted we should not need create_parents - gid = hierarchy.create_auth(str(record.hrn)) - record.gid = gid - count_auths += 1 + count_slices += 1 + continue # - print("Committing to the DB {} new auth gids and {} new user gids" - .format(count_auths, count_users)) + print("Committing to the DB {} new auth gids and {} new user gids and {} new slice gids" + .format(count_auths, count_users, count_slices)) self.session.commit() return True