示例#1
0
def ParseCommandLine(config, args):
    logger.info(
        '***************** INTEL TRUSTED COMPUTE FRAMEWORK (TCF)*****************'
    )
    global input_json_str
    global input_json_dir
    global server_uri
    global output_json_file_name
    global consensus_file_name
    global sig_obj
    global worker_obj
    global private_key
    global encrypted_session_key
    global session_iv

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--logfile",
        help="Name of the log file, __screen__ for standard output",
        type=str)
    parser.add_argument("-p",
                        "--private_key",
                        help="Private Key of the Client",
                        type=str,
                        default=None)
    parser.add_argument("--loglevel", help="Logging level", type=str)
    parser.add_argument("-i",
                        "--input_file",
                        help="JSON input file name",
                        type=str,
                        default="input.json")
    parser.add_argument("--input_dir",
                        help="Logging level",
                        type=str,
                        default=[])
    parser.add_argument("-c",
                        "--connect_uri",
                        help="URI to send requests to",
                        type=str,
                        default=[])
    parser.add_argument("output_file",
                        help="JSON output file name",
                        type=str,
                        default="output.json",
                        nargs="?")

    options = parser.parse_args(args)

    if config.get("Logging") is None:
        config["Logging"] = {"LogFile": "__screen__", "LogLevel": "INFO"}
    if options.logfile:
        config["Logging"]["LogFile"] = options.logfile
    if options.loglevel:
        config["Logging"]["LogLevel"] = options.loglevel.upper()

    input_json_str = None
    input_json_dir = None

    if options.connect_uri:
        server_uri = options.connect_uri
    else:
        logger.error("ERROR: Please enter the server URI")

    if options.input_dir:
        logger.info("Load Json Directory from %s", options.input_dir)
        input_json_dir = options.input_dir
    elif options.input_file:
        try:
            logger.info("load JSON input from %s", options.input_file)
            with open(options.input_file, "r") as file:
                input_json_str = file.read()
        except:
            logger.error("ERROR: Failed to read from file %s",
                         options.input_file)
    else:
        logger.info("No input found")

    if options.output_file:
        output_json_file_name = options.output_file
    else:
        output_json_file_name = None

    if options.private_key:
        private_key = options.private_key
    else:
        #Generating the private Key for the client
        private_key = enclave_helper.generate_signing_keys()

    # Initializing Signature object, Worker Object
    sig_obj = signature.ClientSignature()
    worker_obj = worker.WorkerDetails()
def ParseCommandLine(args):

        global worker_obj
        global worker_id
        global message
        global config
        global off_chain

        parser = argparse.ArgumentParser()
        use_service = parser.add_mutually_exclusive_group()
        parser.add_argument("-c", "--config",
                            help="the config file containing the Ethereum " + "
                            "contract information",
                            type=str)
        use_service.add_argument("-r", "--registry-list",
                                 help="the Ethereum address of the " +
                                 "registry list",
                                 type=str)
        use_service.add_argument("-s", "--service-uri",
                                 help="skip URI lookup and send to " +
                                 "specified URI",
                                 type=str)
        use_service.add_argument("-o", "--off-chain",
                                 help="skip URI lookup and use the registry " +
                                 "in the config file",
                                 action="store_true")
        parser.add_argument("-w", "--worker-id",
                            help="skip worker lookup and retrieve " +
                            "specified worker",
                            type=str)
        parser.add_argument("-m", "--message",
                            help="text message to be included in the " +
                            "JSON request payload",
                            type=str)

        options = parser.parse_args(args)

        if options.config:
            conffiles = [options.config]
        else:
            conffiles = [TCFHOME + "/examples/common/python/connectors/" +
                         "tcf_connector.toml"]
        confpaths = ["."]
        try:
                config = pconfig.parse_configuration_files(
                    conffiles, confpaths)
                json.dumps(config)
        except pconfig.ConfigurationException as e:
                logger.error(str(e))
                sys.exit(-1)

        global direct_wrapper
        direct_wrapper = DirectAdaptorFactoryWrapper(conffiles[0])

        # Whether or not to connect to the registry list on the blockchain
        off_chain = False

        if options.registry_list:
                config["ethereum"]["direct_registry_contract_address"] = \
                    options.registry_list

        if options.service_uri:
                config["tcf"]["json_rpc_uri"] = options.service_uri
                off_chain = True

        if options.off_chain:
                off_chain = True

        worker_id = options.worker_id
        message = options.message
        if options.message is None or options.message == "":
                message = "Hello world"

        # Initializing Worker Object
        worker_obj = worker.WorkerDetails()
def ParseCommandLine(config, args) :
    logger.info('***************** INTEL TRUSTED COMPUTE FRAMEWORK (TCF)*****************') 
    global input_json_str
    global input_json_dir
    global server_uri
    global output_json_file_name
    global consensus_file_name
    global sig_obj
    global worker_obj
    global private_key
    
    parser = argparse.ArgumentParser()
    parser.add_argument('--logfile', help='Name of the log file, __screen__ for standard output', type=str)
    parser.add_argument('-p', '--private_key',help="Private Key of the Client", type=str, default=None)
    parser.add_argument('--loglevel', help='Logging level', type=str)
    parser.add_argument('-i', '--input_file', help='JSON input file name', type=str, default='input.json')
    parser.add_argument('--input_dir', help='Logging level', type=str, default=[])
    parser.add_argument(
        '-c', '--connect_uri', help='URI to send requests to', type=str, default=[])
    parser.add_argument(
        'output_file',
        help='JSON output file name',
        type=str,
        default='output.json',
        nargs='?')

    options = parser.parse_args(args)

    if config.get('Logging') is None :
        config['Logging'] = {
            'LogFile' : '__screen__',
            'LogLevel' : 'INFO'
        }
    if options.logfile :
        config['Logging']['LogFile'] = options.logfile
    if options.loglevel :
        config['Logging']['LogLevel'] = options.loglevel.upper()
    
    input_json_str = None
    input_json_dir = None
    
    if options.connect_uri:
        server_uri = options.connect_uri
    else:
        logger.error("ERROR: Please enter the server URI")
    
    if options.input_dir:
        logger.info('Load Json Directory from %s',options.input_dir)
        input_json_dir = options.input_dir
    elif options.input_file:
        try:
            logger.info('load JSON input from %s', options.input_file)

            with open(options.input_file, "r") as file:
                input_json_str = file.read()
        except:
            logger.error("ERROR: Failed to read from file %s", options.input_file)
    else :
        logger.info('No input found')

    if options.output_file:
        output_json_file_name = options.output_file
    else:
        output_json_file_name = None

    if options.private_key:
        private_key = options.private_key
    else:#Generating the private Key for the client
        private_key = helper.generate_signing_keys()

    # Initializing Signature object, Worker Object
    sig_obj = signature.ClientSignature()
    worker_obj = worker.WorkerDetails()