Merge "Use http_client constants instead of hardcoding"
This commit is contained in:
commit
ee58ebb724
|
@ -16,6 +16,7 @@
|
|||
import uuid
|
||||
|
||||
import six
|
||||
from six.moves import http_client
|
||||
|
||||
from keystone.catalog import schema
|
||||
from keystone.common import controller
|
||||
|
@ -231,7 +232,8 @@ class RegionV3(controller.V3Controller):
|
|||
ref = self.catalog_api.create_region(ref, initiator)
|
||||
return wsgi.render_response(
|
||||
RegionV3.wrap_member(request.context_dict, ref),
|
||||
status=(201, 'Created'))
|
||||
status=(http_client.CREATED,
|
||||
http_client.responses[http_client.CREATED]))
|
||||
|
||||
@controller.filterprotected('parent_region_id')
|
||||
def list_regions(self, request, filters):
|
||||
|
|
|
@ -31,6 +31,7 @@ from oslo_utils import importutils
|
|||
from oslo_utils import strutils
|
||||
import routes.middleware
|
||||
import six
|
||||
from six.moves import http_client
|
||||
import webob.dec
|
||||
import webob.exc
|
||||
|
||||
|
@ -245,7 +246,9 @@ class Application(BaseApplication):
|
|||
user_locale=best_match_language(req))
|
||||
|
||||
if result is None:
|
||||
return render_response(status=(204, 'No Content'))
|
||||
return render_response(
|
||||
status=(http_client.NO_CONTENT,
|
||||
http_client.responses[http_client.NO_CONTENT]))
|
||||
elif isinstance(result, six.string_types):
|
||||
return result
|
||||
elif isinstance(result, webob.Response):
|
||||
|
@ -263,7 +266,8 @@ class Application(BaseApplication):
|
|||
controller = importutils.import_class('keystone.common.controller')
|
||||
code = None
|
||||
if isinstance(self, controller.V3Controller) and req_method == 'POST':
|
||||
code = (201, 'Created')
|
||||
code = (http_client.CREATED,
|
||||
http_client.responses[http_client.CREATED])
|
||||
return code
|
||||
|
||||
def _normalize_arg(self, arg):
|
||||
|
@ -695,7 +699,7 @@ class V3ExtensionRouter(ExtensionRouter, RoutersBase):
|
|||
|
||||
response = request.get_response(self.application)
|
||||
|
||||
if response.status_code != 200:
|
||||
if response.status_code != http_client.OK:
|
||||
# The request failed, so don't update the response.
|
||||
return response
|
||||
|
||||
|
@ -721,7 +725,8 @@ def render_response(body=None, status=None, headers=None, method=None):
|
|||
|
||||
if body is None:
|
||||
body = b''
|
||||
status = status or (204, 'No Content')
|
||||
status = status or (http_client.NO_CONTENT,
|
||||
http_client.responses[http_client.NO_CONTENT])
|
||||
else:
|
||||
content_types = [v for h, v in headers if h == 'Content-Type']
|
||||
if content_types:
|
||||
|
@ -733,7 +738,8 @@ def render_response(body=None, status=None, headers=None, method=None):
|
|||
body = jsonutils.dump_as_bytes(body, cls=utils.SmarterEncoder)
|
||||
if content_type is None:
|
||||
headers.append(('Content-Type', 'application/json'))
|
||||
status = status or (200, 'OK')
|
||||
status = status or (http_client.OK,
|
||||
http_client.responses[http_client.OK])
|
||||
|
||||
# NOTE(davechen): `mod_wsgi` follows the standards from pep-3333 and
|
||||
# requires the value in response header to be binary type(str) on python2,
|
||||
|
|
|
@ -39,6 +39,7 @@ import uuid
|
|||
from keystoneclient.contrib.ec2 import utils as ec2_utils
|
||||
from oslo_serialization import jsonutils
|
||||
import six
|
||||
from six.moves import http_client
|
||||
|
||||
from keystone.common import controller
|
||||
from keystone.common import dependency
|
||||
|
@ -435,4 +436,6 @@ def render_token_data_response(token_id, token_data):
|
|||
headers = [('X-Subject-Token', token_id)]
|
||||
|
||||
return wsgi.render_response(body=token_data,
|
||||
status=(200, 'OK'), headers=headers)
|
||||
status=(http_client.OK,
|
||||
http_client.responses[http_client.OK]),
|
||||
headers=headers)
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
import string
|
||||
|
||||
from oslo_log import log
|
||||
from six.moves import http_client
|
||||
from six.moves import urllib
|
||||
import webob
|
||||
|
||||
|
@ -95,7 +96,9 @@ class IdentityProvider(_ControllerBase):
|
|||
identity_provider.setdefault('enabled', False)
|
||||
idp_ref = self.federation_api.create_idp(idp_id, identity_provider)
|
||||
response = IdentityProvider.wrap_member(request.context_dict, idp_ref)
|
||||
return wsgi.render_response(body=response, status=(201, 'Created'))
|
||||
return wsgi.render_response(
|
||||
body=response, status=(http_client.CREATED,
|
||||
http_client.responses[http_client.CREATED]))
|
||||
|
||||
@controller.filterprotected('id', 'enabled')
|
||||
def list_identity_providers(self, request, filters):
|
||||
|
@ -183,7 +186,9 @@ class FederationProtocol(_ControllerBase):
|
|||
ref = self._normalize_dict(protocol)
|
||||
ref = self.federation_api.create_protocol(idp_id, protocol_id, ref)
|
||||
response = FederationProtocol.wrap_member(request.context_dict, ref)
|
||||
return wsgi.render_response(body=response, status=(201, 'Created'))
|
||||
return wsgi.render_response(
|
||||
body=response, status=(http_client.CREATED,
|
||||
http_client.responses[http_client.CREATED]))
|
||||
|
||||
@controller.protected()
|
||||
@validation.validated(schema.protocol_update, 'protocol')
|
||||
|
@ -222,7 +227,9 @@ class MappingController(_ControllerBase):
|
|||
mapping_ref = self.federation_api.create_mapping(mapping_id, ref)
|
||||
response = MappingController.wrap_member(request.context_dict,
|
||||
mapping_ref)
|
||||
return wsgi.render_response(body=response, status=(201, 'Created'))
|
||||
return wsgi.render_response(
|
||||
body=response, status=(http_client.CREATED,
|
||||
http_client.responses[http_client.CREATED]))
|
||||
|
||||
@controller.protected()
|
||||
def list_mappings(self, request):
|
||||
|
@ -394,9 +401,10 @@ class Auth(auth_controllers.Auth):
|
|||
(response, service_provider) = t
|
||||
|
||||
headers = self._build_response_headers(service_provider)
|
||||
return wsgi.render_response(body=response.to_string(),
|
||||
status=(200, 'OK'),
|
||||
headers=headers)
|
||||
return wsgi.render_response(
|
||||
body=response.to_string(),
|
||||
status=(http_client.OK, http_client.responses[http_client.OK]),
|
||||
headers=headers)
|
||||
|
||||
@validation.validated(schema.saml_create, 'auth')
|
||||
def create_ecp_assertion(self, context, auth):
|
||||
|
@ -414,9 +422,10 @@ class Auth(auth_controllers.Auth):
|
|||
relay_state_prefix)
|
||||
|
||||
headers = self._build_response_headers(service_provider)
|
||||
return wsgi.render_response(body=ecp_assertion.to_string(),
|
||||
status=(200, 'OK'),
|
||||
headers=headers)
|
||||
return wsgi.render_response(
|
||||
body=ecp_assertion.to_string(),
|
||||
status=(http_client.OK, http_client.responses[http_client.OK]),
|
||||
headers=headers)
|
||||
|
||||
|
||||
@dependency.requires('assignment_api', 'resource_api')
|
||||
|
@ -491,7 +500,9 @@ class ServiceProvider(_ControllerBase):
|
|||
CONF.saml.relay_state_prefix)
|
||||
sp_ref = self.federation_api.create_sp(sp_id, service_provider)
|
||||
response = ServiceProvider.wrap_member(request.context_dict, sp_ref)
|
||||
return wsgi.render_response(body=response, status=(201, 'Created'))
|
||||
return wsgi.render_response(
|
||||
body=response, status=(http_client.CREATED,
|
||||
http_client.responses[http_client.CREATED]))
|
||||
|
||||
@controller.filterprotected('id', 'enabled')
|
||||
def list_service_providers(self, request, filters):
|
||||
|
@ -529,5 +540,7 @@ class SAMLMetadataV3(_ControllerBase):
|
|||
except IOError as e:
|
||||
# Raise HTTP 500 in case Metadata file cannot be read.
|
||||
raise exception.MetadataFileError(reason=e)
|
||||
return wsgi.render_response(body=metadata, status=(200, 'OK'),
|
||||
headers=[('Content-Type', 'text/xml')])
|
||||
return wsgi.render_response(
|
||||
body=metadata, status=(http_client.OK,
|
||||
http_client.responses[http_client.OK]),
|
||||
headers=[('Content-Type', 'text/xml')])
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import timeutils
|
||||
from six.moves import http_client
|
||||
|
||||
from keystone.common import controller
|
||||
from keystone.common import dependency
|
||||
|
@ -260,9 +261,11 @@ class OAuthControllerV3(controller.V3Controller):
|
|||
result += expiry_bit
|
||||
|
||||
headers = [('Content-Type', 'application/x-www-urlformencoded')]
|
||||
response = wsgi.render_response(result,
|
||||
status=(201, 'Created'),
|
||||
headers=headers)
|
||||
response = wsgi.render_response(
|
||||
result,
|
||||
status=(http_client.CREATED,
|
||||
http_client.responses[http_client.CREATED]),
|
||||
headers=headers)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -339,9 +342,11 @@ class OAuthControllerV3(controller.V3Controller):
|
|||
result += expiry_bit
|
||||
|
||||
headers = [('Content-Type', 'application/x-www-urlformencoded')]
|
||||
response = wsgi.render_response(result,
|
||||
status=(201, 'Created'),
|
||||
headers=headers)
|
||||
response = wsgi.render_response(
|
||||
result,
|
||||
status=(http_client.CREATED,
|
||||
http_client.responses[http_client.CREATED]),
|
||||
headers=headers)
|
||||
|
||||
return response
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
import uuid
|
||||
|
||||
from six.moves import http_client
|
||||
|
||||
from keystone.common import controller
|
||||
from keystone.common import dependency
|
||||
|
@ -188,8 +189,10 @@ class DomainConfigV3(controller.V3Controller):
|
|||
# Return status code 200, since config already existed
|
||||
return wsgi.render_response(body={self.member_name: ref})
|
||||
else:
|
||||
return wsgi.render_response(body={self.member_name: ref},
|
||||
status=(201, 'Created'))
|
||||
return wsgi.render_response(
|
||||
body={self.member_name: ref},
|
||||
status=(http_client.CREATED,
|
||||
http_client.responses[http_client.CREATED]))
|
||||
|
||||
@controller.protected()
|
||||
def get_domain_config(self, request, domain_id, group=None, option=None):
|
||||
|
|
|
@ -107,7 +107,8 @@ class ApplicationTest(BaseWSGITest):
|
|||
|
||||
def test_render_response_custom_status(self):
|
||||
resp = wsgi.render_response(
|
||||
status=(http_client.NOT_IMPLEMENTED, 'Not Implemented'))
|
||||
status=(http_client.NOT_IMPLEMENTED,
|
||||
http_client.responses[http_client.NOT_IMPLEMENTED]))
|
||||
self.assertEqual('501 Not Implemented', resp.status)
|
||||
self.assertEqual(http_client.NOT_IMPLEMENTED, resp.status_int)
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
# under the License.
|
||||
|
||||
from oslo_serialization import jsonutils
|
||||
from six.moves import http_client
|
||||
import webob
|
||||
|
||||
from keystone.common import extension
|
||||
|
@ -169,11 +170,14 @@ class Version(wsgi.Application):
|
|||
headers=(('Content-Type', MimeTypes.JSON_HOME),))
|
||||
|
||||
versions = self._get_versions_list(request.context_dict)
|
||||
return wsgi.render_response(status=(300, 'Multiple Choices'), body={
|
||||
'versions': {
|
||||
'values': list(versions.values())
|
||||
}
|
||||
})
|
||||
return wsgi.render_response(
|
||||
status=(http_client.MULTIPLE_CHOICES,
|
||||
http_client.responses[http_client.MULTIPLE_CHOICES]),
|
||||
body={
|
||||
'versions': {
|
||||
'values': list(versions.values())
|
||||
}
|
||||
})
|
||||
|
||||
def get_version_v2(self, request):
|
||||
versions = self._get_versions_list(request.context_dict)
|
||||
|
|
Loading…
Reference in New Issue