Exemplo n.º 1
0
 def exception_wrapper(*args, **kwargs):
     try:
         restlogger = restfullogger.get_logger()
         restlogger.debug("calling {}".format(func.__name__))
         ret = func(*args, **kwargs)
         return ret
     except Exception as error:
         restlogger.info("Exception from function {} (error: {})".format(
             func.__name__, str(error)))
         if isinstance(error, ConfigError):
             raise error
         else:
             raise ConfigError(str(error))
Exemplo n.º 2
0
 def __init__(self):
     super(AMAuth, self).__init__()
     config = RestConfig()
     config.parse()
     conf = config.get_section("AM", format='dict')
     self.logger = logger.get_logger()
     try:
         self.host = conf['host']
         self.port = conf['port']
     except KeyError as error:
         self.logger.error(
             "Failed to find all the needed parameters. Authentication with AM not possible: {}"
             .format(str(error)))
     self.sender = AuthSender(self.host, self.port)
Exemplo n.º 3
0
 def __init__(self):
     super(AMApiBase, self).__init__()
     self.logger = logger.get_logger()
     configparser = AMConfigParser()
     self.config = configparser.parse()
     self.db = amdb.AMDatabase(db_name=self.config["DB"]["name"],
                               db_addr=self.config["DB"]["addr"],
                               db_port=int(self.config["DB"]["port"]),
                               db_user=self.config["DB"]["user"],
                               db_pwd=self.config["DB"]["pwd"],
                               logger=self.logger)
     if self.get_token() != "":
         self.keystone = self.auth_keystone()
     self.token = self.get_token()
Exemplo n.º 4
0
 def __init__(self):
     super(KeystoneAuth, self).__init__()
     self.logger = logger.get_logger()
     config = RestConfig()
     config.parse()
     conf = config.get_section("keystone", format='dict')
     try:
         self.user = conf["user"]
         self.password = conf["password"]
         self.uri = conf["auth_uri"] + '/v3'
         self.domain = "default"
     except KeyError as error:
         self.logger.error(
             "Failed to find all the needed parameters. Authentication with Keystone not possible: {}"
             .format(str(error)))
     self.auth = v3.Password(auth_url=self.uri,
                             username=self.user,
                             password=self.password,
                             user_domain_id=self.domain)
     self.sess = session.Session(auth=self.auth)
     self.keystone = client.Client(session=self.sess)
     self.tokenmanager = TokenManager(self.keystone)
Exemplo n.º 5
0
def main():
    logger = restlog.get_logger()
    config = get_config(sys.argv[1:], logger)
    if not config:
        raise ConfigError("Failed to read config file")
    initialize(config, logger)
    run_params = {}
    run_params["debug"] = config.get_debug()
    run_params["port"] = config.get_port()
    run_params["host"] = config.get_ip()
    # When this https://github.com/pallets/werkzeug/issues/954 is fixed then the error handling
    # can be done in the error handler of app level
    passthrough_errors = config.get_passthrough_errors()
    run_params["passthrough_errors"] = passthrough_errors
    run_params["threaded"] = config.is_threaded()
    logger.debug("%s %s %s", run_params["debug"], run_params["port"], run_params["threaded"])
    if config.use_ssl():
        context = SSL.Context(SSL.SSLv23_METHOD)
        context.use_privatekey_file(config.get_private_key())
        context.use_certificate_file(config.get_certificate())
        run_params['ssl_context'] = context
    while True:
        try:
            app.run(**run_params)
        except Exception as err: # pylint: disable=broad-except
            logger.warning("Caught exception but starting again %s", err)
            if passthrough_errors:
                handle_excp(err)
            else:
                raise err
            logger.warning("Die in piece %s", err)
            func = request.environ.get('werkzeug.server.shutdown')
            if func is None:
               raise RuntimeError('Not running with the Werkzeug Server')
            func()

    return 0
Exemplo n.º 6
0
 def __init__(self, path, api, auth_method):
     self.logger = restlog.get_logger()
     self.plugin_class_type = RestResource
     self.auth_method = self._get_auth_method(auth_method)
     self.path = path
     self.api = api
Exemplo n.º 7
0
def get_wsgi_application():
    logger = restlog.get_logger()
    config = get_config(None, logger)
    initialize(config, logger)
    return app