示例#1
0
    def apigateway_response_restapis_individual(self, request, full_url, headers):
        if request.method in ['GET', 'DELETE']:
            return apigateway_response_restapis_individual_orig(self, request, full_url, headers)

        self.setup_class(request, full_url, headers)
        function_id = self.path.replace('/restapis/', '', 1).split('/')[0]

        if self.method == 'PATCH':
            not_supported_attributes = ['/id', '/region_name', '/create_date']

            rest_api = self.backend.apis.get(function_id)
            if not rest_api:
                msg = 'Invalid API identifier specified %s:%s' % (TEST_AWS_ACCOUNT_ID, function_id)
                return (404, {}, msg)

            patch_operations = self._get_param('patchOperations')
            for operation in patch_operations:
                if operation['path'].strip('/') in REST_API_ATTRIBUTES:
                    operation['path'] = camelcase_to_underscores(operation['path'])
                if operation['path'] in not_supported_attributes:
                    msg = 'Invalid patch path %s' % (operation['path'])
                    return (400, {}, msg)

            rest_api.__dict__ = DelSafeDict(rest_api.__dict__)
            apply_json_patch_safe(rest_api.__dict__, patch_operations, in_place=True)

            return 200, {}, json.dumps(self.backend.get_rest_api(function_id).to_dict())

        # handle import rest_api via swagger file
        if self.method == 'PUT':
            body = json.loads(to_str(self.body))
            rest_api = self.backend.put_rest_api(function_id, body)
            return 200, {}, json.dumps(rest_api.to_dict())

        return 400, {}, ''
示例#2
0
    def apigateway_response_restapis_individual(self, request, full_url,
                                                headers):
        if request.method in ["GET", "DELETE"]:
            return apigateway_response_restapis_individual_orig(
                self, request, full_url, headers)

        self.setup_class(request, full_url, headers)
        function_id = self.path.replace("/restapis/", "", 1).split("/")[0]

        if self.method == "PATCH":
            not_supported_attributes = ["/id", "/region_name", "/createdDate"]

            rest_api = self.backend.apis.get(function_id)
            if not rest_api:
                msg = "Invalid API identifier specified %s:%s" % (
                    TEST_AWS_ACCOUNT_ID,
                    function_id,
                )
                return 404, {}, msg

            patch_operations = self._get_param("patchOperations")
            model_attributes = list(rest_api.__dict__.keys())
            for operation in patch_operations:
                if operation["path"] in not_supported_attributes:
                    msg = "Invalid patch path %s" % (operation["path"])
                    return 400, {}, msg
                path_start = operation["path"].strip("/").split("/")[0]
                path_start_usc = camelcase_to_underscores(path_start)
                if path_start not in model_attributes and path_start_usc in model_attributes:
                    operation["path"] = operation["path"].replace(
                        path_start, path_start_usc)

            rest_api.__dict__ = DelSafeDict(rest_api.__dict__)
            apply_json_patch_safe(rest_api.__dict__,
                                  patch_operations,
                                  in_place=True)

            # fix data types after patches have been applied
            rest_api.minimum_compression_size = int(
                rest_api.minimum_compression_size or -1)
            endpoint_configs = rest_api.endpoint_configuration or {}
            if isinstance(endpoint_configs.get("vpcEndpointIds"), str):
                endpoint_configs["vpcEndpointIds"] = [
                    endpoint_configs["vpcEndpointIds"]
                ]

            return 200, {}, json.dumps(
                self.backend.get_rest_api(function_id).to_dict())

        # handle import rest_api via swagger file
        if self.method == "PUT":
            body = json.loads(to_str(self.body))
            rest_api = self.backend.put_rest_api(function_id, body,
                                                 self.querystring)
            return 200, {}, json.dumps(rest_api.to_dict())

        return 400, {}, ""
