app_util.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:raw-data-repository 作者: all-of-us 项目源码 文件源码
def auth_required(role_whitelist):
  """A decorator that keeps the function from being called without auth.
  role_whitelist can be a string or list of strings specifying one or
  more roles that are allowed to call the function. """

  assert role_whitelist, "Can't call `auth_required` with empty role_whitelist."

  if type(role_whitelist) != list:
    role_whitelist = [role_whitelist]

  def auth_required_wrapper(func):
    def wrapped(*args, **kwargs):
      appid = app_identity.get_application_id()
      # Only enforce HTTPS and auth for external requests; requests made for data generation
      # are allowed through (when enabled).
      if not _is_self_request():
        if request.scheme.lower() != 'https' and appid not in ('None', 'testbed-test', 'testapp'):
          raise Unauthorized('HTTPS is required for %r' % appid)
        check_auth(role_whitelist)
      return func(*args, **kwargs)
    return wrapped
  return auth_required_wrapper
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号