예제 #1
0
def configure(args):
    """For load configuration file/object"""

    if args.get('config'):
        config = Configuration(args.get('config'))
        config.mix(dict(args))
    else:
        config = dict(args)

    if 'freq' in config.keys():
        parts = config['freq'].split('-')
        config['freq'] = (float(parts[0]), float(parts[1]))

    config['template'] = config['template'].read()

    # Initialize LtSender with the config credentials but only
    # if we aren't in batch mode or simulation mode
    engine = None
    if not (config['batch_mode'] or config['simulation']):
        try:
            if "sender" not in config.keys():
                config['sender'] = {
                    'key': config.get('key', None),
                    'chain': config.get('chain', None),
                    'cert': config.get('cert', None),
                    'address': config.get('address', None),
                    'port': config.get('port', 443)
                }

            engine = Sender(config=config.get('sender'))
        except Exception as error:
            print_error(error, show_help=False)
            print_error("Error when loading devo sender configuration",
                        show_help=True)
    return engine, config
예제 #2
0
def init_conf(args):
    """ Generic configuration of CLI, from config file and cli arguments """
    config = Configuration()
    if args.get('config'):
        config.load_json(args.get('config'), 'sender')
    config.mix(dict(args))

    if "address" not in args.keys() and "url" in args.keys():
        config.set('address', args['url'])

    if "address" not in args.keys():
        address = os.environ.get('DEVO_SENDER_ADDRESS', None)
        if not address:
            address = os.environ.get('DEVO_SENDER_URL', None)

        config.set("address", address)
        config.set("port", os.environ.get('DEVO_SENDER_PORT', None))

    if config.get()['cert_reqs']:
        if "config" not in args.keys() and "key" not in args.keys() \
                and "cert" not in args.keys() and "chain" not in args.keys():
            config.set("key", os.environ.get('DEVO_SENDER_KEY', None))
            config.set("cert", os.environ.get('DEVO_SENDER_CERT', None))
            config.set("chain", os.environ.get('DEVO_SENDER_CHAIN', None))

        if not config.keys("key") and not config.keys("cert") and not \
                config.keys("chain") and os.path.exists("~/.devo.json"):
            config.load_default_json('api')

    config.keys('from')
    config.keys('to')

    return config
예제 #3
0
def configure(args):
    """
    Load CLI configuration
    :param args: args from files, launch vars, etc
    :return: Client API Object and Config values in array
    """
    config = Configuration()
    if args.get('config') != "~/.devo.json":
        config.load_json(args.get('config'), 'api')

    config.mix(dict(args))

    if "key" not in args.keys() and "api" not in args.keys() \
            and "token" not in args.keys():
        config.set("key", os.environ.get('DEVO_API_KEY', None))
        config.set("secret", os.environ.get('DEVO_API_SECRET', None))
        if "url" not in args.keys():
            config.set("url", os.environ.get('DEVO_API_URL', None))

    if not config.keys("key") and not config.keys("api") \
            and not config.keys("token") \
            and os.path.exists("~/.devo.json"):
        config.load_default_json('api')

    config.keys('from')
    config.keys('to')

    # Try to compose the api
    api = None
    try:
        api = Client.from_config(config.get())
    except DevoClientException as error:
        print_error(str(error), show_help=True)
    return api, config.get()
예제 #4
0
def configure(args):
    """For load configuration file/object"""

    if args.get('config'):
        config = Configuration(path=args.get('config'), section="faker")
        config.mix(dict(args))
    else:
        config = dict(args)

    if 'frequency' in config.keys() and isinstance(config.get("frequency"),
                                                   (str, bytes)):
        config['frequency'] = tuple(
            [float(x) for x in config.get("frequency").split("-")])

    config['template'] = config['template'].read()

    # Initialize devo.sender with the config credentials but only
    # if we aren't in batch mode or simulation mode
    engine = None
    if not (config['batch_mode'] or config['simulation']
            or config.get('file_name', None)):
        try:
            if "sender" not in config.keys():
                config['sender'] = {
                    'key': config.get('key', None),
                    'chain': config.get('chain', None),
                    'cert': config.get('cert', None),
                    'address': config.get('address', None),
                    'port': config.get('port', 443)
                }

            engine = Sender(config=config.get('sender'))
        except Exception as error:
            print_error(error, show_help=False)
            print_error("Error when loading devo sender configuration",
                        show_help=True)
    return engine, config