• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python helpers._auth_key函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pymongo.helpers._auth_key函数的典型用法代码示例。如果您正苦于以下问题:Python _auth_key函数的具体用法?Python _auth_key怎么用?Python _auth_key使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: authenticate

    def authenticate(self, name, password):
        """Authenticate to use this database.

        Once authenticated, the user has full read and write access to
        this database. Raises :class:`TypeError` if either `name` or
        `password` is not an instance of ``(str,
        unicode)``. Authentication lasts for the life of the underlying
        :class:`~pymongo.connection.Connection`, or until :meth:`logout`
        is called.

        The "admin" database is special. Authenticating on "admin"
        gives access to *all* databases. Effectively, "admin" access
        means root access to the database.

        .. note:: This method authenticates the current connection, and
           will also cause all new :class:`~socket.socket` connections
           in the underlying :class:`~pymongo.connection.Connection` to
           be authenticated automatically.

           - When sharing a :class:`~pymongo.connection.Connection`
             between multiple threads, all threads will share the
             authentication. If you need different authentication profiles
             for different purposes (e.g. admin users) you must use
             distinct instances of :class:`~pymongo.connection.Connection`.

           - To get authentication to apply immediately to all
             existing sockets you may need to reset this Connection's
             sockets using :meth:`~pymongo.connection.Connection.disconnect`.

        .. warning:: Currently, calls to
           :meth:`~pymongo.connection.Connection.end_request` will
           lead to unpredictable behavior in combination with
           auth. The :class:`~socket.socket` owned by the calling
           thread will be returned to the pool, so whichever thread
           uses that :class:`~socket.socket` next will have whatever
           permissions were granted to the calling thread.

        :Parameters:
          - `name`: the name of the user to authenticate
          - `password`: the password of the user to authenticate

        .. mongodoc:: authenticate
        """
        if not isinstance(name, basestring):
            raise TypeError("name must be an instance of basestring")
        if not isinstance(password, basestring):
            raise TypeError("password must be an instance of basestring")

        nonce = self.command("getnonce")["nonce"]
        key = helpers._auth_key(nonce, name, password)
        try:
            self.command("authenticate", user=unicode(name),
                         nonce=nonce, key=key)
            self.connection._cache_credentials(self.name,
                                               unicode(name),
                                               unicode(password))
            return True
        except OperationFailure:
            return False
开发者ID:gone,项目名称:mongo-python-driver,代码行数:59,代码来源:database.py


示例2: copy_database

    def copy_database(self, from_name, to_name,
                      from_host=None, username=None, password=None):
        """Copy a database, potentially from another host.

        Raises :class:`TypeError` if `from_name` or `to_name` is not
        an instance of :class:`basestring` (:class:`str` in python 3).
        Raises :class:`~pymongo.errors.InvalidName` if `to_name` is
        not a valid database name.

        If `from_host` is ``None`` the current host is used as the
        source. Otherwise the database is copied from `from_host`.

        If the source database requires authentication, `username` and
        `password` must be specified.

        :Parameters:
          - `from_name`: the name of the source database
          - `to_name`: the name of the target database
          - `from_host` (optional): host name to copy from
          - `username` (optional): username for source database
          - `password` (optional): password for source database

        .. note:: Specifying `username` and `password` requires server
           version **>= 1.3.3+**.

        .. versionadded:: 1.5
        """
        if not isinstance(from_name, basestring):
            raise TypeError("from_name must be an instance "
                            "of %s" % (basestring.__name__,))
        if not isinstance(to_name, basestring):
            raise TypeError("to_name must be an instance "
                            "of %s" % (basestring.__name__,))

        database._check_name(to_name)

        command = {"fromdb": from_name, "todb": to_name}

        if from_host is not None:
            command["fromhost"] = from_host

        in_request = self.in_request()
        try:
            if not in_request:
                self.start_request()

            if username is not None:
                nonce = self.admin.command("copydbgetnonce",
                                           fromhost=from_host)["nonce"]
                command["username"] = username
                command["nonce"] = nonce
                command["key"] = helpers._auth_key(nonce, username, password)

            return self.admin.command("copydb", **command)
        finally:
            if not in_request:
                self.end_request()
开发者ID:assaflavie,项目名称:mongo-python-driver,代码行数:57,代码来源:connection.py


示例3: authenticate

    def authenticate(self, name, password):
        """Authenticate to use this database.

        Once authenticated, the user has full read and write access to
        this database. Raises :class:`TypeError` if either `name` or
        `password` is not an instance of ``(str,
        unicode)``. Authentication lasts for the life of the database
        connection, or until :meth:`logout` is called.

        The "admin" database is special. Authenticating on "admin"
        gives access to *all* databases. Effectively, "admin" access
        means root access to the database.

        .. note:: Currently, authentication is per
           :class:`~socket.socket`. This means that there are a couple
           of situations in which re-authentication is necessary:

           - On failover (when an
             :class:`~pymongo.errors.AutoReconnect` exception is
             raised).

           - After a call to
             :meth:`~pymongo.connection.Connection.disconnect` or
             :meth:`~pymongo.connection.Connection.end_request`.

           - When sharing a :class:`~pymongo.connection.Connection`
             between multiple threads, each thread will need to
             authenticate separately.

        .. warning:: Currently, calls to
           :meth:`~pymongo.connection.Connection.end_request` will
           lead to unpredictable behavior in combination with
           auth. The :class:`~socket.socket` owned by the calling
           thread will be returned to the pool, so whichever thread
           uses that :class:`~socket.socket` next will have whatever
           permissions were granted to the calling thread.

        :Parameters:
          - `name`: the name of the user to authenticate
          - `password`: the password of the user to authenticate

        .. mongodoc:: authenticate
        """
        if not isinstance(name, basestring):
            raise TypeError("name must be an instance of basestring")
        if not isinstance(password, basestring):
            raise TypeError("password must be an instance of basestring")

        nonce = self.command("getnonce")["nonce"]
        key = helpers._auth_key(nonce, name, password)
        try:
            self.command("authenticate", user=unicode(name),
                         nonce=nonce, key=key)
            return True
        except OperationFailure:
            return False
开发者ID:pmljm,项目名称:mongo-python-driver,代码行数:56,代码来源:database.py


示例4: __auth

    def __auth(self, sock, dbname, user, passwd):
        """Authenticate socket `sock` against database `dbname`.
        """
        # Get a nonce
        response = self.__simple_command(sock, dbname, {"getnonce": 1})
        nonce = response["nonce"]
        key = helpers._auth_key(nonce, user, passwd)

        # Actually authenticate
        query = SON([("authenticate", 1), ("user", user), ("nonce", nonce), ("key", key)])
        self.__simple_command(sock, dbname, query)
开发者ID:ananim,项目名称:mongo-python-driver,代码行数:11,代码来源:replica_set_connection.py


示例5: __auth

    def __auth(self, sock, dbname, user, passwd):
        """Authenticate socket `sock` against database `dbname`.
        """
        # Get a nonce
        response = self.__simple_command(sock, dbname, {'getnonce': 1})
        nonce = response['nonce']
        key = helpers._auth_key(nonce, user, passwd)

        # Actually authenticate
        query = SON([('authenticate', 1),
                     ('user', user), ('nonce', nonce), ('key', key)])
        self.__simple_command(sock, dbname, query)
开发者ID:eKIK,项目名称:mongo-python-driver,代码行数:12,代码来源:replica_set_connection.py


示例6: authenticate_with_nonce

    def authenticate_with_nonce(self, result, name, password, d):
        nonce = result['nonce']
        key = helpers._auth_key(nonce, name, password)

        # hacky because order matters
        auth_command = SON(authenticate=1)
        auth_command['user'] = unicode(name)
        auth_command['nonce'] = nonce
        auth_command['key'] = key

        # Now actually authenticate
        df = self["$cmd"].find_one(auth_command)
        df.addCallback(self.authenticated, d)
        df.addErrback(d.errback)

        return df
开发者ID:aschobel,项目名称:txmongo,代码行数:16,代码来源:database.py


示例7: __auth

    def __auth(self, sock, dbase, user, passwd):
        """Athenticate `sock` against `dbase`
        """
        # TODO: Error handling...
        # Get a nonce
        request_id, msg, _ = message.query(0, dbase + '.$cmd',
                                           0, -1, {'getnonce': 1})
        sock.sendall(msg)
        raw = self.__recv_msg(1, request_id, sock)
        nonce = helpers._unpack_response(raw)['data'][0]['nonce']
        key = helpers._auth_key(nonce, user, passwd)

        # Actually authenticate
        query = {'authenticate': 1, 'user': user, 'nonce': nonce, 'key': key}
        request_id, msg, _ = message.query(0, dbase + '.$cmd', 0, -1, query)
        sock.sendall(msg)
        raw = self.__recv_msg(1, request_id, sock)
        print helpers._unpack_response(raw)['data'][0]
开发者ID:bugrax,项目名称:mongo-python-driver,代码行数:18,代码来源:replica_set_connection.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python helpers._check_command_response函数代码示例发布时间:2022-05-27
下一篇:
Python database.Database类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap