Fix [H302] errors in heat/common

Change-Id: Id72426a6f921002630ad74ed00166885fb2ddf37
This commit is contained in:
Peter Razumovsky 2014-11-13 14:57:22 +03:00
parent f6107ce70b
commit 90f9a0a49d
6 changed files with 18 additions and 20 deletions

View File

@ -16,7 +16,7 @@
from keystoneclient import exceptions as keystone_exceptions
from keystoneclient.v2_0 import client as keystone_client
from webob.exc import HTTPUnauthorized
from webob import exc
class KeystonePasswordAuthProtocol(object):
@ -56,7 +56,7 @@ class KeystonePasswordAuthProtocol(object):
def _reject_request(self, env, start_response, auth_url):
"""Redirect client to auth server."""
headers = [('WWW-Authenticate', 'Keystone uri=\'%s\'' % auth_url)]
resp = HTTPUnauthorized('Authentication required', headers)
resp = exc.HTTPUnauthorized('Authentication required', headers)
return resp(env, start_response)
def _build_user_headers(self, token_info):

View File

@ -16,8 +16,7 @@
from oslo.config import cfg
from oslo.utils import importutils
from webob.exc import HTTPBadRequest
from webob.exc import HTTPUnauthorized
from webob import exc
from heat.common.i18n import _
from heat.common import wsgi
@ -42,13 +41,12 @@ class AuthUrlFilter(wsgi.Middleware):
def _validate_auth_url(self, auth_url):
"""Validate auth_url to ensure it can be used."""
if not auth_url:
raise HTTPBadRequest(_('Request missing required header '
raise exc.HTTPBadRequest(_('Request missing required header '
'X-Auth-Url'))
allowed = cfg.CONF.auth_password.allowed_auth_uris
if auth_url not in allowed:
raise HTTPUnauthorized(_('Header X-Auth-Url "%s" not an allowed '
'endpoint')
% auth_url)
raise exc.HTTPUnauthorized(_('Header X-Auth-Url "%s" not '
'an allowed endpoint') % auth_url)
return True
def process_request(self, req):

View File

@ -12,8 +12,7 @@
# under the License.
from heat.common.i18n import _
from heat.common.template_format import yaml
from heat.common.template_format import yaml_loader
from heat.common import template_format
SECTIONS = (PARAMETERS, RESOURCE_REGISTRY) = \
@ -26,8 +25,9 @@ def parse(env_str):
return {}
try:
env = yaml.load(env_str, Loader=yaml_loader)
except yaml.YAMLError as yea:
env = template_format.yaml.load(env_str,
Loader=template_format.yaml_loader)
except template_format.yaml.YAMLError as yea:
raise ValueError(yea)
else:
if env is None:

View File

@ -13,7 +13,7 @@
"""Keystone Client functionality for use by resources."""
from collections import namedtuple
import collections
import copy
import json
from oslo.utils import importutils
@ -34,7 +34,7 @@ from heat.openstack.common import log as logging
LOG = logging.getLogger('heat.common.keystoneclient')
AccessKey = namedtuple('AccessKey', ['id', 'access', 'secret'])
AccessKey = collections.namedtuple('AccessKey', ['id', 'access', 'secret'])
_default_keystone_backend = "heat.common.heat_keystoneclient.KeystoneClientV3"

View File

@ -20,7 +20,6 @@ import base64
import uuid
import six
from six.moves import xrange
from heat.common.i18n import _
@ -31,7 +30,7 @@ def _to_byte_string(value, num_bits):
Padding is added at the end (i.e. after the least-significant bit) if
required.
"""
shifts = xrange(num_bits - 8, -8, -8)
shifts = six.moves.xrange(num_bits - 8, -8, -8)
byte_at = lambda off: (value >> off if off >= 0 else value << -off) & 0xff
return ''.join(chr(byte_at(offset)) for offset in shifts)

View File

@ -16,6 +16,7 @@
import mock
import webob
from webob import exc
from heat.common import auth_url
from heat.tests import common
@ -83,11 +84,11 @@ class AuthUrlFilterTest(common.HeatTestCase):
self.assertTrue(mock_validate.called)
def test_validate_auth_url_with_missing_url(self):
self.assertRaises(auth_url.HTTPBadRequest,
self.assertRaises(exc.HTTPBadRequest,
self.middleware._validate_auth_url,
auth_url='')
self.assertRaises(auth_url.HTTPBadRequest,
self.assertRaises(exc.HTTPBadRequest,
self.middleware._validate_auth_url,
auth_url=None)
@ -95,7 +96,7 @@ class AuthUrlFilterTest(common.HeatTestCase):
def test_validate_auth_url_with_url_not_allowed(self, mock_cfg):
mock_cfg.auth_password.allowed_auth_uris = ['foobar']
self.assertRaises(auth_url.HTTPUnauthorized,
self.assertRaises(exc.HTTPUnauthorized,
self.middleware._validate_auth_url,
auth_url='not foobar')