コード例 #1
0
 def update_account(
     self, context: RequestContext, patch_operations: ListOfPatchOperation = None
 ) -> Account:
     region_details = APIGatewayRegion.get()
     apply_json_patch_safe(region_details.account, patch_operations, in_place=True)
     result = to_account_response_json(region_details.account)
     return Account(**result)
コード例 #2
0
 def get_account(
     self,
     context: RequestContext,
 ) -> Account:
     region_details = APIGatewayRegion.get()
     result = to_account_response_json(region_details.account)
     return Account(**result)
コード例 #3
0
    def update_request_validator(
        self,
        context: RequestContext,
        rest_api_id: String,
        request_validator_id: String,
        patch_operations: ListOfPatchOperation = None,
    ) -> RequestValidator:
        region_details = APIGatewayRegion.get()

        auth_list = region_details.validators.get(rest_api_id) or []
        validator = ([a for a in auth_list if a["id"] == request_validator_id] or [None])[0]

        if validator is None:
            raise NotFoundException(
                f"Validator {request_validator_id} for API Gateway {rest_api_id} not found"
            )

        result = apply_json_patch_safe(validator, patch_operations)

        entry_list = region_details.validators[rest_api_id]
        for i in range(len(entry_list)):
            if entry_list[i]["id"] == request_validator_id:
                entry_list[i] = result

        result = to_validator_response_json(rest_api_id, result)
        return RequestValidator(**result)
コード例 #4
0
    def update_base_path_mapping(
        self,
        context: RequestContext,
        domain_name: String,
        base_path: String,
        patch_operations: ListOfPatchOperation = None,
    ) -> BasePathMapping:
        region_details = APIGatewayRegion.get()

        mappings_list = region_details.base_path_mappings.get(domain_name) or []

        mapping = ([m for m in mappings_list if m["basePath"] == base_path] or [None])[0]
        if mapping is None:
            raise NotFoundException(
                f"Not found: mapping for domain name {domain_name}, "
                f"base path {base_path} in list {mappings_list}"
            )

        patch_operations = ensure_list(patch_operations)
        for operation in patch_operations:
            if operation["path"] == "/restapiId":
                operation["path"] = "/restApiId"
        result = apply_json_patch_safe(mapping, patch_operations)

        for i in range(len(mappings_list)):
            if mappings_list[i]["basePath"] == base_path:
                mappings_list[i] = result

        result = to_base_mapping_response_json(domain_name, base_path, result)
        return BasePathMapping(**result)
コード例 #5
0
 def get_vpc_link(self, context: RequestContext, vpc_link_id: String) -> VpcLink:
     region_details = APIGatewayRegion.get()
     vpc_link = region_details.vpc_links.get(vpc_link_id)
     if vpc_link is None:
         raise NotFoundException(f'VPC link ID "{vpc_link_id}" not found')
     result = to_vpc_link_response_json(vpc_link)
     return VpcLink(**result)
コード例 #6
0
 def delete_client_certificate(
     self, context: RequestContext, client_certificate_id: String
 ) -> None:
     region_details = APIGatewayRegion.get()
     entity = region_details.client_certificates.pop(client_certificate_id, None)
     if entity is None:
         raise NotFoundException(f'VPC link ID "{client_certificate_id}" not found for deletion')
コード例 #7
0
 def get_client_certificate(
     self, context: RequestContext, client_certificate_id: String
 ) -> ClientCertificate:
     region_details = APIGatewayRegion.get()
     result = region_details.client_certificates.get(client_certificate_id)
     if result is None:
         raise NotFoundException(f"Client certificate ID {client_certificate_id} not found")
     return ClientCertificate(**result)
コード例 #8
0
 def get_vpc_links(
     self, context: RequestContext, position: String = None, limit: NullableInteger = None
 ) -> VpcLinks:
     region_details = APIGatewayRegion.get()
     result = region_details.vpc_links.values()
     result = [to_vpc_link_response_json(r) for r in result]
     result = {"items": result}
     return result
