def Main() :
    import pdo.common.config as pconfig
    import pdo.common.logger as plogger

    # parse out the configuration file first
    conffiles = [ 'eservice_tests.toml' ]
    confpaths = [ ".", "./etc", ContractEtc ]

    parser = argparse.ArgumentParser()
    parser.add_argument('--config', help='configuration file', nargs = '+')
    parser.add_argument('--config-dir', help='configuration file', nargs = '+')
    (options, remainder) = parser.parse_known_args()

    if options.config :
        conffiles = options.config

    if options.config_dir :
        confpaths = options.config_dir

    global config_map
    config_map['identity'] = 'test-request'

    try :
        config = pconfig.parse_configuration_files(conffiles, confpaths, config_map)
    except pconfig.ConfigurationException as e :
        logger.error(str(e))
        sys.exit(-1)

    ParseCommandLine(config, remainder)

    plogger.setup_loggers(config.get('Logging', {}))
    sys.stdout = plogger.stream_to_logger(logging.getLogger('STDOUT'), logging.DEBUG)
    sys.stderr = plogger.stream_to_logger(logging.getLogger('STDERR'), logging.WARN)

    LocalMain(config)
Exemplo n.º 2
0
def Main():
    # parse out the configuration file first
    conffiles = ['toxaway.toml']
    confpaths = [".", "./etc", ContractEtc]

    parser = argparse.ArgumentParser()

    parser.add_argument('--config', help='configuration file', nargs='+')
    parser.add_argument('--config-dir',
                        help='directory to search for configuration files',
                        nargs='+')

    parser.add_argument('--identity',
                        help='Identity to use for the process',
                        required=True,
                        type=str)

    parser.add_argument(
        '--logfile',
        help='Name of the log file, __screen__ for standard output',
        type=str)
    parser.add_argument('--loglevel', help='Logging level', type=str)

    options = parser.parse_args()

    # first process the options necessary to load the default configuration
    if options.config:
        conffiles = options.config

    if options.config_dir:
        confpaths = options.config_dir

    global config_map
    config_map['identity'] = options.identity

    try:
        config = pconfig.parse_configuration_files(conffiles, confpaths,
                                                   config_map)
    except pconfig.ConfigurationException as e:
        logger.error(str(e))
        sys.exit(-1)

    # set up the logging configuration
    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()

    plogger.setup_loggers(config.get('Logging', {}))
    sys.stdout = plogger.stream_to_logger(logging.getLogger('STDOUT'),
                                          logging.DEBUG)
    sys.stderr = plogger.stream_to_logger(logging.getLogger('STDERR'),
                                          logging.WARN)

    # GO!
    LocalMain(config)
def Main():
    save_path = os.path.realpath(
        os.path.join(ContractData, "EServiceEnclaveInfo.tmp"))
    spid = os.environ.get(
        "PDO_SPID"
    ) if "PDO_SPID" in os.environ else "00000000000000000000000000000000"

    parser = argparse.ArgumentParser()

    parser.add_argument('--spid',
                        help='SPID to generate enclave basename',
                        type=str)
    parser.add_argument('--save',
                        help='Where to save MR_ENCLAVE and BASENAME',
                        type=str)
    parser.add_argument(
        '--logfile',
        help='Name of the log file, __screen__ for standard output',
        type=str)
    parser.add_argument('--loglevel', help='Logging level', type=str)

    options = parser.parse_args()

    # Location to save MR_ENCLAVE and MR_BASENAME
    if options.save:
        save_path = options.save

    if options.spid:
        spid = options.spid

    LogConfig = {}
    LogConfig['Logging'] = {'LogFile': '__screen__', 'LogLevel': 'INFO'}

    if options.logfile:
        LogConfig['Logging']['LogFile'] = options.logfile
    if options.loglevel:
        LogConfig['Logging']['LogLevel'] = options.loglevel.upper()

    plogger.setup_loggers(LogConfig.get('Logging', {}))
    sys.stdout = plogger.stream_to_logger(logging.getLogger('STDOUT'),
                                          logging.DEBUG)
    sys.stderr = plogger.stream_to_logger(logging.getLogger('STDERR'),
                                          logging.WARN)

    # GO!
    LocalMain(spid, save_path)
