Small function for basic email address validation
This function only checks syntax ([]@[]) for the email address you put in for notification. Removing library validate-email to prevent further conflicts. Change-Id: I0567a71a15c5d051bf491630956296f1c6726569
This commit is contained in:
@@ -258,11 +258,11 @@ class TestNotificationValidation(unittest.TestCase):
|
|||||||
self.fail("shouldn't happen")
|
self.fail("shouldn't happen")
|
||||||
|
|
||||||
def test_validation_exception_for_invalid_email_address(self):
|
def test_validation_exception_for_invalid_email_address(self):
|
||||||
notification = {"name": "MyEmail", "type": "EMAIL", "address": "name@domain."}
|
notification = {"name": "MyEmail", "type": "EMAIL", "address": "name@"}
|
||||||
with self.assertRaises(schemas_exceptions.ValidationException) as ve:
|
with self.assertRaises(schemas_exceptions.ValidationException) as ve:
|
||||||
schemas_notifications.parse_and_validate(notification, valid_periods)
|
schemas_notifications.parse_and_validate(notification, valid_periods)
|
||||||
ex = ve.exception
|
ex = ve.exception
|
||||||
self.assertEqual("Address name@domain. is not of correct format", ex.message)
|
self.assertEqual("Address name@ is not of correct format", ex.message)
|
||||||
|
|
||||||
def test_validation_exception_for_invalid_period_for_email(self):
|
def test_validation_exception_for_invalid_period_for_email(self):
|
||||||
notification = {"name": "MyEmail", "type": "EMAIL", "address": "name@domain.com", "period": "60"}
|
notification = {"name": "MyEmail", "type": "EMAIL", "address": "name@domain.com", "period": "60"}
|
||||||
|
@@ -12,9 +12,9 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import monasca_api.v2.common.validation as validation
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
import six.moves.urllib.parse as urlparse
|
import six.moves.urllib.parse as urlparse
|
||||||
from validate_email import validate_email
|
|
||||||
from voluptuous import All
|
from voluptuous import All
|
||||||
from voluptuous import Any
|
from voluptuous import Any
|
||||||
from voluptuous import Length
|
from voluptuous import Length
|
||||||
@@ -64,7 +64,7 @@ def parse_and_validate(msg, valid_periods, require_all=False):
|
|||||||
|
|
||||||
|
|
||||||
def _validate_email(address):
|
def _validate_email(address):
|
||||||
if not validate_email(address):
|
if not validation.validate_email_address(address):
|
||||||
raise exceptions.ValidationException("Address {} is not of correct format".format(address))
|
raise exceptions.ValidationException("Address {} is not of correct format".format(address))
|
||||||
|
|
||||||
|
|
||||||
|
@@ -30,6 +30,8 @@ VALUE_META_MAX_LENGTH = 2048
|
|||||||
|
|
||||||
VALUE_META_NAME_MAX_LENGTH = 255
|
VALUE_META_NAME_MAX_LENGTH = 255
|
||||||
|
|
||||||
|
EMAIL_PATTERN = '^.+@.+$'
|
||||||
|
|
||||||
|
|
||||||
def metric_name(name):
|
def metric_name(name):
|
||||||
assert isinstance(name, (str, unicode)), "Metric name must be a string"
|
assert isinstance(name, (str, unicode)), "Metric name must be a string"
|
||||||
@@ -117,3 +119,10 @@ def validate_state_query(state_str):
|
|||||||
if state_str not in VALID_ALARM_STATES:
|
if state_str not in VALID_ALARM_STATES:
|
||||||
raise HTTPUnprocessableEntityError("Unprocessable Entity",
|
raise HTTPUnprocessableEntityError("Unprocessable Entity",
|
||||||
"state {} must be one of 'ALARM','OK','UNDETERMINED'".format(state_str))
|
"state {} must be one of 'ALARM','OK','UNDETERMINED'".format(state_str))
|
||||||
|
|
||||||
|
|
||||||
|
def validate_email_address(email):
|
||||||
|
if re.match(EMAIL_PATTERN, email) is None:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
@@ -18,6 +18,5 @@ influxdb
|
|||||||
eventlet
|
eventlet
|
||||||
kafka-python>=0.9.5,<1.0.0
|
kafka-python>=0.9.5,<1.0.0
|
||||||
simplejson
|
simplejson
|
||||||
validate_email>=1.3
|
|
||||||
monasca-common>=0.0.2
|
monasca-common>=0.0.2
|
||||||
sqlalchemy
|
sqlalchemy
|
||||||
|
Reference in New Issue
Block a user