From 936e34bf6f9d71af2201a1b3f336e11a94aad340 Mon Sep 17 00:00:00 2001 From: ZhiQiang Fan Date: Thu, 25 Dec 2014 16:12:51 +0800 Subject: [PATCH] Use oslo.context oslo-incubator.context has been ported to oslo.context, now we can remove openstack.commn.context Change-Id: Ie3729dcb494befe597a484e61e1cf92e1366bf6f --- heat/common/context.py | 2 +- heat/openstack/common/context.py | 122 ------------------------------- openstack-common.conf | 1 - requirements.txt | 1 + 4 files changed, 2 insertions(+), 124 deletions(-) delete mode 100644 heat/openstack/common/context.py diff --git a/heat/common/context.py b/heat/common/context.py index c6df51c974..7c5489815e 100644 --- a/heat/common/context.py +++ b/heat/common/context.py @@ -13,13 +13,13 @@ from oslo.middleware import request_id as oslo_request_id from oslo.utils import importutils +from oslo_context import context from heat.common import exception from heat.common import policy from heat.common import wsgi from heat.db import api as db_api from heat.engine import clients -from heat.openstack.common import context from heat.openstack.common import local diff --git a/heat/openstack/common/context.py b/heat/openstack/common/context.py deleted file mode 100644 index 168989004c..0000000000 --- a/heat/openstack/common/context.py +++ /dev/null @@ -1,122 +0,0 @@ -# Copyright 2011 OpenStack Foundation. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -""" -Simple class that stores security context information in the web request. - -Projects should subclass this class if they wish to enhance the request -context or provide additional information in their specific WSGI pipeline. -""" - -import itertools -import uuid - - -def generate_request_id(): - return b'req-' + str(uuid.uuid4()).encode('ascii') - - -class RequestContext(object): - - """Helper class to represent useful information about a request context. - - Stores information about the security context under which the user - accesses the system, as well as additional request information. - """ - - user_idt_format = '{user} {tenant} {domain} {user_domain} {p_domain}' - - def __init__(self, auth_token=None, user=None, tenant=None, domain=None, - user_domain=None, project_domain=None, is_admin=False, - read_only=False, show_deleted=False, request_id=None, - instance_uuid=None): - self.auth_token = auth_token - self.user = user - self.tenant = tenant - self.domain = domain - self.user_domain = user_domain - self.project_domain = project_domain - self.is_admin = is_admin - self.read_only = read_only - self.show_deleted = show_deleted - self.instance_uuid = instance_uuid - if not request_id: - request_id = generate_request_id() - self.request_id = request_id - - def to_dict(self): - user_idt = ( - self.user_idt_format.format(user=self.user or '-', - tenant=self.tenant or '-', - domain=self.domain or '-', - user_domain=self.user_domain or '-', - p_domain=self.project_domain or '-')) - - return {'user': self.user, - 'tenant': self.tenant, - 'domain': self.domain, - 'user_domain': self.user_domain, - 'project_domain': self.project_domain, - 'is_admin': self.is_admin, - 'read_only': self.read_only, - 'show_deleted': self.show_deleted, - 'auth_token': self.auth_token, - 'request_id': self.request_id, - 'instance_uuid': self.instance_uuid, - 'user_identity': user_idt} - - @classmethod - def from_dict(cls, ctx): - return cls( - auth_token=ctx.get("auth_token"), - user=ctx.get("user"), - tenant=ctx.get("tenant"), - domain=ctx.get("domain"), - user_domain=ctx.get("user_domain"), - project_domain=ctx.get("project_domain"), - is_admin=ctx.get("is_admin", False), - read_only=ctx.get("read_only", False), - show_deleted=ctx.get("show_deleted", False), - request_id=ctx.get("request_id"), - instance_uuid=ctx.get("instance_uuid")) - - -def get_admin_context(show_deleted=False): - context = RequestContext(None, - tenant=None, - is_admin=True, - show_deleted=show_deleted) - return context - - -def get_context_from_function_and_args(function, args, kwargs): - """Find an arg of type RequestContext and return it. - - This is useful in a couple of decorators where we don't - know much about the function we're wrapping. - """ - - for arg in itertools.chain(kwargs.values(), args): - if isinstance(arg, RequestContext): - return arg - - return None - - -def is_user_context(context): - """Indicates if the request context is a normal user.""" - if not context or context.is_admin: - return False - return context.user_id and context.project_id diff --git a/openstack-common.conf b/openstack-common.conf index ae1eb32f63..97ac412a89 100644 --- a/openstack-common.conf +++ b/openstack-common.conf @@ -2,7 +2,6 @@ # The list of modules to copy from oslo-incubator module=config -module=context module=crypto module=eventlet_backdoor module=local diff --git a/requirements.txt b/requirements.txt index 51aa280a09..312a84885c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,6 +14,7 @@ kombu>=2.5.0 lxml>=2.3 netaddr>=0.7.12 oslo.config>=1.4.0 # Apache-2.0 +oslo.context>=0.1.0 # Apache-2.0 oslo.db>=1.1.0 # Apache-2.0 oslo.i18n>=1.0.0 # Apache-2.0 oslo.messaging>=1.4.0,!=1.5.0