def validate(config):
    '''
    Validate the beacon configuration
    '''
    vstatus = True
    vmsg = 'Valid beacon configuration'

    # Configuration for wtmp beacon should be a list of dicts
    if not isinstance(config, list):
        vstatus = False
        vmsg = ('Configuration for wtmp beacon must be a list.')
    else:
        _config = {}
        list(map(_config.update, config))

        if 'users' in _config:
            if not isinstance(_config['users'], dict):
                vstatus = False
                vmsg = ('User configuration for wtmp beacon must '
                        'be a dictionary.')
            else:
                for user in _config['users']:
                    _time_range = _config['users'][user].get('time_range', {})
                    vstatus, vmsg = _validate_time_range(_time_range,
                                                         vstatus,
                                                         vmsg)

            if not vstatus:
                return vstatus, vmsg

        if 'groups' in _config:
            if not isinstance(_config['groups'], dict):
                vstatus = False
                vmsg = ('Group configuration for wtmp beacon must '
                        'be a dictionary.')
            else:
                for group in _config['groups']:
                    _time_range = _config['groups'][group].get('time_range', {})
                    vstatus, vmsg = _validate_time_range(_time_range,
                                                         vstatus,
                                                         vmsg)
            if not vstatus:
                return vstatus, vmsg

        if 'defaults' in _config:
            if not isinstance(_config['defaults'], dict):
                vstatus = False
                vmsg = ('Defaults configuration for wtmp beacon must '
                        'be a dictionary.')
            else:
                _time_range = _config['defaults'].get('time_range', {})
                vstatus, vmsg = _validate_time_range(_time_range,
                                                     vstatus,
                                                     vmsg)
            if not vstatus:
                return vstatus, vmsg

    return vstatus, vmsg
def validate ( config ) : vstatus = True vmsg = 'Valid beacon configuration' if not isinstance ( config , list ) : vstatus = False vmsg = ( 'Configuration for wtmp beacon must be a list.' ) else : _config = { } list ( map ( _config . update , config ) ) if 'users' in _config : if not isinstance ( _config [ 'users' ] , dict ) : vstatus = False vmsg = ( 'User configuration for wtmp beacon must ' 'be a dictionary.' ) else : for user in _config [ 'users' ] : _time_range = _config [ 'users' ] [ user ] . get ( 'time_range' , { } ) vstatus , vmsg = _validate_time_range ( _time_range , vstatus , vmsg ) if not vstatus : return vstatus , vmsg if 'groups' in _config : if not isinstance ( _config [ 'groups' ] , dict ) : vstatus = False vmsg = ( 'Group configuration for wtmp beacon must ' 'be a dictionary.' ) else : for group in _config [ 'groups' ] : _time_range = _config [ 'groups' ] [ group ] . get ( 'time_range' , { } ) vstatus , vmsg = _validate_time_range ( _time_range , vstatus , vmsg ) if not vstatus : return vstatus , vmsg if 'defaults' in _config : if not isinstance ( _config [ 'defaults' ] , dict ) : vstatus = False vmsg = ( 'Defaults configuration for wtmp beacon must ' 'be a dictionary.' ) else : _time_range = _config [ 'defaults' ] . get ( 'time_range' , { } ) vstatus , vmsg = _validate_time_range ( _time_range , vstatus , vmsg ) if not vstatus : return vstatus , vmsg return vstatus , vmsg
Validate the beacon configuration