Exemplo n.º 4
0
def Main():
    # parse out the configuration file first
    conffiles = ['eservice.toml']
    confpaths = [".", "./etc", ContractEtc]

    parser = argparse.ArgumentParser()

    parser.add_argument('--config', help='configuration file', nargs='+')
    parser.add_argument('--config-dir', help='configuration file', nargs='+')

    parser.add_argument('--identity',
                        help='Identity to use for the process',
                        required=True,
                        type=str)

    parser.add_argument(
        '--logfile',
        help='Name of the log file, __screen__ for standard output',
        type=str)
    parser.add_argument('--loglevel', help='Logging level', type=str)

    parser.add_argument('--http',
                        help='Port on which to run the http server',
                        type=int)
    parser.add_argument('--ledger',
                        help='Default url for connection to the ledger',
                        type=str)

    parser.add_argument(
        '--enclave-data',
        help='Name of the file containing enclave sealed storage',
        type=str)
    parser.add_argument(
        '--enclave-save',
        help='Name of the directory where enclave data will be save',
        type=str)
    parser.add_argument('--enclave-path',
                        help='Directories to search for the enclave data file',
                        type=str,
                        nargs='+')

    options = parser.parse_args()

    # first process the options necessary to load the default configuration
    if options.config:
        conffiles = options.config

    if options.config_dir:
        confpaths = options.config_dir

    global config_map
    config_map['identity'] = options.identity

    try:
        config = pconfig.parse_configuration_files(conffiles, confpaths,
                                                   config_map)
    except pconfig.ConfigurationException as e:
        logger.error(str(e))
        sys.exit(-1)

    # set up the logging configuration
    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()

    plogger.setup_loggers(config.get('Logging', {}))
    sys.stdout = plogger.stream_to_logger(logging.getLogger('STDOUT'),
                                          logging.DEBUG)
    sys.stderr = plogger.stream_to_logger(logging.getLogger('STDERR'),
                                          logging.WARN)

    # set up the ledger configuration
    if config.get('Sawtooth') is None:
        config['Sawtooth'] = {
            'LedgerURL': 'http://localhost:8008',
        }
    if options.ledger:
        config['Sawtooth']['LedgerURL'] = options.ledger

    # set up the enclave service configuration
    if config.get('EnclaveService') is None:
        config['EnclaveService'] = {
            'HttpPort': 7101,
            'Host': 'localhost',
            'Identity': 'enclave'
        }
    if options.http:
        config['EnclaveService']['HttpPort'] = options.http

    if config.get('EnclaveData') is None:
        config['EnclaveData'] = {
            'FileName': 'enclave.data',
            'SavePath': './data',
            'SearchPath': ['.', './data']
        }
    if options.enclave_data:
        config['EnclaveData']['FileName'] = options.enclave_data
    if options.enclave_save:
        config['EnclaveData']['SavePath'] = options.enclave_save
    if options.enclave_path:
        config['EnclaveData']['SearchPath'] = options.enclave_path

    # GO!
    LocalMain(config)
Exemplo n.º 5
0
def Main():
    import pdo.common.config as pconfig
    import pdo.common.logger as plogger

    # parse out the configuration file first
    conffiles = ['pcontract.toml']
    confpaths = [".", "./etc", ContractEtc]

    parser = argparse.ArgumentParser()

    parser.add_argument('--config', help='configuration file', nargs='+')
    parser.add_argument('--config-dir', help='configuration file', nargs='+')

    parser.add_argument('--identity',
                        help='Identity to use for the process',
                        type=str,
                        required=True)

    parser.add_argument(
        '--logfile',
        help='Name of the log file, __screen__ for standard output',
        type=str)
    parser.add_argument('--loglevel', help='Logging level', type=str)

    parser.add_argument('--ledger',
                        help='URL for the Sawtooth ledger',
                        type=str)
    parser.add_argument('--data-dir',
                        help='Path for storing generated files',
                        type=str)
    parser.add_argument('--save-file',
                        help='Name of the file where contract data is stored',
                        type=str,
                        required=True)

    parser.add_argument('--key-dir',
                        help='Directories to search for key files',
                        nargs='+')

    parser.add_argument('--enclave',
                        help='URL of the enclave service to use',
                        type=str)

    parser.add_argument('message', help="Message to evaluate", type=str)

    options = parser.parse_args()

    # first process the options necessary to load the default configuration
    if options.config:
        conffiles = options.config

    if options.config_dir:
        confpaths = options.config_dir

    global config_map
    config_map['identity'] = options.identity
    config_map['contract'] = '__unknown__'
    if options.data_dir:
        config_map['data'] = options.data_dir

    try:
        config = pconfig.parse_configuration_files(conffiles, confpaths,
                                                   config_map)
    except pconfig.ConfigurationException as e:
        logger.error(str(e))
        sys.exit(-1)

    # set up the logging configuration
    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()

    plogger.setup_loggers(config.get('Logging', {}))

    # set up the ledger configuration
    if config.get('Sawtooth') is None:
        config['Sawtooth'] = {
            'LedgerURL': 'http://localhost:8008',
        }
    if options.ledger:
        config['Sawtooth']['LedgerURL'] = options.ledger

    # make sure we have an enclave
    if config.get('Service') is None:
        config['Service'] = {'PreferredEnclaveService': 'http://locahost:7001'}
    if options.enclave:
        config['Service']['PreferredEnclaveService'] = options.enclave

    # set up the key search paths
    if config.get('Key') is None:
        config['Key'] = {
            'SearchPath': ['.', './keys', ContractKeys],
            'FileName': options.identity + ".pem"
        }
    if options.key_dir:
        config['Key']['SearchPath'] = options.key_dir

    # set up the data paths
    if config.get('Contract') is None:
        config['Contract'] = {
            'DataDirectory': ContractData,
            'SaveFile': options.save_file
        }
    config['Contract']['SaveFile'] = options.save_file

    # GO!
    LocalMain(config, options.message)
Exemplo n.º 6
0
def Main(commands):
    # parse out the configuration file first
    conffiles = ['pcontract.toml']
    confpaths = [".", "./etc", ContractEtc]

    parser = argparse.ArgumentParser()
    parser.add_argument('--config', help='configuration file', nargs='+')
    parser.add_argument('--config-dir', help='configuration file', nargs='+')

    parser.add_argument('--identity',
                        help='Identity to use for the process',
                        required=True,
                        type=str)

    parser.add_argument(
        '--logfile',
        help='Name of the log file, __screen__ for standard output',
        type=str)
    parser.add_argument('--loglevel', help='Logging level', type=str)

    parser.add_argument('--ledger',
                        help='URL for the Sawtooth ledger',
                        type=str)
    parser.add_argument('--data-dir',
                        help='Path for storing generated files',
                        type=str)
    parser.add_argument('--contract',
                        help='Name of the contract',
                        required=True,
                        type=str)
    parser.add_argument('--source',
                        help='Gipsy Scheme source for the contract',
                        required=True,
                        type=str)
    parser.add_argument('--save-file',
                        help='Name of the file where contract data is stored',
                        type=str)

    parser.add_argument('--key-dir',
                        help='Directories to search for key files',
                        nargs='+')

    parser.add_argument('--eservice-url',
                        help='List of enclave service URLs to use',
                        nargs='+')
    parser.add_argument('--pservice-url',
                        help='List of provisioning service URLs to use',
                        nargs='+')

    options = parser.parse_args()

    # first process the options necessary to load the default configuration
    if options.config:
        conffiles = options.config

    if options.config_dir:
        confpaths = options.config_dir

    global config_map
    config_map['identity'] = options.identity
    config_map['contract'] = options.contract
    if options.data_dir:
        config_map['data'] = options.data_dir

    try:
        config = pconfig.parse_configuration_files(conffiles, confpaths,
                                                   config_map)
    except pconfig.ConfigurationException as e:
        logger.error(str(e))
        sys.exit(-1)

    # set up the logging configuration
    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()

    plogger.setup_loggers(config.get('Logging', {}))

    # process the reset of the command parameters

    # set up the ledger configuration
    if config.get('Sawtooth') is None:
        config['Sawtooth'] = {
            'LedgerURL': 'http://localhost:8008',
        }
    if options.ledger:
        config['Sawtooth']['LedgerURL'] = options.ledger

    # set up the service configuration
    if config.get('Service') is None:
        config['Service'] = {
            'EnclaveServiceURLs': [],
            'ProvisioningServiceURLs': []
        }
    if options.eservice_url:
        config['Service']['EnclaveServiceURLs'] = options.eservice_url
    if options.pservice_url:
        config['Service']['ProvisioningServiceURLs'] = options.pservice_url

    # set up the key search paths
    if config.get('Key') is None:
        config['Key'] = {
            'SearchPath': ['.', './keys', ContractKeys],
            'FileName': options.identity + ".pem"
        }
    if options.key_dir:
        config['Key']['SearchPath'] = options.key_dir

    # set up the data paths
    if config.get('Contract') is None:
        config['Contract'] = {
            'Name':
            options.contract,
            'DataDirectory':
            ContractData,
            'SaveFile':
            options.contract + '.pdo',
            'SourceName':
            options.contract,
            'SourceSearchPath':
            [".", "./contract",
             os.path.join(ContractHome, 'contracts')]
        }
    config['Contract']['SourceName'] = options.source
    if options.save_file:
        config['Contract']['SaveFile'] = options.save_file

    # GO!!!
    LocalMain(commands, config)
Exemplo n.º 7
0
    ErrorShutdown()

contract_creator_keys = keys.ServiceKeys.create_service_keys()
contract_creator_id = contract_creator_keys.identity
contract_id = crypto.byte_array_to_hex(crypto.random_bit_string(256))[:32]

try :
    block_store_file = config['StorageService']['BlockStore']
    block_store = BlockStoreManager(block_store_file, create_block_store=True)
except Exception as e :
    logger.error('failed to initialize the block store; %s', str(e))
    ErrorShutdown()

# -----------------------------------------------------------------
# -----------------------------------------------------------------
plogger.setup_loggers({'LogLevel' : options.loglevel.upper(), 'LogFile' : options.logfile})

# -----------------------------------------------------------------
# -----------------------------------------------------------------
enclave_helper.initialize_enclave(config)
enclave_client = enclave_helper.Enclave.create_new_enclave()
enclave_client.attach_block_store(block_store)

# -----------------------------------------------------------------
logger.info('test correct inputs')
# -----------------------------------------------------------------
def test_secrets(secret_count) :
    global enclave_client
    global contract_id
    global contract_creator_id
Exemplo n.º 8
0
def Main():
    global use_ledger
    global use_eservice
    global use_pservice

    import pdo.common.config as pconfig
    import pdo.common.logger as plogger

    # parse out the configuration file first
    conffiles = ['pcontract.toml', 'enclave.toml']
    confpaths = [".", "./etc", ContractEtc]

    parser = argparse.ArgumentParser()

    parser.add_argument('--config', help='configuration file', nargs='+')
    parser.add_argument(
        '--config-dir',
        help='directories to search for the configuration file',
        nargs='+')

    parser.add_argument('-i',
                        '--identity',
                        help='Identity to use for the process',
                        type=str)

    parser.add_argument(
        '--logfile',
        help='Name of the log file, __screen__ for standard output',
        type=str)
    parser.add_argument('--loglevel', help='Logging level', type=str)

    parser.add_argument('--ledger',
                        help='URL for the Sawtooth ledger',
                        type=str)
    parser.add_argument('--no-ledger',
                        help='Do not attempt ledger registration',
                        action="store_true")

    parser.add_argument('--data-dir',
                        help='Directory for storing generated files',
                        type=str)
    parser.add_argument('--source-dir',
                        help='Directories to search for contract source',
                        nargs='+',
                        type=str)
    parser.add_argument('--key-dir',
                        help='Directories to search for key files',
                        nargs='+')

    parser.add_argument('--eservice-url',
                        help='List of enclave service URLs to use',
                        nargs='+')
    parser.add_argument('--pservice-url',
                        help='List of provisioning service URLs to use',
                        nargs='+')

    parser.add_argument('--secret-count',
                        help='Number of secrets to generate',
                        type=int,
                        default=3)
    parser.add_argument('--iterations',
                        help='Number of operations to perform',
                        type=int,
                        default=10)

    options = parser.parse_args()

    # first process the options necessary to load the default configuration
    if options.config:
        conffiles = options.config

    if options.config_dir:
        confpaths = options.config_dir

    # customize the configuration file for the current request
    global config_map

    config_map['identity'] = 'test-request'
    if options.identity:
        config_map['identity'] = options.identity

    if options.data_dir:
        config_map['data'] = options.data_dir

    config_map['contract'] = 'mock-contract'

    # parse the configuration file
    try:
        config = pconfig.parse_configuration_files(conffiles, confpaths,
                                                   config_map)
    except pconfig.ConfigurationException as e:
        logger.error(str(e))
        sys.exit(-1)

    # set up the logging configuration
    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()

    plogger.setup_loggers(config.get('Logging', {}))
    sys.stdout = plogger.stream_to_logger(logging.getLogger('STDOUT'),
                                          logging.DEBUG)
    sys.stderr = plogger.stream_to_logger(logging.getLogger('STDERR'),
                                          logging.WARN)

    # set up the ledger configuration
    if config.get('Sawtooth') is None:
        config['Sawtooth'] = {
            'LedgerURL': 'http://localhost:8008',
        }
    if options.ledger:
        config['Sawtooth']['LedgerURL'] = options.ledger

    # set up the key search paths
    if config.get('Key') is None:
        config['Key'] = {
            'SearchPath': ['.', './keys', ContractKeys],
            'FileName': options.identity + ".pem"
        }
    if options.key_dir:
        config['Key']['SearchPath'] = options.key_dir

    # set up the service configuration
    if config.get('Service') is None:
        config['Service'] = {
            'EnclaveServiceURLs': [],
            'ProvisioningServiceURLs': []
        }
    if options.eservice_url:
        use_eservice = True
        config['Service']['EnclaveServiceURLs'] = options.eservice_url
    if options.pservice_url:
        use_pservice = True
        config['Service']['ProvisioningServiceURLs'] = options.pservice_url

    # set up the data paths
    if config.get('Contract') is None:
        config['Contract'] = {
            'DataDirectory':
            ContractData,
            'SourceSearchPath':
            [".", "./contract",
             os.path.join(ContractHome, 'contracts')]
        }

    if options.data_dir:
        config['Contract']['DataDirectory'] = options.data_dir
    if options.source_dir:
        config['Contract']['SourceSearchPath'] = options.source_dir

    putils.set_default_data_directory(config['Contract']['DataDirectory'])

    if options.no_ledger or not config['Sawtooth']['LedgerURL']:
        use_ledger = False
        config.pop('Sawtooth', None)

    config['secrets'] = options.secret_count
    config['iterations'] = options.iterations

    LocalMain(config)
