requires.py 文件源码

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

项目:charm-interface-manila-plugin 作者: openstack 项目源码 文件源码
def set_authentication_data(self, value, name=None):
        """Set the authentication data to the plugin charm.  This is to enable
        the plugin to either 'talk' to OpenStack or to provide authentication
        data into the configuraiton sections that it needs to set (the generic
        backend needs to do this).

        The authentication data format is:
        {
            'username': <value>
            'password': <value>
            'project_domain_id': <value>
            'project_name': <value>
            'user_domain_id': <value>
            'auth_uri': <value>
            'auth_url': <value>
            'auth_type': <value>  # 'password', typically
        }

        :param value: a dictionary of data to set.
        :param name: OPTIONAL - target the config at a particular name only
        """
        keys = {'username', 'password', 'project_domain_id', 'project_name',
                'user_domain_id', 'auth_uri', 'auth_url', 'auth_type'}
        passed_keys = set(value.keys())
        if passed_keys.difference(keys) or keys.difference(passed_keys):
            hookenv.log(
                "Setting Authentication data; there may be missing or mispelt "
                "keys: passed: {}".format(passed_keys),
                level=hookenv.WARNING)
        # need to check for each conversation whether we've sent the data, or
        # whether it is different, and then set the local & remote only if that
        # is the case.
        for conversation in self.conversations():
            if conversation.scope is None:
                # the conversation has gone away; ignore it
                continue
            if name is not None:
                conversation_name = self.get_remote('_name', default=None,
                                                    scope=conversation.scope)
                if name != conversation_name:
                    continue
            existing_auth_data = self.get_local('_authentication_data',
                                                default=None,
                                                scope=conversation.scope)
            if existing_auth_data is not None:
                # see if they are different
                existing_auth = json.loads(existing_auth_data)["data"]
                if (existing_auth.keys() == value.keys() and
                        all([v == value[k]
                             for k, v in existing_auth.items()])):
                    # the values haven't changed, so don't set them again
                    continue
            self.set_local(_authentication_data=json.dumps({"data": value}),
                           scope=conversation.scope)
            self.set_remote(_authentication_data=json.dumps({"data": value}),
                            scope=conversation.scope)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号