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() try: if args.get('config'): config.load_config(args.get('config'), 'api') if args.get('env'): config.set("key", os.environ.get('DEVO_API_KEY', None)) config.set("secret", os.environ.get('DEVO_API_SECRET', None)) config.set("url", os.environ.get('DEVO_API_URL', None)) config.set("user", os.environ.get('DEVO_API_USER', None)) config.set("comment", os.environ.get('DEVO_API_COMMENT', None)) if args.get('default'): config.load_default_config(section="api") finally: config.mix(dict(args)) conf = config.get() # Try to compose the api api = None try: api = Client.from_config(conf) except DevoClientException as error: print_error(str(error), show_help=True) return api, conf
def test_load_config(self): config = Configuration() with self.assertRaises(Exception) as context: config.load_config(self.config_path + ".ini") self.assertTrue("Configuration file type unknown or not supported: " "%s%stestfile_config.ini" % \ (os.path.dirname(os.path.abspath(__file__)), os.sep) in str(context.exception))
def init_conf(args): """ Generic configuration of CLI, from config file and cli arguments """ config = Configuration() try: if args.get('config'): config.load_config(args.get('config'), 'sender') if args.get('env'): config.set("address", os.environ.get('DEVO_SENDER_ADDRESS', os.environ.get('DEVO_SENDER_URL', None))) config.set("port", os.environ.get('DEVO_SENDER_PORT', None)) 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 args.get('default'): config.load_default_config(section="sender") finally: config.mix(dict(args)) return config
def configure(args): """ Load CLI configuration :param args: args from files, launch vars, etc :return: Clien t API Object and Config values in array """ config = Configuration() try: if args.get('config'): config.load_config(args.get('config'), 'api') if args.get('env'): config.set("key", os.environ.get('DEVO_API_KEY', None)) config.set("secret", os.environ.get('DEVO_API_SECRET', None)) config.set("token", os.environ.get('DEVO_API_TOKEN', None)) config.set("jwt", os.environ.get('DEVO_API_JWT', None)) config.set("address", os.environ.get('DEVO_API_ADDRESS', None)) config.set("user", os.environ.get('DEVO_API_USER', None)) config.set("comment", os.environ.get('DEVO_API_COMMENT', None)) config.set("retries", os.environ.get('DEVO_API_RETRIES', None)) config.set("timeout", os.environ.get('DEVO_API_TIMEOUT', None)) if args.get('default'): config.load_default_config(section="api") except Exception as error: print_error(str(error), show_help=True) finally: config.mix(dict(args)) # Try to compose the api try: api = Client(config=config) except DevoClientException as error: print_error(str(error), show_help=True) if isinstance(error, DevoClientException): raise DevoClientException(error.args[0]) else: raise DevoClientException(str(error.args[0])) return api, config