Exemplo n.º 9
0
def Main() :
    import pdo.common.config as pconfig
    import pdo.common.logger as plogger

    # parse out the configuration file first
    conffiles = [ 'pcontract.toml' ]
    confpaths = [ ".", "./etc", ContractEtc ]

    parser = argparse.ArgumentParser()

    parser.add_argument('--config', help='configuration file', nargs = '+')
    parser.add_argument('--config-dir', help='directories to search for the configuration file', nargs = '+')

    parser.add_argument('-i', '--identity', help='Identity to use for the process', type=str)
    parser.add_argument('-c', '--contract', help='Name of the contract', type = str)

    parser.add_argument('--logfile', help='Name of the log file, __screen__ for standard output', type=str)
    parser.add_argument('--loglevel', help='Logging level', type=str)

    parser.add_argument('--ledger', help='URL for the Sawtooth ledger', type=str)

    parser.add_argument('--data-dir', help='Directory for storing generated files', type=str)
    parser.add_argument('--source-dir', help='Directories to search for contract source', nargs='+', type=str)
    parser.add_argument('--key-dir', help='Directories to search for key files', nargs='+')

    parser.add_argument('--eservice-url', help='List of enclave service URLs to use', nargs='+')
    parser.add_argument('--pservice-url', help='List of provisioning service URLs to use', nargs='+')

    parser.add_argument('-m', '--mapvar', help='Define variables for script use', nargs=2, action='append')
    parser.add_argument('-s', '--script', help='File from which to read script', type=str)

    options = parser.parse_args()

    # first process the options necessary to load the default configuration
    if options.config :
        conffiles = options.config

    if options.config_dir :
        confpaths = options.config_dir

    global config_map
    config_map['identity'] = '__unknown__'
    if options.identity :
        config_map['identity'] = options.identity
    config_map['contract'] = '__unknown__'
    if options.data_dir :
        config_map['data'] = options.data_dir

    try :
        config = pconfig.parse_configuration_files(conffiles, confpaths, config_map)
    except pconfig.ConfigurationException as e :
        logger.error(str(e))
        sys.exit(-1)

    # set up the logging configuration
    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()

    plogger.setup_loggers(config.get('Logging', {}))

    # set up the ledger configuration
    if config.get('Sawtooth') is None :
        config['Sawtooth'] = {
            'LedgerURL' : 'http://localhost:8008',
        }
    if options.ledger :
        config['Sawtooth']['LedgerURL'] = options.ledger

    # set up the key search paths
    if config.get('Key') is None :
        config['Key'] = {
            'SearchPath' : ['.', './keys', ContractKeys],
            'FileName' : options.identity + ".pem"
        }
    if options.key_dir :
        config['Key']['SearchPath'] = options.key_dir

    # set up the service configuration
    if config.get('Service') is None :
        config['Service'] = {
            'EnclaveServiceURLs' : [],
            'ProvisioningServiceURLs' : []
        }
    if options.eservice_url :
        config['Service']['EnclaveServiceURLs'] = options.eservice_url
    if options.pservice_url :
        config['Service']['ProvisioningServiceURLs'] = options.pservice_url

    # set up the data paths
    if config.get('Contract') is None :
        config['Contract'] = {
            'DataDirectory' : ContractData,
            'SourceSearchPath' : [ ".", "./contract", os.path.join(ContractHome,'contracts') ]
        }

    if options.data_dir :
        config['Contract']['DataDirectory'] = options.data_dir
    if options.source_dir :
        config['Contract']['SourceSearchPath'] = options.source_dir

    if options.script :
        config["ScriptFile"] = options.script

    if options.mapvar :
        varmap = config.get("VariableMap", {})
        for (k, v) in options.mapvar : varmap[k] = v
        config["VariableMap"] = varmap

    # GO!
    LocalMain(config)
Exemplo n.º 10
0
def Main():
    import pdo.common.config as pconfig
    import pdo.common.logger as plogger

    # parse out the configuration file first
    conffiles = ['pcontract.toml']
    confpaths = [".", "./etc", ContractEtc]

    parser = argparse.ArgumentParser(allow_abbrev=False)

    parser.add_argument('--config', help='configuration file', nargs='+')
    parser.add_argument(
        '--config-dir',
        help='directories to search for the configuration file',
        nargs='+')

    parser.add_argument('-i',
                        '--identity',
                        help='Identity to use for the process',
                        type=str)

    parser.add_argument(
        '--logfile',
        help='Name of the log file, __screen__ for standard output',
        type=str)
    parser.add_argument('--loglevel', help='Logging level', type=str)

    parser.add_argument('--ledger',
                        help='URL for the Sawtooth ledger',
                        type=str)

    parser.add_argument('--data-dir',
                        help='Directory for storing generated files',
                        type=str)
    parser.add_argument('--source-dir',
                        help='Directories to search for contract source',
                        nargs='+',
                        type=str)
    parser.add_argument('--key-dir',
                        help='Directories to search for key files',
                        nargs='+')

    parser.add_argument('--eservice-db',
                        help='json file for eservice database',
                        type=str)

    parser.add_argument('-m',
                        '--mapvar',
                        help='Define variables for script use',
                        nargs=2,
                        action='append')

    options, script = parser.parse_known_args()

    # first process the options necessary to load the default configuration
    if options.config:
        conffiles = options.config

    if options.config_dir:
        confpaths = options.config_dir

    global config_map
    config_map['identity'] = '__unknown__'
    if options.identity:
        config_map['identity'] = options.identity
    if options.data_dir:
        config_map['data'] = options.data_dir
        ContractData = options.data_dir

    try:
        config = pconfig.parse_configuration_files(conffiles, confpaths,
                                                   config_map)
    except pconfig.ConfigurationException as e:
        logger.error(str(e))
        sys.exit(-1)

    # set up the logging configuration
    if config.get('Logging') is None:
        config['Logging'] = {'LogFile': '__screen__', 'LogLevel': 'WARN'}
    if options.logfile:
        config['Logging']['LogFile'] = options.logfile
    if options.loglevel:
        config['Logging']['LogLevel'] = options.loglevel.upper()

    plogger.setup_loggers(config.get('Logging', {}))

    # set up the ledger configuration
    if config.get('Sawtooth') is None:
        config['Sawtooth'] = {
            'LedgerURL': 'http://localhost:8008',
        }
    if options.ledger:
        config['Sawtooth']['LedgerURL'] = options.ledger

    # set up the key search paths
    if config.get('Key') is None:
        config['Key'] = {
            'SearchPath': ['.', './keys', ContractKeys],
            'FileName': options.identity + ".pem"
        }
    if options.key_dir:
        config['Key']['SearchPath'] = options.key_dir

