Updated entrypoint.sh to utilize the email-validator package for email validation. #7297

This commit is contained in:
Pravesh Sharma 2024-07-18 11:05:37 +05:30 committed by GitHub
parent c9cc5257c7
commit a75273a714
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 17 additions and 5 deletions

View File

@ -43,10 +43,19 @@ if [ ! -f /var/lib/pgadmin/pgadmin4.db ]; then
exit 1 exit 1
fi fi
if ! echo "${PGADMIN_DEFAULT_EMAIL}" | grep -E "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$" > /dev/null; then # Validate PGADMIN_DEFAULT_EMAIL
CHECK_EMAIL_DELIVERABILITY="False"
if [ -n "${PGADMIN_CONFIG_CHECK_EMAIL_DELIVERABILITY}" ]; then
CHECK_EMAIL_DELIVERABILITY=${PGADMIN_CONFIG_CHECK_EMAIL_DELIVERABILITY}
fi
is_valid_email=$(cd /pgadmin4/pgadmin/utils && /venv/bin/python3 -c "from validation_utils import validate_email; val = validate_email('${PGADMIN_DEFAULT_EMAIL}', ${CHECK_EMAIL_DELIVERABILITY}); print(val)")
if echo "${is_valid_email}" | grep "False" > /dev/null; then
echo "'${PGADMIN_DEFAULT_EMAIL}' does not appear to be a valid email address. Please reset the PGADMIN_DEFAULT_EMAIL environment variable and try again." echo "'${PGADMIN_DEFAULT_EMAIL}' does not appear to be a valid email address. Please reset the PGADMIN_DEFAULT_EMAIL environment variable and try again."
exit 1 exit 1
fi fi
# Switch back to root directory for further process
cd /pgadmin4
# Read secret contents # Read secret contents
if [ -n "${PGADMIN_DEFAULT_PASSWORD_FILE}" ]; then if [ -n "${PGADMIN_DEFAULT_PASSWORD_FILE}" ]; then

View File

@ -35,7 +35,7 @@ from .typecast import register_global_typecasters,\
register_string_typecasters, register_binary_typecasters, \ register_string_typecasters, register_binary_typecasters, \
register_array_to_string_typecasters, ALL_JSON_TYPES register_array_to_string_typecasters, ALL_JSON_TYPES
from .encoding import get_encoding, configure_driver_encodings from .encoding import get_encoding, configure_driver_encodings
from pgadmin.utils import csv from pgadmin.utils import csv_lib as csv
from pgadmin.utils.master_password import get_crypt_key from pgadmin.utils.master_password import get_crypt_key
from io import StringIO from io import StringIO
from pgadmin.utils.locker import ConnectionLocker from pgadmin.utils.locker import ConnectionLocker

View File

@ -9,14 +9,17 @@
from email_validator import validate_email as email_validate, \ from email_validator import validate_email as email_validate, \
EmailNotValidError EmailNotValidError
import config
def validate_email(email): def validate_email(email, check_email_deliverability=None):
try: try:
if check_email_deliverability is None:
import config
check_email_deliverability = config.CHECK_EMAIL_DELIVERABILITY
# Validate. # Validate.
_ = email_validate( _ = email_validate(
email, check_deliverability=config.CHECK_EMAIL_DELIVERABILITY) email, check_deliverability=check_email_deliverability)
# Update with the normalized form. # Update with the normalized form.
return True return True