Parse roles from Keystone into the Context
Change-Id: I9e2f1e45db70384943b5d59b8e27599905711634
This commit is contained in:
@@ -13,10 +13,10 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from moniker.openstack.common.context import RequestContext
|
||||
from moniker.openstack.common import cfg
|
||||
from moniker.openstack.common import log as logging
|
||||
from moniker import wsgi
|
||||
from moniker.context import MonikerContext
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@@ -40,12 +40,16 @@ def pipeline_factory(loader, global_conf, **local_conf):
|
||||
class KeystoneContextMiddleware(wsgi.Middleware):
|
||||
def process_request(self, request):
|
||||
headers = request.headers
|
||||
context = RequestContext(auth_tok=headers.get('X-Auth-Token'),
|
||||
|
||||
roles = headers.get('X-Roles').split(',')
|
||||
|
||||
context = MonikerContext(auth_tok=headers.get('X-Auth-Token'),
|
||||
user=headers.get('X-User-ID'),
|
||||
tenant=headers.get('X-Tenant-ID'))
|
||||
tenant=headers.get('X-Tenant-ID'),
|
||||
roles=roles)
|
||||
request.environ['context'] = context
|
||||
|
||||
|
||||
class NoAuthMiddleware(wsgi.Middleware):
|
||||
def process_request(self, request):
|
||||
request.environ['context'] = RequestContext()
|
||||
request.environ['context'] = MonikerContext()
|
||||
|
||||
@@ -19,7 +19,8 @@ from moniker.openstack.common import context
|
||||
|
||||
class MonikerContext(context.RequestContext):
|
||||
def __init__(self, auth_tok=None, user=None, tenant=None, is_admin=False,
|
||||
read_only=False, show_deleted=False, request_id=None):
|
||||
read_only=False, show_deleted=False, request_id=None,
|
||||
roles=[]):
|
||||
super(MonikerContext, self).__init__(
|
||||
auth_tok=auth_tok,
|
||||
user=user,
|
||||
@@ -31,6 +32,7 @@ class MonikerContext(context.RequestContext):
|
||||
|
||||
self.user_id = user
|
||||
self.tenant_id = tenant
|
||||
self.roles = roles
|
||||
|
||||
def to_dict(self):
|
||||
d = super(MonikerContext, self).to_dict()
|
||||
@@ -38,6 +40,7 @@ class MonikerContext(context.RequestContext):
|
||||
d.update({
|
||||
'user_id': self.user_id,
|
||||
'tenant_id': self.tenant_id,
|
||||
'roles': self.roles,
|
||||
})
|
||||
|
||||
return d
|
||||
|
||||
Reference in New Issue
Block a user