Пример #1
0
def validate_node_address(address: str):
    if isinstance(address, str) and len(address) == 42:
        prefix, body = _split_icon_address(address)
        if prefix != 'hx' or not _is_lowercase_hex_string(body):
            raise InvalidFormatException("Invalid hx Address")
    else:
        raise InvalidFormatException("Invalid hx Address")
Пример #2
0
def validate_port(port: str, validating_field: str):
    try:
        port = int(port, 10)
    except ValueError:
        raise InvalidFormatException(f'Invalid {validating_field} format. port: "{port}"')

    if not 0 < port < 65536:
        raise InvalidFormatException(f"Invalid {validating_field} format. Port out of range: {port}")
Пример #3
0
def validate_p2p_endpoint(p2p_endpoint: str):
    network_locate_info = p2p_endpoint.split(":")

    if len(network_locate_info) != 2:
        raise InvalidFormatException("Invalid endpoint format. endpoint must have port info")

    validate_port(network_locate_info[1], ConstantKeys.P2P_ENDPOINT)

    if ENDPOINT_IP_PATTERN.match(p2p_endpoint):
        return

    if not ENDPOINT_DOMAIN_NAME_PATTERN.match(p2p_endpoint.lower()):
        raise InvalidFormatException("Invalid endpoint format")
Пример #4
0
def validate_prep_data(data: dict, blank_able: bool = False):
    if not blank_able:

        for key in fields_to_validate:
            if key not in data:
                raise InvalidFormatException(f'"{key}" not found')
            elif len(data[key].strip()) < 1:
                raise InvalidFormatException("Can not set empty data")

    for key in data:
        if len(data[key].strip()) < 1 and not blank_able:
            raise InvalidFormatException("Can not set empty data")

        validate_field_in_prep_data(key, data[key])
Пример #5
0
def _check_keystore(password: str):
    if not password:
        password = getpass.getpass("Input your keystore password: "******"Retype your keystore password: "******"Sorry, passwords do not match. Failed to make keystore file")

    if not validate_password(password):
        raise InvalidFormatException(
            "Password must be at least 8 characters long including alphabet, number, "
            "and special character.")
    return password
Пример #6
0
def validate_uri(uri: str):
    uri = uri.lower()
    if WEBSITE_DOMAIN_NAME_PATTERN.match(uri):
        return
    if WEBSITE_IP_PATTERN.match(uri):
        return

    raise InvalidFormatException("Invalid uri format")
Пример #7
0
def validate_field_in_prep_data(key: str, value: str):

    if not validate_field_key(key):
        raise InvalidFormatException(f"Invalid key : {key}")

    if key == ConstantKeys.P2P_ENDPOINT:
        validate_p2p_endpoint(value)
    elif key in (ConstantKeys.WEBSITE, ConstantKeys.DETAILS):
        validate_uri(value)
    elif key == ConstantKeys.EMAIL:
        validate_email(value)
    elif key == ConstantKeys.COUNTRY:
        validate_country(value)
Пример #8
0
def validate_country(country_code: str):
    if country_code.upper() not in iso3166.countries_by_alpha3:
        raise InvalidFormatException("Invalid alpha-3 country code")
Пример #9
0
def validate_email(email: str):
    if not EMAIL_PATTERN.match(email):
        raise InvalidFormatException("Invalid email format")