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:
parent
6f7497e764
commit
9e479d559b
|
@ -258,11 +258,11 @@ class TestNotificationValidation(unittest.TestCase):
|
|||
self.fail("shouldn't happen")
|
||||
|
||||
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:
|
||||
schemas_notifications.parse_and_validate(notification, valid_periods)
|
||||
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):
|
||||
notification = {"name": "MyEmail", "type": "EMAIL", "address": "name@domain.com", "period": "60"}
|
||||
|
|
|
@ -12,9 +12,9 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import monasca_api.v2.common.validation as validation
|
||||
from oslo_log import log
|
||||
import six.moves.urllib.parse as urlparse
|
||||
from validate_email import validate_email
|
||||
from voluptuous import All
|
||||
from voluptuous import Any
|
||||
from voluptuous import Length
|
||||
|
@ -64,7 +64,7 @@ def parse_and_validate(msg, valid_periods, require_all=False):
|
|||
|
||||
|
||||
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))
|
||||
|
||||
|
||||
|
|
|
@ -30,6 +30,8 @@ VALUE_META_MAX_LENGTH = 2048
|
|||
|
||||
VALUE_META_NAME_MAX_LENGTH = 255
|
||||
|
||||
EMAIL_PATTERN = '^.+@.+$'
|
||||
|
||||
|
||||
def metric_name(name):
|
||||
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:
|
||||
raise HTTPUnprocessableEntityError("Unprocessable Entity",
|
||||
"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
|
||||
kafka-python>=0.9.5,<1.0.0
|
||||
simplejson
|
||||
validate_email>=1.3
|
||||
monasca-common>=0.0.2
|
||||
sqlalchemy
|
||||
|
|
Loading…
Reference in New Issue