Commit 254e1cd8 authored by Jason Frisvold's avatar Jason Frisvold
Browse files

- Add validation for fields

- Convert to int for appropriate fields
- TODO: Add validation for ip range
parent 4536b8bb
......@@ -110,7 +110,10 @@ class SkynetTimer(object):
@client_id.setter
def client_id(self, value):
self._client_id = value
if value == None:
self._client_id = None
else:
self._client_id = int(value)
@client_id.deleter
def client_id(self):
......@@ -122,7 +125,10 @@ class SkynetTimer(object):
@timer_id.setter
def timer_id(self, value):
self._timer_id = value
if value == None:
self._timer_id = None
else:
self._timer_id = int(value)
@timer_id.deleter
def timer_id(self):
......@@ -141,7 +147,7 @@ class SkynetTimer(object):
if (matches.group() == '*'):
self._minute = ['*'] # list(range(60))
else:
self._minute = value.split(',')
self._minute = [int(x) for x in value.split(',')]
else:
# [0-59]-[0-59]/[1-60] or */[1-60]
matches = re.match(r'^((([0-5]?[0-9])\-([0-5]?[0-9])|\*)'
......@@ -157,8 +163,7 @@ class SkynetTimer(object):
step = int(matches.group(5))
for x in range(start, end + 1, step):
self._minute.append(x)
self._minute = [int(x) for x in range(start, end + 1, step)]
else:
self._minute = [0]
......@@ -180,7 +185,7 @@ class SkynetTimer(object):
if (matches.group() == '*'):
self._hour = ['*'] # list(range(24))
else:
self._hour = value.split(',')
self._hour = [int (x) for x in value.split(',')]
else:
# [0-23]-[0-23]/[1-24] or */[1-24]
matches = re.match(r'^((([01]?[0-9]|2[0-3])\-'
......@@ -197,8 +202,7 @@ class SkynetTimer(object):
step = int(matches.group(5))
for x in range(start, end + 1, step):
self._hour.append(x)
self._hour = [int(x) for x in range(start, end + 1, step)]
else:
self._hour = [0]
......@@ -220,7 +224,7 @@ class SkynetTimer(object):
if (matches.group() == '*'):
self._day = ['*'] # list(range(1, 31 + 1))
else:
self._day = value.split(',')
self._day = [int(x) for x in value.split(',')]
else:
# [1-31]-[1-31]/[1-31] or */[1-31]
matches = re.match(r'^((([1-9]|[1-2][0-9]|3[01])\-'
......@@ -237,8 +241,7 @@ class SkynetTimer(object):
step = int(matches.group(5))
for x in range(start, end + 1, step):
self._day.append(x)
self._day = [int(x) for x in range(start, end + 1, step)]
else:
self._day = [0]
......@@ -259,7 +262,7 @@ class SkynetTimer(object):
if (matches.group() == '*'):
self._month = ['*'] # list(range(1, 12 + 1))
else:
self._month = value.split(',')
self._month = [int(x) for x in value.split(',')]
else:
# [1-12]-[1-12]/[1-12] or */[1-12]
matches = re.match(r'^((([1-9]|1[0-2])\-([1-9]|1[0-2])|\*)'
......@@ -275,8 +278,7 @@ class SkynetTimer(object):
step = int(matches.group(5))
for x in range(start, end + 1, step):
self._month.append(x)
self._month = [int(x) for x in range(start, end + 1, step)]
else:
self._month = [0]
......@@ -290,7 +292,10 @@ class SkynetTimer(object):
@override.setter
def override(self, value):
self._override = value
if value == True or value == 1:
self._override = True
else:
self._override = False
@override.deleter
def override(self):
......@@ -302,6 +307,7 @@ class SkynetTimer(object):
@ip_range.setter
def ip_range(self, value):
# TODO: This should validate the IP range (0-4294967295 for the IP and 0-32 for the CIDR)
self._ip_range = value
@ip_range.deleter
......@@ -326,7 +332,10 @@ class SkynetTimer(object):
@action.setter
def action(self, value):
self._action = value
if value in ['add', 'modify', 'delete']:
self._action = value
else:
raise ValueError('Invalid Option')
@action.deleter
def action(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment