简体   繁体   English

Keystone中间件(OpenStack)中的依赖注入

[英]Dependency injection in a Keystone middleware (openstack)

In my keystone middleware, i'm trying to call the assignment_api function get_project_by_name. 在我的主要中间件中,我试图调用Assignment_api函数get_project_by_name。

I'm trying to do so by using a dependency injection, but instead, i'm seeing the following error in the debug log: 我正在尝试通过使用依赖项注入来执行此操作,但是相反,我在调试日志中看到以下错误:

AttributeError: 'ProjectsByDemand' object has no attribute 'assignment_api' AttributeError:“ ProjectsByDemand”对象没有属性“ assignment_api”

See the code below: 请参见下面的代码:

from keystone.openstack.common import log as logging
from keystone.common import dependency
from keystone import config
from keystone import exception
from keystone.common import cache
from keystone.common import wsgi

@dependency.requires('assignment_api')
class ProjectsByDemand(wsgi.Middleware):
  def __init__(self, app, conf):
    self.conf = conf
    self.app = app
    self.internal_l = ['admin','neutron','glance','cinder','nova']
    self.log = logging.getLogger(__name__)

   .
   .
   .

  def process_request(self, environ, start_response):
    auth = self.get_username(environ)
    if auth is not None:
      if auth[0] is not self.internal_l:
        self.log.debug('middleware-debug: Authenticating with: %s' % (auth[0]) )
        project_ref = self.assignment_api.get_project_by_name(username, "default")
        self.log.debug("middleware-debug: Project ref is: %s", project_ref)
    return self.app(environ, start_response)

Any idea what is it that's missing? 知道丢失了什么吗?

您混用了制表符和空格,并且还弄混了缩进,请尝试使用python -tt运行脚本以进行检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM