Remove oslo.uuidutils

The only use of uuidutils in barbican is generate_uuid
which will be dropped from oslo-incubator.

This patch moves generate_uuid to barbican.common.utils and
updates the context module from oslo.

Following changes were updated in context:

13eb01c Adding domain to context and log
12bcdb7 Remove vim header
bdabd51 Remove uuidutils imports in oslo modules
44e8222 Revert "Removes generate_uuid from uuidutils"
571a78a Removes generate_uuid from uuidutils
36859e5 Adding instance_uuid to context and log

Change-Id: If27f8308f00ce92d8cde0bc1c669c8020137eba5
Partial-bug: #1253497
This commit is contained in:
Zhongyue Luo 2014-02-27 13:05:22 +08:00
parent 4b22ed0e1c
commit 53100d02bd
6 changed files with 45 additions and 52 deletions

View File

@ -18,6 +18,7 @@ Common utilities for Barbican.
"""
import time
import uuid
from oslo.config import cfg
@ -157,3 +158,7 @@ class TimeKeeper(object):
self.logger.debug(" Final time/elapsed:"
"{0:.3f}/{1:.0f}".format(time_current,
total_elapsed * 1000.))
def generate_uuid():
return str(uuid.uuid4())

View File

@ -15,9 +15,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from barbican.common import utils
from barbican.openstack.common import policy
from barbican.openstack.common import local
from barbican.openstack.common import uuidutils
class RequestContext(object):
@ -39,7 +39,7 @@ class RequestContext(object):
# (mkbhanda) possibly domain could be owner
# brings us to the key scope question
self.owner_is_tenant = owner_is_tenant
self.request_id = uuidutils.generate_uuid()
self.request_id = utils.generate_uuid()
self.service_catalog = service_catalog
self.policy_enforcer = policy_enforcer or policy.Enforcer()
self.is_admin = is_admin

View File

@ -23,7 +23,6 @@ from sqlalchemy import orm
from barbican.common import utils
from barbican.openstack.common import timeutils
from barbican.openstack.common import uuidutils
LOG = utils.getLogger(__name__)
@ -55,7 +54,7 @@ class ModelBase(object):
"created_at", "updated_at", "deleted_at", "deleted"])
id = sa.Column(sa.String(36), primary_key=True,
default=uuidutils.generate_uuid)
default=utils.generate_uuid)
created_at = sa.Column(sa.DateTime, default=timeutils.utcnow,
nullable=False)

View File

@ -1,5 +1,3 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2011 OpenStack Foundation.
# All Rights Reserved.
#
@ -23,12 +21,11 @@ context or provide additional information in their specific WSGI pipeline.
"""
import itertools
from barbican.openstack.common import uuidutils
import uuid
def generate_request_id():
return 'req-%s' % uuidutils.generate_uuid()
return 'req-%s' % str(uuid.uuid4())
class RequestContext(object):
@ -39,26 +36,46 @@ class RequestContext(object):
accesses the system, as well as additional request information.
"""
def __init__(self, auth_token=None, user=None, tenant=None, is_admin=False,
read_only=False, show_deleted=False, request_id=None):
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}
'request_id': self.request_id,
'instance_uuid': self.instance_uuid,
'user_identity': user_idt}
def get_admin_context(show_deleted=False):
@ -81,3 +98,14 @@ def get_context_from_function_and_args(function, args, kwargs):
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

View File

@ -1,39 +0,0 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright (c) 2012 Intel Corporation.
# 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.
"""
UUID related utilities and helper functions.
"""
import uuid
def generate_uuid():
return str(uuid.uuid4())
def is_uuid_like(val):
"""Returns validation of a value as a UUID.
For our purposes, a UUID is a canonical form string:
aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
"""
try:
return str(uuid.UUID(val)) == val
except (TypeError, ValueError, AttributeError):
return False

View File

@ -1,7 +1,7 @@
[DEFAULT]
# The list of modules to copy from openstack-common
modules=gettextutils,jsonutils,log,local,timeutils,uuidutils,importutils,policy
modules=gettextutils,jsonutils,log,local,timeutils,importutils,policy
# The base module to hold the copy of openstack.common
base=barbican