summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-01-06 03:39:05 +0000
committerGerrit Code Review <review@openstack.org>2015-01-06 03:39:06 +0000
commit860cdee514e32cbad121a9d8b7076b8931ed22c1 (patch)
tree1bd704943ed09e8053151309b0b9141de1fe422b
parent7c8e3e1061c2b51be59f034e0cd5b914a4ad6f47 (diff)
parent6824065b8140760cb6da4f557dc517a3439196db (diff)
downloadoslo-middleware-860cdee514e32cbad121a9d8b7076b8931ed22c1.tar.gz
Merge "switch to oslo.context"
-rw-r--r--openstack-common.conf2
-rw-r--r--oslo/middleware/openstack/__init__.py0
-rw-r--r--oslo/middleware/openstack/common/__init__.py17
-rw-r--r--oslo/middleware/openstack/common/context.py126
-rw-r--r--oslo/middleware/request_id.py2
-rw-r--r--requirements.txt1
-rw-r--r--tox.ini2
7 files changed, 3 insertions, 147 deletions
diff --git a/openstack-common.conf b/openstack-common.conf
index fc54de5..4a7efc5 100644
--- a/openstack-common.conf
+++ b/openstack-common.conf
@@ -1,8 +1,6 @@
[DEFAULT]
# The list of modules to copy from oslo-incubator.git
-module=context
-
script = tools/run_cross_tests.sh
# The base module to hold the copy of openstack.common
diff --git a/oslo/middleware/openstack/__init__.py b/oslo/middleware/openstack/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/oslo/middleware/openstack/__init__.py
+++ /dev/null
diff --git a/oslo/middleware/openstack/common/__init__.py b/oslo/middleware/openstack/common/__init__.py
deleted file mode 100644
index d1223ea..0000000
--- a/oslo/middleware/openstack/common/__init__.py
+++ /dev/null
@@ -1,17 +0,0 @@
-#
-# 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.
-
-import six
-
-
-six.add_move(six.MovedModule('mox', 'mox', 'mox3.mox'))
diff --git a/oslo/middleware/openstack/common/context.py b/oslo/middleware/openstack/common/context.py
deleted file mode 100644
index b612db7..0000000
--- a/oslo/middleware/openstack/common/context.py
+++ /dev/null
@@ -1,126 +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:
- return False
- if context.is_admin:
- return False
- if not context.user_id or not context.project_id:
- return False
- return True
diff --git a/oslo/middleware/request_id.py b/oslo/middleware/request_id.py
index f3a22c1..a8663f8 100644
--- a/oslo/middleware/request_id.py
+++ b/oslo/middleware/request_id.py
@@ -13,10 +13,10 @@
# License for the specific language governing permissions and limitations
# under the License.
+from oslo_context import context
import webob.dec
from oslo.middleware import base
-from oslo.middleware.openstack.common import context
ENV_REQUEST_ID = 'openstack.request_id'
diff --git a/requirements.txt b/requirements.txt
index 275fa4f..1b66bf0 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -5,6 +5,7 @@
pbr>=0.6,!=0.7,<1.0
Babel>=1.3
oslo.config>=1.4.0 # Apache-2.0
+oslo.context>=0.1.0 # Apache-2.0
oslo.i18n>=1.0.0 # Apache-2.0
six>=1.7.0
WebOb>=1.2.3
diff --git a/tox.ini b/tox.ini
index bf490eb..5895c1d 100644
--- a/tox.ini
+++ b/tox.ini
@@ -34,7 +34,7 @@ commands = python setup.py testr --coverage --testr-args='{posargs}'
show-source = True
ignore = E123,E125,H305,H803,H904
-exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,__init__.py
+exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,__init__.py
[hacking]
import_exceptions = oslo.middleware.i18n