X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fserver%2Fsfa-ca.py;h=9ab75e7e5998bbbac02c9a547e4587b3843ad744;hb=fce75353564503c071680974dba9938be6503e6f;hp=8297b2ddbcfba56c3d34d874dbb6bab58bb97edd;hpb=dc275f2cd6bfc8938e35c4676019d95eb5a71338;p=sfa.git diff --git a/sfa/server/sfa-ca.py b/sfa/server/sfa-ca.py index 8297b2dd..9ab75e7e 100755 --- a/sfa/server/sfa-ca.py +++ b/sfa/server/sfa-ca.py @@ -21,11 +21,14 @@ import os import sys from optparse import OptionParser -from sfa.trust.certificate import Keypair, Certificate + +from sfa.util.config import Config + from sfa.trust.gid import GID, create_uuid from sfa.trust.hierarchy import Hierarchy -from sfa.util.config import Config -from collections import defaultdict + +from sfa.storage.alchemy import dbsession +from sfa.storage.model import RegRecord def main(): args = sys.argv @@ -110,28 +113,24 @@ def sign(options): def export_gid(options): - from sfa.util.table import SfaTable # lookup the record for the specified hrn hrn = options.export type = options.type # check sfa table first - filter = {'hrn': hrn} - if type: - filter['type'] = type - table = SfaTable() - records = table.find(filter) - if not records: + request=dbsession.query(RegRecord).filter_by(hrn=hrn) + if type: request = request.filter_by(type=type) + record=request.first() + if not record: # check the authorities hierarchy hierarchy = Hierarchy() try: - auth_info = hierarchy.get_auth_info() + auth_info = hierarchy.get_auth_info(hrn) gid = auth_info.gid_object except: print "Record: %s not found" % hrn sys.exit(1) else: - record = records[0] - gid = GID(string=record['gid']) + gid = GID(string=record.gid) # get the outfile outfile = options.outfile @@ -148,8 +147,6 @@ def import_gid(options): Import the specified gid into the registry (db and authorities hierarchy) overwriting any previous gid. """ - from sfa.util.table import SfaTable - from sfa.util.record import SfaRecord # load the gid gidfile = os.path.abspath(options.importgid) if not gidfile or not os.path.isfile(gidfile): @@ -164,16 +161,14 @@ def import_gid(options): sys.exit(1) # check if record exists in db - table = SfaTable() - records = table.find({'hrn': gid.get_hrn(), 'type': 'authority'}) - if not records: - print "%s not found in record database" % get.get_hrn() + record = dbsession.query(RegRecord).filter_by(type='authority',hrn=gid.get_hrn()).first() + if not record: + print "%s not found in record database" % gid.get_hrn() sys.exit(1) # update the database record - record = records[0] - record['gid'] = gid.save_to_string(save_parents=True) - table.update(record) + record.gid = gid.save_to_string(save_parents=True) + dbsession.commit() if options.verbose: print "Imported %s gid into db" % record['hrn']