コード例 #1
0
def writeConfig(data):
    if mutex.acquire(timeout=1) == False:
        log.error('mutex timeout')
        return

    utils.writeJsonFile(filepath, data, log)
    mutex.release()
コード例 #2
0
 def run(self):
     packets = []
     ignored = []
     bucket_names = getJsonFile(bucketListPath)
     for bucket_name in bucket_names:
         if regMatch(r"^[1-9]\d{28}$", bucket_name):
             packets.append(bucket_name)
         else:
             ignored.append(bucket_name)
     writeJsonFile(packetListPath, packets)
     writeJsonFile(ignoredBucketListPath, ignored)
     myPrint("Total " + str(len(packets)) + " packets found")
     myPrint("Total " + str(len(ignored)) + " ignored buckets found")
コード例 #3
0
ファイル: main.py プロジェクト: lalithkota/mosip-infra
def main():
    args, parser = args_parse()
    initLogger(logPath)
    start_time = getTimeInSec()
    myPrint(conf.minio_endpoint)
    try:
        prev_time = start_time
        if args.action == 'get_buckets' or args.action == 'all':
            myPrint("Action: get_buckets", 1)
            GetBuckets().run()
            prev_time, prstr = timeDiff(prev_time)
            myPrint("Time taken by Action get_buckets: " + prstr, 11)
        if args.action == 'find_packets' or args.action == 'all':
            myPrint("Action: find_packets", 1)
            FindPackets().run()
            prev_time, prstr = timeDiff(prev_time)
            myPrint("Time taken by Action find_packets: " + prstr, 11)
        if args.action == 'migrate' or args.action == 'all':
            myPrint("Action: migrate", 1)
            Migration().run()
            prev_time, prstr = timeDiff(prev_time)
            myPrint("Time taken by Action migrate: " + prstr, 11)
        if args.action == 'get_records' or args.action == 'all':
            myPrint("Action: get_records", 1)
            m = MinioWrapper()
            objs = m.listObjects(conf.new_bucket_name, False)
            new_objs = []
            for ob in objs:
                new_objs.append(ob.replace("/", ""))
            writeJsonFile(migratedPackets, new_objs)
            myPrint("Total objects level 1 " + str(len(new_objs)))
            prev_time, prstr = timeDiff(prev_time)
            myPrint("Time taken by Action get_records: " + prstr, 11)
    except:
        prev_time, prstr = timeDiff(start_time)
        myPrint("Total time taken by the script: " + prstr, 11)
        formatted_lines = traceback.format_exc()
        myPrint(formatted_lines, 13)
        sys.exit(1)
    prev_time, prstr = timeDiff(start_time)
    myPrint("Total time taken by the script: " + prstr, 11)
    return sys.exit(0)
コード例 #4
0
ファイル: get_buckets.py プロジェクト: lalithkota/mosip-infra
 def run(self):
     bucket_names = self.m.listBucketNames()
     writeJsonFile(bucketListPath, bucket_names)
     myPrint("Total " + str(len(bucket_names)) + " buckets found")
コード例 #5
0
ファイル: config_ex.py プロジェクト: Brollof/Yamori
def saveData(data):
    writeJsonFile(filepath, data, log)
