Exemple #1
0
 def is_valid_method(self, func):
     """
     验证方法是否可用
     :param func: 需要导入的函数
     :return: True/False
     """
     self.func = func
     current_app.logger.debug('正在验证模块 {} 下 {} 方法是否存在'.format(self.module_name, self.func))
     if self.module is None:
         current_app.warning('函数验证失败,模块{}为空'.format(self.module_name))
         return False
     return hasattr(self.module, self.func)
Exemple #2
0
def get_err_source_info(original_traceback=None) -> dict:
    """Use this when an error is handled to get info on where it occurred."""
    try:  # carefully try to get the actual place where the error happened
        if not original_traceback:
            original_traceback = sys.exc_info()[2]  # class, exc, traceback
        first_call = traceback.extract_tb(original_traceback)[-1]
        return dict(
            src_module=first_call[0],
            src_linenr=first_call[1],
            src_func=first_call[2],
            src_code=first_call[3],
        )
    except Exception as e:
        current_app.warning(
            "I was unable to retrieve error source information: %s." % str(e))
        return dict(module="", linenr=0, method="", src_code="")
Exemple #3
0
 def with_auth_ip(*args, **kwargs):
     if request:
         if request.remote_addr not in current_app.config['AUTH_IP']:
             current_app.logger.warning(
                 "IP address {0} not allowed to access admin API.",
                 request.remote_addr)
             # 403 ("Forbidden") is the correct status code here
             # according to the HTTP spec ("Authorization will not
             # help and the request SHOULD NOT be repeated.")
             # Also, do not bother to return a properly formatted
             # JSON message for REST API consumption -- if somebody
             # is attempting unauthorized access, the last thing we
             # want to do is give 'em hints at how to properly do
             # their requests...
             abort(403)
     else:
         current_app.warning(
             "No request context, cannot check IP authorization!")
     return fn(*args, **kwargs)
Exemple #4
0
def parse_packages_file(url, repo):
    r = get_redis()
    req = requests.get(url)

    if req.status_code != 200:
        current_app.logger.warning(f"No Packages found at {url}")
        return {}

    packages = {}
    mapping = {}
    linebuffer = ""
    for line in req.text.splitlines():
        if line == "":
            parser = email.parser.Parser()
            package = parser.parsestr(linebuffer)
            source_name = package.get("SourceName")
            if source_name:
                packages[source_name] = dict(
                    (name.lower().replace("-", "_"), val)
                    for name, val in package.items()
                )
                packages[source_name]["repository"] = repo
                package_name = package.get("Package")
                if source_name != package_name:
                    mapping[package_name] = source_name
            else:
                current_app.warning(f"Something wired about {package}")
            linebuffer = ""
        else:
            linebuffer += line + "\n"

    for package, source in mapping.items():
        if not r.hexists("mapping-abi", package):
            current_app.logger.info(f"Add ABI mapping {package} -> {source}")
            r.hset("mapping-abi", package, source)

    current_app.logger.debug(f"Found {len(packages)} in {repo}")

    return packages