Exemple #1
0
    def validate(cls, urn_str: str) -> None:
        """
        Validate if a string is in valid Urn format
        :param urn_str: to be validated urn string
        :raises InvalidUrnError if the string representation is in invalid format
        """
        parts: List[str] = urn_str.split(":", 3)
        if len(parts) != 4:
            raise InvalidUrnError(
                f"Invalid urn string: {urn_str}. Expect 4 parts from urn string but found {len(parts)}"
            )

        if "" in parts:
            raise InvalidUrnError(
                f"Invalid urn string: {urn_str}. There should not be empty parts in urn string."
            )

        if parts[0] != Urn.URN_PREFIX:
            raise InvalidUrnError(
                f'Invalid urn string: {urn_str}. Expect urn starting with "urn" but found {parts[0]}'
            )

        if "" in cls._get_entity_id_from_str(parts[3]):
            raise InvalidUrnError(
                f"Invalid entity id in urn string: {urn_str}. There should not be empty parts in entity id."
            )

        cls._validate_entity_type(parts[2])
        cls._validate_entity_id(cls._get_entity_id_from_str(parts[3]))
Exemple #2
0
    def _validate_entity_id(entity_id: List[str]) -> None:
        # expected entity id format (<platform_urn>,<table_name>,<env>)
        if len(entity_id) != 3:
            raise InvalidUrnError(
                f"Expect 3 parts in the entity id but found {entity_id}")

        env = entity_id[2].upper()
        if env not in DataFlowUrn.VALID_FABRIC_SET:
            raise InvalidUrnError(
                f"Invalid env:{env}. Allowed evn are {DataFlowUrn.VALID_FABRIC_SET}"
            )
Exemple #3
0
    def _validate_entity_id(entity_id: List[str]) -> None:
        if len(entity_id) != 2:
            raise InvalidUrnError(
                f"Expect 2 part in entity id, but found{len(entity_id)}")

        data_flow_urn_str = entity_id[0]
        DataFlowUrn.validate(data_flow_urn_str)
Exemple #4
0
 def __init__(
     self, entity_type: str, entity_id: List[str], urn_domain: str = LI_DOMAIN
 ):
     if len(entity_id) == 0:
         raise InvalidUrnError("Empty entity id.")
     self._validate_entity_type(entity_type)
     self._validate_entity_id(entity_id)
     self._entity_type = entity_type
     self._domain = urn_domain
     self._entity_id = entity_id
Exemple #5
0
 def _validate_entity_id(entity_id: List[str]) -> None:
     if len(entity_id) != 1:
         raise InvalidUrnError(
             f"Expect 1 part in entity id, but found{len(entity_id)}")
Exemple #6
0
 def _validate_entity_type(entity_type: str) -> None:
     if entity_type != DomainUrn.ENTITY_TYPE:
         raise InvalidUrnError(
             f"Entity type should be {DomainUrn.ENTITY_TYPE} but found {entity_type}"
         )
 def _validate_entity_type(entity_type: str) -> None:
     if entity_type != DataProcessInstanceUrn.ENTITY_TYPE:
         raise InvalidUrnError(
             f"Entity type should be {DataProcessInstanceUrn.ENTITY_TYPE} but found {entity_type}"
         )