# set up the service configuration
    if config.get('Service') is None:
        config['Service'] = {
            'EnclaveServiceDatabaseFile':
            os.path.join(ContractData, 'eservice_db.json')
        }

    if options.eservice_db:
        config['Service']['EnclaveServiceDatabaseFile'] = options.eservice_db

    # set up the data paths
    if config.get('Contract') is None:
        config['Contract'] = {
            'DataDirectory':
            ContractData,
            'SourceSearchPath':
            [".", "./contract",
             os.path.join(ContractHome, 'contracts')]
        }

    if options.data_dir:
        config['Contract']['DataDirectory'] = options.data_dir
    if options.source_dir:
        config['Contract']['SourceSearchPath'] = options.source_dir

    putils.set_default_data_directory(config['Contract']['DataDirectory'])

    if script:
        config["ScriptFile"] = script.pop(0)

        varmap = config.get("Bindings", {})
        while script:
            try:
                key = script.pop(0)
                val = script.pop(0)
            except ValueError:
                logger.error('unable to process script arguments')
                sys.exit(1)

            key = key.lstrip('-')
            varmap[key] = val
        config["Bindings"] = varmap

    # this sets the initial bindings available in the script
    if options.mapvar:
        varmap = config.get("Bindings", {})
        for (k, v) in options.mapvar:
            varmap[k] = v
        config["Bindings"] = varmap

    # GO!
    LocalMain(config)
Exemplo n.º 11
0
def Main():
    global use_ledger
    global use_eservice
    global use_pservice

    # parse out the configuration file first
    conffiles = ['pcontract.toml', 'enclave.toml']
    confpaths = [".", "./etc", ContractEtc]

    parser = argparse.ArgumentParser()

    parser.add_argument('--config', help='configuration file', nargs='+')
    parser.add_argument(
        '--config-dir',
        help='directories to search for the configuration file',
        nargs='+')

    parser.add_argument('-i',
                        '--identity',
                        help='Identity to use for the process',
                        default='test-request',
                        type=str)

    parser.add_argument(
        '--logfile',
        help='Name of the log file, __screen__ for standard output',
        type=str)
    parser.add_argument('--loglevel', help='Logging level', type=str)

    parser.add_argument('--ledger',
                        help='URL for the Sawtooth ledger',
                        type=str)
    parser.add_argument('--no-ledger',
                        help='Do not attempt ledger registration',
                        action="store_true")

    parser.add_argument('--data-dir',
                        help='Directory for storing generated files',
                        type=str)
    parser.add_argument('--source-dir',
                        help='Directories to search for contract source',
                        nargs='+',
                        type=str)
    parser.add_argument('--key-dir',
                        help='Directories to search for key files',
                        nargs='+')

    parser.add_argument('--eservice-url',
                        help='List of enclave service URLs to use',
                        nargs='+')
    parser.add_argument('--randomize-eservice',
                        help="Randomize eservice used for each update",
                        action="store_true")

    parser.add_argument('--pservice-url',
                        help='List of provisioning service URLs to use',
                        nargs='+')

    parser.add_argument('--block-store',
                        help='Name of the file where blocks are stored',
                        type=str)

    parser.add_argument('--secret-count',
                        help='Number of secrets to generate',
                        type=int,
                        default=3)
    parser.add_argument('--contract',
                        help='Name of the contract to use',
                        default='mock-contract')
    parser.add_argument('--interpreter',
                        help='Name of the contract to to require',
                        default=ContractInterpreter)
    parser.add_argument('--expressions',
                        help='Name of a file to read for expressions',
                        default=None)

    parser.add_argument(
        '--num-provable-replicas',
        help='Number of sservice signatures needed for proof of replication',
        type=int,
        default=1)
    parser.add_argument(
        '--availability-duration',
        help=
        'duration (in seconds) for which the replicas are stored at storage service',
        type=int,
        default=60)

    options = parser.parse_args()

    # first process the options necessary to load the default configuration
    if options.config:
        conffiles = options.config

    if options.config_dir:
        confpaths = options.config_dir

    # customize the configuration file for the current request
    global config_map

    config_map['identity'] = options.identity

    if options.data_dir:
        config_map['data'] = options.data_dir

    config_map['contract'] = options.contract

    # parse the configuration file
    try:
        config = pconfig.parse_configuration_files(conffiles, confpaths,
                                                   config_map)
    except pconfig.ConfigurationException as e:
        logger.error(str(e))
        sys.exit(-1)

    # set up the logging configuration
    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()

    plogger.setup_loggers(config.get('Logging', {}))
    sys.stdout = plogger.stream_to_logger(logging.getLogger('STDOUT'),
                                          logging.DEBUG)
    sys.stderr = plogger.stream_to_logger(logging.getLogger('STDERR'),
                                          logging.WARN)

    # set up the ledger configuration
    if config.get('Sawtooth') is None:
        config['Sawtooth'] = {
            'LedgerURL': 'http://localhost:8008',
        }
    if options.ledger:
        config['Sawtooth']['LedgerURL'] = options.ledger
    if options.no_ledger or not config['Sawtooth']['LedgerURL']:
        use_ledger = False
        config.pop('Sawtooth', None)

    # set up the key search paths
    if config.get('Key') is None:
        config['Key'] = {
            'SearchPath': ['.', './keys', ContractKeys],
            'FileName': options.identity + ".pem"
        }
    if options.key_dir:
        config['Key']['SearchPath'] = options.key_dir

    # set up the service configuration
    if config.get('Service') is None:
        config['Service'] = {
            'EnclaveServiceURLs': [],
            'ProvisioningServiceURLs': [],
            'EnclaveServiceDatabaseFile': None,
            'Randomize_Eservice': False
        }

    if options.randomize_eservice:
        config['Service']['Randomize_Eservice'] = True
    else:
        config['Service']['Randomize_Eservice'] = False
    if options.eservice_url:
        use_eservice = True
        config['Service']['EnclaveServiceURLs'] = options.eservice_url
    if options.pservice_url:
        use_pservice = True
        config['Service']['ProvisioningServiceURLs'] = options.pservice_url

    # replication parameters
    if options.num_provable_replicas:
        config['Replication'][
            'NumProvableReplicas'] = options.num_provable_replicas
    if options.availability_duration:
        config['Replication']['Duration'] = options.availability_duration

    # set up the data paths
    if config.get('Contract') is None:
        config['Contract'] = {
            'DataDirectory':
            ContractData,
            'SourceSearchPath':
            [".", "./contract",
             os.path.join(ContractHome, 'contracts')]
        }

    if config['Contract'].get('Name') is None:
        config['Contract']['Name'] = options.contract
        config['Contract']['SourceFile'] = '_{0}'.format(options.contract)

    config['Contract']['Interpreter'] = options.interpreter

    if options.data_dir:
        config['Contract']['DataDirectory'] = options.data_dir
    if options.source_dir:
        config['Contract']['SourceSearchPath'] = options.source_dir

    putils.set_default_data_directory(config['Contract']['DataDirectory'])

    # set up the storage service configuration
    if config.get('StorageService') is None:
        config['StorageService'] = {
            'BlockStore':
            os.path.join(config['Contract']['DataDirectory'],
                         options.identity + '.mdb'),
        }
    if options.block_store:
        config['StorageService']['BlockStore'] = options.block_store

    config['secrets'] = options.secret_count

    if options.expressions:
        expression_file = options.expressions
    else:
        expression_file = putils.build_simple_file_name(
            options.contract, '.exp')

    try:
        config['expressions'] = putils.find_file_in_path(
            expression_file, ['.', '..', 'tests'])
    except FileNotFoundError as fe:
        logger.error('unable to locate expression file "%s"', expression_file)
        sys.exit(-1)

    LocalMain(config)
Exemplo n.º 12
0
def Main():
    import pdo.common.config as pconfig
    import pdo.common.logger as plogger

    # parse out the configuration file first
    conffiles = ['auction-test.toml']
    confpaths = [".", "./etc", ContractEtc]

    parser = argparse.ArgumentParser()

    parser.add_argument('--config', help='configuration file', nargs='+')
    parser.add_argument('--config-dir', help='configuration file', nargs='+')

    parser.add_argument(
        '--logfile',
        help='Name of the log file, __screen__ for standard output',
        type=str)
    parser.add_argument('--loglevel', help='Logging level', type=str)

    parser.add_argument('--ledger',
                        help='URL for the Sawtooth ledger',
                        type=str)

    parser.add_argument('--asset-contract',
                        help='Name of the asset contract',
                        default="integer-key",
                        type=str)
    parser.add_argument('--asset-identity',
                        help='Identity to use for the asset contract',
                        default="ikey-contract",
                        type=str)
    parser.add_argument('--auction-contract',
                        help='Name of the auction contract',
                        default="integer-key-auction",
                        type=str)
    parser.add_argument('--auction-identity',
                        help='Identity to use for the auction contract',
                        default="auc-contract",
                        type=str)

    parser.add_argument('--key-dir',
                        help='Directories to search for key files',
                        nargs='+')
    parser.add_argument('--data-dir',
                        help='Path for storing generated files',
                        type=str)
    parser.add_argument('--source-dir',
                        help='Directories to search for contract source',
                        nargs='+',
                        type=str)

    options = parser.parse_args()

    # first process the options necessary to load the default configuration
    if options.config:
        conffiles = options.config

    if options.config_dir:
        confpaths = options.config_dir

    global config_map
    config_map['assetidentity'] = options.asset_identity
    config_map['assetcontract'] = options.asset_contract
    config_map['auctionidentity'] = options.auction_identity
    config_map['auctioncontract'] = options.auction_contract

    if options.data_dir:
        config_map['data'] = options.data_dir

    try:
        config = pconfig.parse_configuration_files(conffiles, confpaths,
                                                   config_map)
    except pconfig.ConfigurationException as e:
        logger.error(str(e))
        sys.exit(-1)

    # set up the logging configuration
    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()

    plogger.setup_loggers(config.get('Logging', {}))

    # set up the ledger configuration
    if config.get('Sawtooth') is None:
        config['Sawtooth'] = {
            'LedgerURL': 'http://localhost:8008',
        }
    if options.ledger:
        config['Sawtooth']['LedgerURL'] = options.ledger

    # set up the key search paths
    if config.get('Key') is None:
        config['Key'] = {'SearchPath': ['.', './keys', ContractKeys]}
    if options.key_dir:
        config['Key']['SearchPath'] = options.key_dir

    # set up the data paths
    if config.get('Contract') is None:
        config['Contract'] = {
            'SourceSearchPath':
            ['.', './contract',
             os.path.join(ContractHome, 'contracts')]
        }

    if options.data_dir:
        config['Contract']['DataDirectory'] = options.data_dir
    if options.source_dir:
        config['Contract']['SourceSearchPath'] = options.source_dir

    putils.set_default_data_directory(config['Contract']['DataDirectory'])

    # GO!
    LocalMain(config)
