zoukankan      html  css  js  c++  java
  • 自定义敏感配置项目

    django.utils.log.AdminEmailHandler

    django.views.debug.ExceptionReporter.get_traceback_text

    HIDDEN_SETTINGS = re.compile('API|TOKEN|KEY|SECRET|PASS|SIGNATURE', flags=re.IGNORECASE)
    import functools
    import re
    import sys
    import types
    from pathlib import Path

    from django.conf import settings
    from django.http import HttpResponse, HttpResponseNotFound
    from django.template import Context, Engine, TemplateDoesNotExist
    from django.template.defaultfilters import pprint
    from django.urls import Resolver404, resolve
    from django.utils import timezone
    from django.utils.datastructures import MultiValueDict
    from django.utils.encoding import force_text
    from django.utils.module_loading import import_string
    from django.utils.version import get_docs_version

    # Minimal Django templates engine to render the error templates
    # regardless of the project's TEMPLATES setting. Templates are
    # read directly from the filesystem so that the error handler
    # works even if the template loader is broken.
    DEBUG_ENGINE = Engine(
    debug=True,
    libraries={'i18n': 'django.templatetags.i18n'},
    )

    HIDDEN_SETTINGS = re.compile('API|TOKEN|KEY|SECRET|PASS|SIGNATURE', flags=re.IGNORECASE)

    CLEANSED_SUBSTITUTE = '********************'

    CURRENT_DIR = Path(__file__).parent


    class CallableSettingWrapper:
    """
    Object to wrap callable appearing in settings.
    * Not to call in the debug page (#21345).
    * Not to break the debug page if the callable forbidding to set attributes
    (#23070).
    """
    def __init__(self, callable_setting):
    self._wrapped = callable_setting

    def __repr__(self):
    return repr(self._wrapped)


    def cleanse_setting(key, value):
    """
    Cleanse an individual setting key/value of sensitive content. If the value
    is a dictionary, recursively cleanse the keys in that dictionary.
    """
    try:
    if HIDDEN_SETTINGS.search(key):
    cleansed = CLEANSED_SUBSTITUTE
    else:
    if isinstance(value, dict):
    cleansed = {k: cleanse_setting(k, v) for k, v in value.items()}
    else:
    cleansed = value
    except TypeError:
    # If the key isn't regex-able, just return as-is.
    cleansed = value

    if callable(cleansed):
    # For fixing #21345 and #23070
    cleansed = CallableSettingWrapper(cleansed)

    return cleansed


    def get_safe_settings():
    """
    Return a dictionary of the settings module with values of sensitive
    settings replaced with stars (*********).
    """
    settings_dict = {}
    for k in dir(settings):
    if k.isupper():
    settings_dict[k] = cleanse_setting(k, getattr(settings, k))
    return settings_dict

  • 相关阅读:
    编程随想——从基础开始,顺其自然
    多个SSH私钥配置不当导致Git push 失败的分析及解决方法
    VPS配置记录
    COCI 2010.03.06 T5「PROGRAM」题解
    筛素数
    你的第一个程序--基本输入输出介绍,头文件介绍
    入门指北目录
    尺取法
    HAOI2006 (洛谷P2341)受欢迎的牛 题解
    c++并查集配合STL MAP的实现(洛谷P2814题解)
  • 原文地址:https://www.cnblogs.com/rsapaper/p/12976479.html
Copyright © 2011-2022 走看看