当前位置: 首页>>代码示例>>Python>>正文


Python Auth.basic_auth方法代码示例

本文整理汇总了Python中auth.Auth.basic_auth方法的典型用法代码示例。如果您正苦于以下问题:Python Auth.basic_auth方法的具体用法?Python Auth.basic_auth怎么用?Python Auth.basic_auth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在auth.Auth的用法示例。


在下文中一共展示了Auth.basic_auth方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: RestServer

# 需要导入模块: from auth import Auth [as 别名]
# 或者: from auth.Auth import basic_auth [as 别名]
class RestServer(object):
    URI_PREFIX="uriPrefix"
    WEB_URL="webUrl"
    USER_NAME="userName"
    PUBLIC_URL="publicURL"
    RESULT="result"
    ERROR="error"
    TOKEN="token"
    WEB_INFO="webInfo"
    MAIN_PAGE="mainPage"
    URL="url"
    PASSWORD="password"
    LOCATION="location"

    def __init__(self,conf,log,db):
        self.conf=conf
        self.log=log
        self.db=db

        self.global_cfg=GlobalConfig(self.conf,self.log,self.db)
        self.proxy_mgr=ProxyMgr(self.conf,self.log,self.db)
        self.trans_proxy_mgr=TransparentProxyMgr(self.conf,self.log,self.db)
        self.nginx_mgr=NginxManager(self.conf,self.log,
                                    self.db,self.global_cfg,
                                    self.proxy_mgr,self.trans_proxy_mgr)
        self.token_mgr=TokenMgr(self.conf,self.log,self.db)
        self.user_mgr=UserMgr(self.conf,self.log,self.db)
        self.auth=Auth(self.conf,self.log,self.token_mgr,self.user_mgr,self.proxy_mgr)

        self.app=Flask(__name__)
        self.app.add_url_rule(self.conf.url_prefix+'/trans_proxy',
                             'add_trans_proxy',
                             self._add_trans_proxy,
                             methods=['POST'])
        self.app.add_url_rule(self.conf.url_prefix+'/trans_proxy/<string:location>',
                             'del_trans_proxy',
                             self._del_trans_proxy,
                             methods=['DELETE'])
        self.app.add_url_rule(self.conf.url_prefix+'/trans_proxy_sync',
                              'trans_proxy_sync',
                              self._sync_trans_proxy,
                              methods=['POST'])
        self.app.add_url_rule(self.conf.url_prefix+'/basic_auth',
                            'basic_auth',
                            self._basic_auth,
                            methods=['GET','POST'])
        self.app.add_url_rule(self.conf.url_prefix+'/token_auth',
                              'token_auth',
                              self._token_auth,
                              methods=['GET'])
        self.app.add_url_rule(self.conf.url_prefix+'/global-config',
                              'global_config',
                              self._global_config,
                              methods=['POST'])
        self.app.add_url_rule(self.conf.url_prefix+'/token',
                              'add_token',
                              self._add_token,
                              methods=['POST'])
        self.app.add_url_rule(self.conf.url_prefix+'/sync',
                              "sync",
                              self._sync,
                              methods=['POST'])
        self.app.add_url_rule(self.conf.url_prefix+'/',
                             'add_proxy_config',
                             self._add_proxy_config,
                             methods=['POST']) 
        self.app.add_url_rule(self.conf.url_prefix+'/<string:uri_prefix>',
                            'del_proxy_config',
                            self._del_proxy_config,
                            methods=['DELETE'])

    def _sync_trans_proxy(self):
        self.log.info('sync trans proxy %s'%(request.json))

        if not request.json or not isinstance(request.json,list):
            return jsonify({RestServer.ERROR:HTTP_BAD_REQUEST_STR}),HTTP_BAD_REQUEST
        
        result,code=self._add_trans_proxy()
        
        for location,port in self.trans_proxy_mgr.list_proxy():
            if {RestServer.LOCATION:location} not in request.json:
                self.nginx_mgr.del_trans_proxy(location)

        return result,code

    def _del_trans_proxy(self,location):
        self.log.info("del transparent proxy %s"%location)

        url_comps=location.split('_')
        if len(url_comps)<2:
            return jsonify({RestServer.ERROR:HTTP_BAD_REQUEST_STR}),HTTP_BAD_REQUEST

        port=TRANS_PROXY_DEFAULT_PORT
        if len(url_comps)>2:
            port=url_comps[2]
        
        url=url_comps[0]+"://"+url_comps[1]+":"+port
        self.nginx_mgr.del_trans_proxy(url)

        return jsonify({RestServer.RESULT:"ok"}),HTTP_OK
#.........这里部分代码省略.........
开发者ID:liuran2011,项目名称:web-proxy,代码行数:103,代码来源:rest_server.py


注:本文中的auth.Auth.basic_auth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。