コード例 #9
0
    def delete_authorizer(
        self, context: RequestContext, rest_api_id: String, authorizer_id: String
    ) -> None:
        region_details = APIGatewayRegion.get()

        auth_list = region_details.authorizers.get(rest_api_id, [])
        for i in range(len(auth_list)):
            if auth_list[i]["id"] == authorizer_id:
                del auth_list[i]
                break
コード例 #10
0
    def delete_documentation_part(
        self, context: RequestContext, rest_api_id: String, documentation_part_id: String
    ) -> None:
        region_details = APIGatewayRegion.get()

        auth_list = region_details.documentation_parts[rest_api_id]
        for i in range(len(auth_list)):
            if auth_list[i]["id"] == documentation_part_id:
                del auth_list[i]
                break
コード例 #11
0
    def delete_base_path_mapping(
        self, context: RequestContext, domain_name: String, base_path: String
    ) -> None:
        region_details = APIGatewayRegion.get()

        mappings_list = region_details.base_path_mappings.get(domain_name) or []
        for i in range(len(mappings_list)):
            if mappings_list[i]["basePath"] == base_path:
                del mappings_list[i]
                return

        raise NotFoundException(f"Base path mapping {base_path} for domain {domain_name} not found")
コード例 #12
0
    def get_base_path_mapping(
        self, context: RequestContext, domain_name: String, base_path: String
    ) -> BasePathMapping:
        region_details = APIGatewayRegion.get()

        mappings_list = region_details.base_path_mappings.get(domain_name) or []
        mapping = ([m for m in mappings_list if m["basePath"] == base_path] or [None])[0]
        if mapping is None:
            raise NotFoundException(f"Base path mapping not found: {domain_name} - {base_path}")

        result = to_base_mapping_response_json(domain_name, base_path, mapping)
        return BasePathMapping(**result)
コード例 #13
0
    def get_documentation_parts(
        self, context: RequestContext, request: GetDocumentationPartsRequest
    ) -> DocumentationParts:
        region_details = APIGatewayRegion.get()

        # This function returns either a list or a single entity (depending on the path)
        api_id = request["restApiId"]
        auth_list = region_details.documentation_parts.get(api_id) or []

        result = [to_documentation_part_response_json(api_id, a) for a in auth_list]
        result = {"item": result}
        return result
コード例 #14
0
 def update_vpc_link(
     self,
     context: RequestContext,
     vpc_link_id: String,
     patch_operations: ListOfPatchOperation = None,
 ) -> VpcLink:
     region_details = APIGatewayRegion.get()
     vpc_link = region_details.vpc_links.get(vpc_link_id)
     if vpc_link is None:
         raise NotFoundException(f'VPC link ID "{vpc_link_id}" not found')
     result = apply_json_patch_safe(vpc_link, patch_operations)
     result = to_vpc_link_response_json(result)
     return VpcLink(**result)
コード例 #15
0
 def update_client_certificate(
     self,
     context: RequestContext,
     client_certificate_id: String,
     patch_operations: ListOfPatchOperation = None,
 ) -> ClientCertificate:
     region_details = APIGatewayRegion.get()
     entity = region_details.client_certificates.get(client_certificate_id)
     if entity is None:
         raise NotFoundException(f'Client certificate ID "{client_certificate_id}" not found')
     result = apply_json_patch_safe(entity, patch_operations)
     result = to_client_cert_response_json(result)
     return ClientCertificate(**result)
コード例 #16
0
    def get_request_validators(
        self,
        context: RequestContext,
        rest_api_id: String,
        position: String = None,
        limit: NullableInteger = None,
    ) -> RequestValidators:
        region_details = APIGatewayRegion.get()

        auth_list = region_details.validators.get(rest_api_id) or []

        result = [to_validator_response_json(rest_api_id, a) for a in auth_list]
        return RequestValidators(items=result)
コード例 #17
0
    def get_authorizers(
        self,
        context: RequestContext,
        rest_api_id: String,
        position: String = None,
        limit: NullableInteger = None,
    ) -> Authorizers:
        # TODO add paging
        region_details = APIGatewayRegion.get()

        auth_list = region_details.authorizers.get(rest_api_id) or []

        result = [to_authorizer_response_json(rest_api_id, a) for a in auth_list]
        return Authorizers(items=result)
コード例 #18
0
    def delete_request_validator(
        self, context: RequestContext, rest_api_id: String, request_validator_id: String
    ) -> None:
        region_details = APIGatewayRegion.get()

        auth_list = region_details.validators.get(rest_api_id, [])
        for i in range(len(auth_list)):
            if auth_list[i]["id"] == request_validator_id:
                del auth_list[i]
                return

        raise NotFoundException(
            f"Validator {request_validator_id} for API Gateway {rest_api_id} not found"
        )
コード例 #19
0
 def create_vpc_link(
     self,
     context: RequestContext,
     name: String,
     target_arns: ListOfString,
     description: String = None,
     tags: MapOfStringToString = None,
 ) -> VpcLink:
     region_details = APIGatewayRegion.get()
     link_id = short_uid()
     entry = {"id": link_id, "status": "AVAILABLE"}
     region_details.vpc_links[link_id] = entry
     result = to_vpc_link_response_json(entry)
     return VpcLink(**result)
コード例 #20
0
    def get_request_validator(
        self, context: RequestContext, rest_api_id: String, request_validator_id: String
    ) -> RequestValidator:
        region_details = APIGatewayRegion.get()

        auth_list = region_details.validators.get(rest_api_id) or []
        validator = ([a for a in auth_list if a["id"] == request_validator_id] or [None])[0]

        if validator is None:
            raise NotFoundException(
                f"Validator {request_validator_id} for API Gateway {rest_api_id} not found"
            )
        result = to_validator_response_json(rest_api_id, validator)
        return RequestValidator(**result)
コード例 #21
0
    def create_authorizer(
        self, context: RequestContext, request: CreateAuthorizerRequest
    ) -> Authorizer:
        region_details = APIGatewayRegion.get()

        api_id = request["restApiId"]
        authorizer_id = short_uid()[:6]  # length 6 to make TF tests pass
        result = deepcopy(request)

        result["id"] = authorizer_id
        result = normalize_authorizer(result)
        region_details.authorizers.setdefault(api_id, []).append(result)

        result = to_authorizer_response_json(api_id, result)
        return Authorizer(**result)
コード例 #22
0
    def get_base_path_mappings(
        self,
        context: RequestContext,
        domain_name: String,
        position: String = None,
        limit: NullableInteger = None,
    ) -> BasePathMappings:
        region_details = APIGatewayRegion.get()

        mappings_list = region_details.base_path_mappings.get(domain_name) or []

        result = [
            to_base_mapping_response_json(domain_name, m["basePath"], m) for m in mappings_list
        ]
        return BasePathMappings(items=result)
コード例 #23
0
 def generate_client_certificate(
     self, context: RequestContext, description: String = None, tags: MapOfStringToString = None
 ) -> ClientCertificate:
     region_details = APIGatewayRegion.get()
     cert_id = short_uid()
     creation_time = now_utc()
     entry = {
         "description": description,
         "tags": tags,
         "clientCertificateId": cert_id,
         "createdDate": creation_time,
         "expirationDate": creation_time + 60 * 60 * 24 * 30,  # assume 30 days validity
         "pemEncodedCertificate": "testcert-123",  # TODO return proper certificate!
     }
     region_details.client_certificates[cert_id] = entry
     result = to_client_cert_response_json(entry)
     return ClientCertificate(**result)
コード例 #24
0
    def create_documentation_part(
        self,
        context: RequestContext,
        rest_api_id: String,
        location: DocumentationPartLocation,
        properties: String,
    ) -> DocumentationPart:
        region_details = APIGatewayRegion.get()

        entity_id = short_uid()[:6]  # length 6 for AWS parity / Terraform compatibility
        entry = {
            "id": entity_id,
            "restApiId": rest_api_id,
            "location": location,
            "properties": properties,
        }

        region_details.documentation_parts.setdefault(rest_api_id, []).append(entry)

        result = to_documentation_part_response_json(rest_api_id, entry)
        return DocumentationPart(**result)
