mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Start building validation toolset
This commit is contained in:
parent
007e131a55
commit
01eb5f504c
@ -14,7 +14,7 @@ The following packages are required packages for this module:
|
||||
import logging
|
||||
|
||||
# Import salt libs
|
||||
import salt.utils
|
||||
import salt.utils.validate.net
|
||||
from salt.exceptions import CommandExecutionError
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@ -193,7 +193,7 @@ def block(bdaddr):
|
||||
|
||||
salt '*' bluetooth.block DE:AD:BE:EF:CA:FE
|
||||
'''
|
||||
if not salt.utils.valid_mac(bdaddr):
|
||||
if not salt.utils.validate.net.mac(bdaddr):
|
||||
raise CommandExecutionError(
|
||||
'Invalid BD address passed to bluetooth.block'
|
||||
)
|
||||
@ -212,7 +212,7 @@ def unblock(bdaddr):
|
||||
|
||||
salt '*' bluetooth.unblock DE:AD:BE:EF:CA:FE
|
||||
'''
|
||||
if not salt.utils.valid_mac(bdaddr):
|
||||
if not salt.utils.validate.net.mac(bdaddr):
|
||||
raise CommandExecutionError(
|
||||
'Invalid BD address passed to bluetooth.unblock'
|
||||
)
|
||||
@ -237,7 +237,7 @@ def pair(address, key):
|
||||
TODO: This function is currently broken, as the bluez-simple-agent program
|
||||
no longer ships with BlueZ >= 5.0. It needs to be refactored.
|
||||
'''
|
||||
if not salt.utils.valid_mac(address):
|
||||
if not salt.utils.validate.net.mac(address):
|
||||
raise CommandExecutionError(
|
||||
'Invalid BD address passed to bluetooth.pair'
|
||||
)
|
||||
@ -272,7 +272,7 @@ def unpair(address):
|
||||
TODO: This function is currently broken, as the bluez-simple-agent program
|
||||
no longer ships with BlueZ >= 5.0. It needs to be refactored.
|
||||
'''
|
||||
if not salt.utils.valid_mac(address):
|
||||
if not salt.utils.validate.net.mac(address):
|
||||
raise CommandExecutionError(
|
||||
'Invalid BD address passed to bluetooth.unpair'
|
||||
)
|
||||
|
@ -1753,17 +1753,3 @@ def is_bin_str(data):
|
||||
if len(text) / len(data) > 0.30:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def valid_mac(mac):
|
||||
'''
|
||||
Validates a mac address
|
||||
'''
|
||||
valid = re.compile(r'''
|
||||
(^([0-9A-F]{2}[-]){5}([0-9A-F]{2})$
|
||||
|^([0-9A-F]{2}[:]){5}([0-9A-F]{2})$)
|
||||
''',
|
||||
re.VERBOSE|re.IGNORECASE)
|
||||
if valid.match(mac) is None:
|
||||
return False
|
||||
return True
|
||||
|
0
salt/utils/validate/__init__.py
Normal file
0
salt/utils/validate/__init__.py
Normal file
19
salt/utils/validate/net.py
Normal file
19
salt/utils/validate/net.py
Normal file
@ -0,0 +1,19 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Various network validation utilities
|
||||
'''
|
||||
|
||||
import re
|
||||
|
||||
def mac(mac):
|
||||
'''
|
||||
Validates a mac address
|
||||
'''
|
||||
valid = re.compile(r'''
|
||||
(^([0-9A-F]{2}[-]){5}([0-9A-F]{2})$
|
||||
|^([0-9A-F]{2}[:]){5}([0-9A-F]{2})$)
|
||||
''',
|
||||
re.VERBOSE|re.IGNORECASE)
|
||||
if valid.match(mac) is None:
|
||||
return False
|
||||
return True
|
Loading…
Reference in New Issue
Block a user