示例#1
0
    def set_api_version_request(self):
        """Set API version request based on the request header information.

        Microversions starts with /v2, so if a client sends a /v1 URL, then
        ignore the headers and request 1.0 APIs.
        """

        if not self.script_name:
            self.api_version_request = api_version.APIVersionRequest()
        elif self.script_name == V1_SCRIPT_NAME:
            self.api_version_request = api_version.APIVersionRequest('1.0')
        else:
            if API_VERSION_REQUEST_HEADER in self.headers:
                hdr_string = self.headers[API_VERSION_REQUEST_HEADER]
                self.api_version_request = api_version.APIVersionRequest(
                    hdr_string)

                # Check that the version requested is within the global
                # minimum/maximum of supported API versions
                if not self.api_version_request.matches(
                        api_version.min_api_version(),
                        api_version.max_api_version()):
                    raise exception.InvalidGlobalAPIVersion(
                        req_ver=self.api_version_request.get_string(),
                        min_ver=api_version.min_api_version().get_string(),
                        max_ver=api_version.max_api_version().get_string())

            else:
                self.api_version_request = api_version.APIVersionRequest(
                    api_version.DEFAULT_API_VERSION)

        # Check if experimental API was requested
        if EXPERIMENTAL_API_REQUEST_HEADER in self.headers:
            self.api_version_request.experimental = strutils.bool_from_string(
                self.headers[EXPERIMENTAL_API_REQUEST_HEADER])
示例#2
0
文件: wsgi.py 项目: NetApp/manila
    def set_api_version_request(self):
        """Set API version request based on the request header information.

        Microversions starts with /v2, so if a client sends a /v1 URL, then
        ignore the headers and request 1.0 APIs.
        """

        if not self.script_name:
            self.api_version_request = api_version.APIVersionRequest()
        elif self.script_name == V1_SCRIPT_NAME:
            self.api_version_request = api_version.APIVersionRequest('1.0')
        else:
            if API_VERSION_REQUEST_HEADER in self.headers:
                hdr_string = self.headers[API_VERSION_REQUEST_HEADER]
                self.api_version_request = api_version.APIVersionRequest(
                    hdr_string)

                # Check that the version requested is within the global
                # minimum/maximum of supported API versions
                if not self.api_version_request.matches(
                        api_version.min_api_version(),
                        api_version.max_api_version()):
                    raise exception.InvalidGlobalAPIVersion(
                        req_ver=self.api_version_request.get_string(),
                        min_ver=api_version.min_api_version().get_string(),
                        max_ver=api_version.max_api_version().get_string())

            else:
                self.api_version_request = api_version.APIVersionRequest(
                    api_version.DEFAULT_API_VERSION)

        # Check if experimental API was requested
        if EXPERIMENTAL_API_REQUEST_HEADER in self.headers:
            self.api_version_request.experimental = strutils.bool_from_string(
                self.headers[EXPERIMENTAL_API_REQUEST_HEADER])
示例#3
0
    def set_api_version_request(self):
        """Set API version request based on the request header information."""
        if API_VERSION_REQUEST_HEADER in self.headers:
            hdr_string = self.headers[API_VERSION_REQUEST_HEADER]
            # 'latest' is a special keyword which is equivalent to requesting
            # the maximum version of the API supported
            if hdr_string == 'latest':
                self.api_version_request = api_version.max_api_version()
            else:
                self.api_version_request = api_version.APIVersionRequest(
                    hdr_string)

                # Check that the version requested is within the global
                # minimum/maximum of supported API versions
                if not self.api_version_request.matches(
                        api_version.min_api_version(),
                        api_version.max_api_version()):
                    raise exception.InvalidGlobalAPIVersion(
                        req_ver=self.api_version_request.get_string(),
                        min_ver=api_version.min_api_version().get_string(),
                        max_ver=api_version.max_api_version().get_string())

        else:
            self.api_version_request = api_version.APIVersionRequest(
                api_version.DEFAULT_API_VERSION)

        # Check if experimental API was requested
        if EXPERIMENTAL_API_REQUEST_HEADER in self.headers:
            self.api_version_request.experimental = strutils.bool_from_string(
                self.headers[EXPERIMENTAL_API_REQUEST_HEADER])
示例#4
0
    def test_min_version(self):

        self.assertEqual(
            api_version_request.APIVersionRequest(api_version_request._MIN_API_VERSION),
            api_version_request.min_api_version())
    def test_min_version(self):

        self.assertEqual(
            api_version_request.APIVersionRequest(
                api_version_request._MIN_API_VERSION),
            api_version_request.min_api_version())