+ save_records_to_file(outfile, records)
+
+
+ def _record_dict(self, xrn, type, email, key,
+ slices, researchers, pis,
+ url, description, extras):
+ record_dict = {}
+ if xrn:
+ if type:
+ xrn = Xrn(xrn, type)
+ else:
+ xrn = Xrn(xrn)
+ record_dict['urn'] = xrn.get_urn()
+ record_dict['hrn'] = xrn.get_hrn()
+ record_dict['type'] = xrn.get_type()
+ if url:
+ record_dict['url'] = url
+ if description:
+ record_dict['description'] = description
+ if key:
+ try:
+ pubkey = open(key, 'r').read()
+ except IOError:
+ pubkey = key
+ record_dict['reg-keys'] = [pubkey]
+ if slices:
+ record_dict['slices'] = slices
+ if researchers:
+ record_dict['reg-researchers'] = researchers
+ if email:
+ record_dict['email'] = email
+ if pis:
+ record_dict['reg-pis'] = pis
+ if extras:
+ record_dict.update(extras)
+ return record_dict
+
+
+ @add_options('-x', '--xrn', dest='xrn', metavar='<xrn>', help='object hrn/urn', default=None)
+ @add_options('-t', '--type', dest='type', metavar='<type>', help='object type (mandatory)',)
+ @add_options('-a', '--all', dest='all', metavar='<all>', action='store_true', default=False, help='check all users GID')
+ @add_options('-v', '--verbose', dest='verbose', metavar='<verbose>', action='store_true', default=False, help='verbose mode: display user\'s hrn ')
+ def check_gid(self, xrn=None, type=None, all=None, verbose=None):
+ """Check the correspondance between the GID and the PubKey"""
+
+ # db records
+ from sfa.storage.model import RegRecord
+ db_query = self.api.dbsession().query(RegRecord).filter_by(type=type)
+ if xrn and not all:
+ hrn = Xrn(xrn).get_hrn()
+ db_query = db_query.filter_by(hrn=hrn)
+ elif all and xrn:
+ print "Use either -a or -x <xrn>, not both !!!"
+ sys.exit(1)
+ elif not all and not xrn:
+ print "Use either -a or -x <xrn>, one of them is mandatory !!!"
+ sys.exit(1)
+
+ records = db_query.all()
+ if not records:
+ print "No Record found"
+ sys.exit(1)
+
+ OK = []
+ NOK = []
+ ERROR = []
+ NOKEY = []
+ for record in records:
+ # get the pubkey stored in SFA DB
+ if record.reg_keys:
+ db_pubkey_str = record.reg_keys[0].key
+ try:
+ db_pubkey_obj = convert_public_key(db_pubkey_str)
+ except:
+ ERROR.append(record.hrn)
+ continue
+ else:
+ NOKEY.append(record.hrn)
+ continue
+
+ # get the pubkey from the gid
+ gid_str = record.gid
+ gid_obj = GID(string = gid_str)
+ gid_pubkey_obj = gid_obj.get_pubkey()
+
+ # Check if gid_pubkey_obj and db_pubkey_obj are the same
+ check = gid_pubkey_obj.is_same(db_pubkey_obj)
+ if check :
+ OK.append(record.hrn)
+ else:
+ NOK.append(record.hrn)
+
+ if not verbose:
+ print "Users NOT having a PubKey: %s\n\
+Users having a non RSA PubKey: %s\n\
+Users having a GID/PubKey correpondence OK: %s\n\
+Users having a GID/PubKey correpondence Not OK: %s\n"%(len(NOKEY), len(ERROR), len(OK), len(NOK))
+ else:
+ print "Users NOT having a PubKey: %s and are: \n%s\n\n\
+Users having a non RSA PubKey: %s and are: \n%s\n\n\
+Users having a GID/PubKey correpondence OK: %s and are: \n%s\n\n\
+Users having a GID/PubKey correpondence NOT OK: %s and are: \n%s\n\n"%(len(NOKEY),NOKEY, len(ERROR), ERROR, len(OK), OK, len(NOK), NOK)
+
+
+
+ @add_options('-x', '--xrn', dest='xrn', metavar='<xrn>', help='object hrn/urn (mandatory)')
+ @add_options('-t', '--type', dest='type', metavar='<type>', help='object type', default=None)
+ @add_options('-e', '--email', dest='email', default="",
+ help="email (mandatory for users)")
+ @add_options('-u', '--url', dest='url', metavar='<url>', default=None,
+ help="URL, useful for slices")
+ @add_options('-d', '--description', dest='description', metavar='<description>',
+ help='Description, useful for slices', default=None)
+ @add_options('-k', '--key', dest='key', metavar='<key>', help='public key string or file',
+ default=None)
+ @add_options('-s', '--slices', dest='slices', metavar='<slices>', help='Set/replace slice xrns',
+ default='', type="str", action='callback', callback=optparse_listvalue_callback)
+ @add_options('-r', '--researchers', dest='researchers', metavar='<researchers>', help='Set/replace slice researchers',
+ default='', type="str", action='callback', callback=optparse_listvalue_callback)
+ @add_options('-p', '--pis', dest='pis', metavar='<PIs>',
+ help='Set/replace Principal Investigators/Project Managers',
+ default='', type="str", action='callback', callback=optparse_listvalue_callback)
+ @add_options('-X','--extra',dest='extras',default={},type='str',metavar="<EXTRA_ASSIGNS>",
+ action="callback", callback=optparse_dictvalue_callback, nargs=1,
+ help="set extra/testbed-dependent flags, e.g. --extra enabled=true")
+ def register(self, xrn, type=None, email='', key=None,
+ slices='', pis='', researchers='',
+ url=None, description=None, extras={}):
+ """Create a new Registry record"""
+ record_dict = self._record_dict(xrn=xrn, type=type, email=email, key=key,
+ slices=slices, researchers=researchers, pis=pis,
+ url=url, description=description, extras=extras)
+ self.api.manager.Register(self.api, record_dict)
+
+
+ @add_options('-x', '--xrn', dest='xrn', metavar='<xrn>', help='object hrn/urn (mandatory)')
+ @add_options('-t', '--type', dest='type', metavar='<type>', help='object type', default=None)
+ @add_options('-u', '--url', dest='url', metavar='<url>', help='URL', default=None)
+ @add_options('-d', '--description', dest='description', metavar='<description>',
+ help='Description', default=None)
+ @add_options('-k', '--key', dest='key', metavar='<key>', help='public key string or file',
+ default=None)
+ @add_options('-s', '--slices', dest='slices', metavar='<slices>', help='Set/replace slice xrns',
+ default='', type="str", action='callback', callback=optparse_listvalue_callback)
+ @add_options('-r', '--researchers', dest='researchers', metavar='<researchers>', help='Set/replace slice researchers',
+ default='', type="str", action='callback', callback=optparse_listvalue_callback)
+ @add_options('-p', '--pis', dest='pis', metavar='<PIs>',
+ help='Set/replace Principal Investigators/Project Managers',
+ default='', type="str", action='callback', callback=optparse_listvalue_callback)
+ @add_options('-X','--extra',dest='extras',default={},type='str',metavar="<EXTRA_ASSIGNS>",
+ action="callback", callback=optparse_dictvalue_callback, nargs=1,
+ help="set extra/testbed-dependent flags, e.g. --extra enabled=true")
+ def update(self, xrn, type=None, email='', key=None,
+ slices='', pis='', researchers='',
+ url=None, description=None, extras={}):
+ """Update an existing Registry record"""
+ record_dict = self._record_dict(xrn=xrn, type=type, email=email, key=key,
+ slices=slices, researchers=researchers, pis=pis,
+ url=url, description=description, extras=extras)
+ self.api.manager.Update(self.api, record_dict)