Example #1
0
 def add_service(self, system, ymlfile):
     """
     Add Fake data service mapping records. We provide system name
     which match corresponding name in DASTestDataService and
     associated with this system YML map file.
     """
     fname  = os.path.join(DASPATH, 'services/maps/%s' % ymlfile)
     url    = self.base + '/%s' % system
     for record in read_service_map(fname):
         record['url'] = url
         record['system'] = system
         self.mgr.add(record)
     for record in read_service_map(fname, 'notations'):
         record['system'] = system
         self.mgr.add(record)
Example #2
0
def main():
    """Main function"""
    opt_mgr = DASOptionParser()
    (opts, _args) = opt_mgr.get_opt()

    if  opts.umap:
        for rec in read_service_map(opts.umap, field='uri'):
            print json.dumps(rec)

    if  opts.nmap:
        for rec in read_service_map(opts.nmap, field='notations'):
            print json.dumps(rec)

    if  opts.pmap:
        for rec in read_service_map(opts.pmap, field='presentation'):
            print json.dumps(rec)
Example #3
0
def main():
    """Main function"""
    opt_mgr = DASOptionParser()
    opts, _ = opt_mgr.get_opt()

    if  opts.umap:
        count = 0
        system = ''
        for rec in read_service_map(opts.umap, field='uri'):
            print(json.dumps(rec))
            count += 1
            system = rec['system']
        if  system: # notations map must have system
            arecord = {'type': 'service', 'count': count, 'system': system}
            print(json.dumps(dict(arecord=arecord)))
        # output record(s) containing uris for listing allowed input_values
        for rec in read_service_map(opts.umap, field='input_values'):
            print(json.dumps(rec))

    if  opts.nmap:
        count = 0
        system = ''
        for rec in read_service_map(opts.nmap, field='notations'):
            print(json.dumps(rec))
            count += 1
            system = rec['system']
        if  system: # notations map must have system
            arecord = {'type': 'notation', 'count': count, 'system': system}
            print(json.dumps(dict(arecord=arecord)))

    if  opts.pmap:
        count = 0
        system = 'presentation'
        for rec in read_service_map(opts.pmap, field='presentation'):
            print(json.dumps(rec))
            count += 1
        if  count == 1: # we should have one presentation map
            arecord = {'type': 'presentation', 'count': count, 'system': system}
            print(json.dumps(dict(arecord=arecord)))

    # generate a verification token composed of all record hashes
    if opts.get_verification_token_for:
        with open(opts.get_verification_token_for) as file_:
            token = verification_token(json.loads(line)
                                       for line in file_ if line)
            print(json.dumps({'verification_token': token,
                              'type': 'verification_token'}))
Example #4
0
 def add_service(self, system, ymlfile):
     """
     Add Fake data service mapping records. We provide system name
     which match corresponding name in DASTestDataService and
     associated with this system YML map file.
     """
     conn  = db_connection(self.dburi)
     dbc   = conn['mapping']
     col   = dbc[self.collname]
     fname = os.path.join(DASPATH, 'services/maps/%s' % ymlfile)
     url   = self.base + '/%s' % system
     for record in read_service_map(fname):
         record['url'] = url
         record['system'] = system
         col.insert(record)
     for record in read_service_map(fname, 'notations'):
         record['system'] = system
         col.insert(record)
Example #5
0
 def testReader(self): 
     """test read_service_map function"""
     apimap  = dict(self.apimap)
     del apimap['created']
     fdescr  = tempfile.NamedTemporaryFile()
     mapfile = fdescr.name
     stream  = file(mapfile, 'w')
     yaml.dump(apimap, stream)
     result  = [r for r in read_service_map(mapfile)][0]
     result.pop('created')
     self.assertEqual(apimap, result)
Example #6
0
 def testReader(self):
     """test read_service_map function"""
     apimap = dict(self.apimap)
     del apimap['ts']
     fdescr = tempfile.NamedTemporaryFile()
     mapfile = fdescr.name
     stream = open(mapfile, 'w')
     yaml.dump(apimap, stream)
     result = [r for r in read_service_map(mapfile)][0]
     result.pop('ts')
     result.pop('hash')
     self.assertEqual(apimap, result)
     stream.close()
Example #7
0
def main():
    "Main function"
    optmgr = DASOptionParser()
    (opts, _args) = optmgr.getOpt()

    dburi     = 'mongodb://%s:%s' % (opts.host, opts.port)
    dasconfig = das_readconfig()
    dbname, colname = opts.db.split('.')
    mongodb   = dict(dburi=dburi)
    mappingdb = dict(dbname=dbname, collname=colname)
    config    = dict(verbose=opts.debug, mappingdb=mappingdb,
                mongodb=mongodb, services=dasconfig['das'].get('services', []))

    mgr = DASMapping(config)

    if  opts.listapis:
        apis = mgr.list_apis(opts.system)
        print apis
        sys.exit(0)

    if  opts.listkeys:
        keys = mgr.daskeys(opts.system)
        print keys
        sys.exit(0)

    if  opts.umap:
        for rec in read_service_map(opts.umap, field='uri'):
            if  opts.debug:
                print rec
            spec = {'url':rec['url'], 'urn':rec['urn']}
            mgr.remove(spec) # remove previous record
            mgr.add(rec)

    if  opts.nmap:
        for rec in read_service_map(opts.nmap, field='notations'):
            if  opts.debug:
                print rec
            system = rec['system']
            spec = {'notations':{'$exists':True}, 'system':system}
            mgr.remove(spec) # remove previous record
            mgr.add(rec)

    if  opts.pmap:
        for rec in read_service_map(opts.pmap, field='presentation'):
            if  opts.debug:
                print rec
            spec = {'presentation':{'$exists':True}}
            mgr.remove(spec) # remove previous record
            mgr.add(rec)

    if  opts.clean:
        mgr.delete_db()
        mgr.create_db()
        # I need to clear DAS cache/merge since I don't know
        # a-priory what kind of changes new maps will bring
        conn   = db_connection(dburi)
        dbname = dasconfig['dasdb']['dbname']
        cache  = conn[dbname][dasconfig['dasdb']['cachecollection']]
        cache.remove({})
        merge  = conn[dbname][dasconfig['dasdb']['mergecollection']]
        merge.remove({})

    if  opts.remove:
        mgr.remove(opts.remove)