コード例 #25
0
    def update_documentation_part(
        self,
        context: RequestContext,
        rest_api_id: String,
        documentation_part_id: String,
        patch_operations: ListOfPatchOperation = None,
    ) -> DocumentationPart:
        region_details = APIGatewayRegion.get()

        entity = find_api_subentity_by_id(rest_api_id, documentation_part_id, "documentation_parts")
        if entity is None:
            raise NotFoundException(f"Documentation part not found: {documentation_part_id}")

        result = apply_json_patch_safe(entity, patch_operations)

        auth_list = region_details.documentation_parts[rest_api_id]
        for i in range(len(auth_list)):
            if auth_list[i]["id"] == documentation_part_id:
                auth_list[i] = result

        result = to_documentation_part_response_json(rest_api_id, result)
        return DocumentationPart(**result)
コード例 #26
0
    def update_authorizer(
        self,
        context: RequestContext,
        rest_api_id: String,
        authorizer_id: String,
        patch_operations: ListOfPatchOperation = None,
    ) -> Authorizer:
        region_details = APIGatewayRegion.get()

        authorizer = find_api_subentity_by_id(rest_api_id, authorizer_id, "authorizers")
        if authorizer is None:
            raise NotFoundException(f"Authorizer not found: {authorizer_id}")

        result = apply_json_patch_safe(authorizer, patch_operations)
        result = normalize_authorizer(result)

        auth_list = region_details.authorizers[rest_api_id]
        for i in range(len(auth_list)):
            if auth_list[i]["id"] == authorizer_id:
                auth_list[i] = result

        result = to_authorizer_response_json(rest_api_id, result)
        return Authorizer(**result)
コード例 #27
0
    def create_request_validator(
        self,
        context: RequestContext,
        rest_api_id: String,
        name: String = None,
        validate_request_body: Boolean = None,
        validate_request_parameters: Boolean = None,
    ) -> RequestValidator:
        region_details = APIGatewayRegion.get()

        # length 6 for AWS parity and TF compatibility
        validator_id = short_uid()[:6]

        entry = {
            "id": validator_id,
            "name": name,
            "restApiId": rest_api_id,
            "validateRequestBody": validate_request_body,
            "validateRequestParameters": validate_request_parameters,
        }
        region_details.validators.setdefault(rest_api_id, []).append(entry)

        return RequestValidator(**entry)
コード例 #28
0
    def create_base_path_mapping(
        self,
        context: RequestContext,
        domain_name: String,
        rest_api_id: String,
        base_path: String = None,
        stage: String = None,
    ) -> BasePathMapping:
        region_details = APIGatewayRegion.get()

        # Note: "(none)" is a special value in API GW:
        # https://docs.aws.amazon.com/apigateway/api-reference/link-relation/basepathmapping-by-base-path
        base_path = base_path or "(none)"

        entry = {
            "domainName": domain_name,
            "restApiId": rest_api_id,
            "basePath": base_path,
            "stage": stage,
        }
        region_details.base_path_mappings.setdefault(domain_name, []).append(entry)

        result = to_base_mapping_response_json(domain_name, base_path, entry)
        return BasePathMapping(**result)
コード例 #29
0
 def delete_vpc_link(self, context: RequestContext, vpc_link_id: String) -> None:
     region_details = APIGatewayRegion.get()
     vpc_link = region_details.vpc_links.pop(vpc_link_id, None)
     if vpc_link is None:
         raise NotFoundException(f'VPC link ID "{vpc_link_id}" not found for deletion')
コード例 #30
0
 def get_client_certificates(
     self, context: RequestContext, position: String = None, limit: NullableInteger = None
 ) -> ClientCertificates:
     region_details = APIGatewayRegion.get()
     result = list(region_details.client_certificates.values())
     return ClientCertificates(items=result)