コード例 #6
0
ファイル: main.py プロジェクト: lalithkota/mosip-infra
def main():
    args, parser = args_parse()
    initLogger(logPath)
    start_time = getTimeInSec()
    db = DatabaseSession(conf.db_host, conf.db_port, conf.db_user,
                         conf.db_pass)
    try:
        prev_time = start_time
        if args.action == 'get_vids' or args.action == 'all':
            myPrint("Action: get_vids", 1)
            vids = []
            vid_dicts = db.getVids()
            for vid_dict in vid_dicts:
                vids.append(vid_dict['vid'])
            writeJsonFile(vidListPath, vids)
            prev_time, prstr = timeDiff(prev_time)
            myPrint("Time taken by Action get_vids: " + prstr, 11)
        if args.action == 'fetch_info' or args.action == 'all':
            output = []
            myPrint("Action: fetch_info", 1)
            ms = MosipSession(conf.server, conf.regproc_client_id,
                              conf.regproc_secret_key, conf.regproc_app_id)
            vids = getJsonFile(vidListPath)
            for vid in vids:
                myPrint("Operating on VID " + vid, 3)
                res = ms.getUin(vid)
                uin = res['identity']['UIN']
                if conf.debug:
                    myPrint("UIN: " + uin)

                modulo = int(uin) % conf.idrepo_modulo
                myPrint("Modulo: " + str(modulo))
                salt_row = db.getHash(modulo)
                if salt_row is not None:
                    salt = salt_row['salt']
                    if conf.debug:
                        myPrint("Salt: " + salt)
                    uin_hash = hashlib.sha256(bytes(uin + salt,
                                                    'utf-8')).hexdigest()
                    mod_uin_hash = str(modulo) + "_" + uin_hash.upper()
                    rid_row = db.getRid(mod_uin_hash)
                    if rid_row is not None:
                        rid = rid_row['rid']
                        myPrint("RID found")
                        if conf.debug:
                            myPrint("RID: " + rid)
                        center_id, timestamp = ridToCenterTimestamp(rid)
                        output.append({
                            'vid': vid,
                            'uin': uin,
                            'mod_uin_hash': mod_uin_hash,
                            'salt': salt,
                            'rid': rid,
                            'center_id': center_id,
                            'timestamp': timestamp
                        })
                    else:
                        raise RuntimeError(
                            "RID not found for for mod_uin_hash: " +
                            mod_uin_hash)
                else:
                    raise RuntimeError("salt not found for for modulo: " +
                                       str(modulo))
            writeJsonFile(credentialPreparedDataPath, output)
            prev_time, prstr = timeDiff(prev_time)
            myPrint("Time taken by Action fetch_info: " + prstr, 11)

        if args.action == 'reprint' or args.action == 'all':
            myPrint("Action: reprint", 1)
            output = []
            vids = getJsonFile(credentialPreparedDataPath)
            ms = MosipSession(conf.server, conf.ida_client_id,
                              conf.ida_secret_key, conf.ida_app_id)
            for vidInfo in vids:
                myPrint("VID: " + vidInfo['vid'], 3)
                data = {
                    "id": vidInfo['vid'],
                    "credentialType": conf.credential_type,
                    "issuer": conf.partner_id,
                    "recepiant": "",
                    "user": "******",
                    "encrypt": False,
                    "encryptionKey": "",
                    "sharableAttributes": [],
                    "additionalData": {
                        'centerId': vidInfo['center_id'],
                        'creationDate': vidInfo['timestamp'],
                        'registrationId': vidInfo['rid']
                    }
                }
                json_data = json.dumps(data, separators=(',', ':'))
                myPrint(json_data)
                if db.checkRequestInCredentialTransaction(json_data) is None:
                    resp = ms.credentialRequest(data)
                    output.append(resp)
                else:
                    myPrint("Skipping credential request", 11)
            writeJsonFile(vidRequestId, output)
            myPrint('Input VIDs: ' + str(len(vids)), 12)
            myPrint('Output RequestIds: ' + str(len(output)), 12)
            prev_time, prstr = timeDiff(prev_time)
            myPrint("Time taken by Action reprint: " + prstr, 11)
        db.closeAll()
    except:
        db.closeAll()
        prev_time, prstr = timeDiff(start_time)
        myPrint("Total time taken by the script: " + prstr, 11)
        formatted_lines = traceback.format_exc()
        myPrint(formatted_lines, 13)
        sys.exit(1)
    prev_time, prstr = timeDiff(start_time)
    myPrint("Total time taken by the script: " + prstr, 11)
    return sys.exit(0)