Exemplo n.º 13
0
def Main() :
    # parse out the configuration file first
    conffiles = [ 'sservice.toml' ]
    confpaths = [ ".", "./etc", ContractEtc ]

    parser = argparse.ArgumentParser()

    parser.add_argument('--config', help='configuration file', nargs = '+')
    parser.add_argument('--config-dir', help='directory to search for configuration files', nargs = '+')

    parser.add_argument('--identity', help='Identity to use for the process', required = True, type = str)

    parser.add_argument('--key-dir', help='Directories to search for key files', nargs='+')
    parser.add_argument('--data-dir', help='Path for storing generated files', type=str)

    parser.add_argument('--gc-interval', help='Number of seconds between garbage collection', type=int)
    parser.add_argument('--block-store', help='Name of the file where blocks are stored', type=str)
    parser.add_argument('--create', help='Create the blockstore if it does not exist', action='store_true')
    parser.add_argument('--logfile', help='Name of the log file, __screen__ for standard output', type=str)
    parser.add_argument('--loglevel', help='Logging level', type=str)

    parser.add_argument('--http', help='Port on which to run the http server', type=int)

    options = parser.parse_args()

    # first process the options necessary to load the default configuration
    if options.config :
        conffiles = options.config

    if options.config_dir :
        confpaths = options.config_dir

    global config_map
    config_map['identity'] = options.identity
    if options.data_dir :
        config_map['data'] = options.data_dir

    try :
        config = pconfig.parse_configuration_files(conffiles, confpaths, config_map)
    except pconfig.ConfigurationException as e :
        logger.error(str(e))
        sys.exit(-1)

    # set up the logging configuration
    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()

    plogger.setup_loggers(config.get('Logging', {}))
    sys.stdout = plogger.stream_to_logger(logging.getLogger('STDOUT'), logging.DEBUG)
    sys.stderr = plogger.stream_to_logger(logging.getLogger('STDERR'), logging.WARN)

    if options.create :
        config['create'] = True

    # set up the key search paths
    if config.get('Key') is None :
        config['Key'] = {
            'SearchPath' : ['.', './keys', ContractKeys],
            'FileName' : options.identity + ".pem"
        }
    if options.key_dir :
        config['Key']['SearchPath'] = options.key_dir

    # set up the storage service configuration
    if config.get('StorageService') is None :
        config['StorageService'] = {
            'HttpPort' : 7201,
            'Host' : 'localhost',
            'Identity' : options.identity,
            'BlockStore' : os.path.join(ContractData, options.identity + '.mdb'),
            'GarbageCollectionInterval' : 10
        }
    if options.http :
        config['StorageService']['HttpPort'] = options.http

    if options.block_store :
        config['StorageService']['BlockStore'] = options.block_store

    if options.gc_interval :
        config['StorageService']['GarbageCollectionInterval'] = options.gc_interval

    # GO!
    LocalMain(config)
Exemplo n.º 14
0
def Main():
    dispatcher = {
        'add': do_add_cmd,
        'list': do_list_cmd,
        'remove': do_remove_cmd,
        'rename': do_rename_cmd,
        'reset': do_reset_cmd,
        'verify': do_verify_cmd,
    }

    # parse out the configuration file first
    conffiles = ['pcontract.toml']
    confpaths = [".", "./etc", ContractEtc]

    parser = argparse.ArgumentParser()

    parser.add_argument('--config', help='configuration file', nargs='+')
    parser.add_argument('--config-dir', help='configuration file', nargs='+')

    parser.add_argument('--loglevel',
                        help='Set the logging level',
                        default='INFO')
    parser.add_argument('--logfile',
                        help='Name of the log file',
                        default='__screen__')

    parser.add_argument('-l', '--ledger', help='Ledger URL', type=str)
    parser.add_argument('-d',
                        '--database',
                        help='json file for database',
                        type=str)

    parser.add_argument('command', nargs=argparse.REMAINDER)

    options = parser.parse_args()

    # first process the options necessary to load the default configuration
    if options.config:
        conffiles = options.config

    if options.config_dir:
        confpaths = options.config_dir

    global config_map

    try:
        config = pconfig.parse_configuration_files(conffiles, confpaths,
                                                   config_map)
    except pconfig.ConfigurationException as e:
        logger.error(str(e))
        sys.exit(-1)

    # set up the logging configuration
    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()

    plogger.setup_loggers(config.get('Logging', {}))

    # set up the ledger configuration
    if config.get('Ledger') is None:
        config['Ledger'] = {
            'LedgerURL': 'http://localhost:8008',
        }
    if options.ledger:
        config['Ledger']['LedgerURL'] = options.ledger

    #set up the service configuration
    if config.get('Service') is None:
        config['Service'] = {
            'EnclaveServiceDatabaseFile':
            os.path.join(ContractData, "eservice-db.json")
        }

    if options.database:
        config['Service']['EnclaveServiceDatabaseFile'] = options.database

    if options.command:
        command = options.command.pop(0)
        command_function = dispatcher.get(command)
        if command_function is None:
            logger.error('unknown command %s', command)
            sys.exit(-1)

        command_function(config, options.command)
        sys.exit(0)

    logger.error('missing command')
    sys.exit(-1)