示例#1
0
 def test_get_package_hierarchy_for_customer_uploaded_event(self):
     self.assertEqual("schema.myevent", get_package_hierarchy("MyEvent"))
     self.assertEqual(
         "schema.myevent_special_characters_etc",
         get_package_hierarchy("MyEvent.Special#Characters$etc"))
     self.assertEqual("schema.myevent.discriminator",
                      get_package_hierarchy("MyEvent@Discriminator"))
     self.assertEqual(
         "schema.myevent.discriminator.another",
         get_package_hierarchy("MyEvent@Discriminator@Another"))
示例#2
0
 def test_get_package_hierarchy_for_aws_schema(self):
     self.assertEqual(
         "schema.aws.autoscalling.ec2instancelaunchsuccessful",
         get_package_hierarchy(
             "aws.autoscalling@EC2InstanceLaunchSuccessful"),
     )
     self.assertEqual(
         "schema.aws.ec2.ec2instancestatechangenotificationevent",
         get_package_hierarchy(
             "aws.ec2.EC2InstanceStateChangeNotificationEvent"),
     )
示例#3
0
 def test_get_package_hierarchy_for_partner_schema(self):
     self.assertEqual(
         "schema.aws.partner.mongodb_com_1234567_tickets.ticketcreated",
         get_package_hierarchy(
             "aws.partner-mongodb.com/1234567-tickets@TicketCreated"),
     )
     self.assertEqual(
         "schema.aws.partner.zendesk_com_some_other_special_chars.myevent",
         get_package_hierarchy(
             "aws.partner-zendesk.com/some#other#special#chars@MyEvent"),
     )
     self.assertEqual(
         "schema.aws.partner.pagerduty_com.yougotpaged",
         get_package_hierarchy("aws.partner-pagerduty.com@YouGotPaged"),
     )
示例#4
0
    def get_schema_metadata(self, registry_name, schema_name):
        describe_schema_response = self._schemas_client.describe_schema(
            RegistryName=registry_name, SchemaName=schema_name
        )
        try:
            content = json.loads(describe_schema_response["Content"])
            schemas = content["components"]["schemas"]
            # setting default values
            event_source = DEFAULT_EVENT_SOURCE
            event_source_detail_type = DEFAULT_EVENT_DETAIL_TYPE
            schema_root_name = sanitize_name(list(schemas.keys())[0])
            schemas_package_hierarchy = get_package_hierarchy(schema_name)
            if schemas.get("AWSEvent") is not None:
                aws_event = schemas.get("AWSEvent")
                if aws_event.get("x-amazon-events-source") is not None:
                    event_source = aws_event.get("x-amazon-events-source")
                if aws_event.get("x-amazon-events-detail-type") is not None:
                    event_source_detail_type = aws_event.get("x-amazon-events-detail-type")
                possible_root_schema_name = aws_event["properties"]["detail"]["$ref"]
                schema_root_name = sanitize_name(possible_root_schema_name[len("#/components/schemas/") :])
            return {
                "event_source": event_source,
                "event_source_detail_type": event_source_detail_type,
                "schema_root_name": schema_root_name,
                "schemas_package_hierarchy": schemas_package_hierarchy,
            }

        except JSONDecodeError:
            raise SchemasApiException(
                "Parse error reading the content from Schemas response. This should not be possible, please raise an issue."
            )
示例#5
0
    def get_schema_metadata(self, registry_name, schema_name):
        """
        Calls schemas service to get schema metadata.

        Parameters
        ----------
        registry_name:
            Registry Name
        schema_name:
            Schema Name

        Returns
        -------
        Schema metadata
        """
        try:
            describe_schema_response = self._schemas_client.describe_schema(
                RegistryName=registry_name, SchemaName=schema_name)
        except EndpointConnectionError as ex:
            raise NotAvailableInRegion(
                SCHEMAS_NOT_AVAILABLE_IN_REGION_ERROR) from ex
        try:
            content = json.loads(describe_schema_response["Content"])
            schemas = content["components"]["schemas"]
            # setting default values
            event_source = DEFAULT_EVENT_SOURCE
            event_source_detail_type = DEFAULT_EVENT_DETAIL_TYPE
            schema_root_name = sanitize_name(list(schemas.keys())[0])
            schemas_package_hierarchy = get_package_hierarchy(schema_name)
            if schemas.get("AWSEvent") is not None:
                aws_event = schemas.get("AWSEvent")
                if aws_event.get("x-amazon-events-source") is not None:
                    event_source = aws_event.get("x-amazon-events-source")
                if aws_event.get("x-amazon-events-detail-type") is not None:
                    event_source_detail_type = aws_event.get(
                        "x-amazon-events-detail-type")
                possible_root_schema_name = aws_event["properties"]["detail"][
                    "$ref"]
                schema_root_name = sanitize_name(
                    possible_root_schema_name[len("#/components/schemas/"):])
            return {
                "event_source": event_source,
                "event_source_detail_type": event_source_detail_type,
                "schema_root_name": schema_root_name,
                "schemas_package_hierarchy": schemas_package_hierarchy,
            }

        except JSONDecodeError as ex:
            raise SchemasApiException(
                "Parse error reading the content from Schemas response. This should not be possible, please raise an issue."
            ) from ex
示例#6
0
 def test_get_package_hierarchy_for_discovered_event(self):
     self.assertEqual("schema.order.neworder",
                      get_package_hierarchy("order@NewOrder"))