示例#3
0
    def apigateway_response_restapis_individual(self, request, full_url,
                                                headers):
        if request.method in ["GET", "DELETE"]:
            return apigateway_response_restapis_individual_orig(
                self, request, full_url, headers)

        self.setup_class(request, full_url, headers)
        function_id = self.path.replace("/restapis/", "", 1).split("/")[0]

        if self.method == "PATCH":
            rest_api = self.backend.apis.get(function_id)
            if not rest_api:
                msg = "Invalid API identifier specified %s:%s" % (
                    TEST_AWS_ACCOUNT_ID,
                    function_id,
                )
                return 404, {}, msg

            if not isinstance(rest_api.__dict__, DelSafeDict):
                rest_api.__dict__ = DelSafeDict(rest_api.__dict__)

            result = _patch_api_gateway_entity(self, rest_api.__dict__)
            if result is not None:
                return result

            # fix data types after patches have been applied
            rest_api.minimum_compression_size = int(
                rest_api.minimum_compression_size or -1)
            endpoint_configs = rest_api.endpoint_configuration or {}
            if isinstance(endpoint_configs.get("vpcEndpointIds"), str):
                endpoint_configs["vpcEndpointIds"] = [
                    endpoint_configs["vpcEndpointIds"]
                ]

            return 200, {}, json.dumps(
                self.backend.get_rest_api(function_id).to_dict())

        # handle import rest_api via swagger file
        if self.method == "PUT":
            body = json.loads(to_str(self.body))
            rest_api = self.backend.put_rest_api(function_id, body,
                                                 self.querystring)
            return 200, {}, json.dumps(rest_api.to_dict())

        return 400, {}, ""
示例#4
0
    def apigateway_response_resource_individual(self, request, full_url, headers):
        if request.method in ["GET", "POST", "DELETE"]:
            return apigateway_response_resource_individual_orig(self, request, full_url, headers)

        self.setup_class(request, full_url, headers)
        function_id = self.path.replace("/restapis/", "", 1).split("/")[0]

        if self.method == "PATCH":
            resource_id = self.path.split("/")[4]
            resource = self.backend.get_resource(function_id, resource_id)
            if not isinstance(resource.__dict__, DelSafeDict):
                resource.__dict__ = DelSafeDict(resource.__dict__)
            result = _patch_api_gateway_entity(self, resource.__dict__)
            if result is not None:
                return result
            return 200, {}, json.dumps(resource.to_dict())

        return 404, {}, ""
示例#5
0
    def apigateway_response_restapis_individual(self, request, full_url, headers):
        if request.method in ['GET', 'DELETE']:
            return apigateway_response_restapis_individual_orig(self, request, full_url, headers)

        self.setup_class(request, full_url, headers)
        function_id = self.path.replace('/restapis/', '', 1).split('/')[0]

        if self.method == 'PATCH':
            not_supported_attributes = ['/id', '/region_name', '/createdDate']

            rest_api = self.backend.apis.get(function_id)
            if not rest_api:
                msg = 'Invalid API identifier specified %s:%s' % (TEST_AWS_ACCOUNT_ID, function_id)
                return 404, {}, msg

            patch_operations = self._get_param('patchOperations')
            model_attributes = list(rest_api.__dict__.keys())
            for operation in patch_operations:
                if operation['path'] in not_supported_attributes:
                    msg = 'Invalid patch path %s' % (operation['path'])
                    return 400, {}, msg
                path_stripped = operation['path'].strip('/')
                path_underscores = camelcase_to_underscores(path_stripped)
                if path_stripped not in model_attributes and path_underscores in model_attributes:
                    operation['path'] = operation['path'].replace(path_stripped, path_underscores)

            rest_api.__dict__ = DelSafeDict(rest_api.__dict__)
            apply_json_patch_safe(rest_api.__dict__, patch_operations, in_place=True)

            # fix data types after patches have been applied
            # if rest_api.minimum_compression_size:
            rest_api.minimum_compression_size = int(rest_api.minimum_compression_size or -1)

            return 200, {}, json.dumps(self.backend.get_rest_api(function_id).to_dict())

        # handle import rest_api via swagger file
        if self.method == 'PUT':
            body = json.loads(to_str(self.body))
            rest_api = self.backend.put_rest_api(function_id, body, self.querystring)
            return 200, {}, json.dumps(rest_api.to_dict())

        return 400, {}, ''