How to use the validators.uuid function in validators

To help you get started, we’ve selected a few validators examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kvesteri / validators / tests / test_uuid.py View on Github external
def test_returns_true_on_valid_mac_address(value):
    assert uuid(value)
github rapid7 / lecli / lecli / api_utils.py View on Github external
def get_named_logkey(name):
    """
    Get named log-key from the config file.

    :param name: name of the log key
    """

    section = 'LogNicknames'

    try:
        named_logkeys = dict(CONFIG.items(section))
        name = name.lower()
        if name in named_logkeys:
            logkey = (named_logkeys[name],)
            if not validators.uuid(logkey[0]):
                print_config_error_and_exit(section, 'Named Logkey(%s)' % name, logkey)
            else:
                return logkey
        else:
            print_config_error_and_exit(section, 'Named Logkey(%s)' % name)
    except ConfigParser.NoSectionError:
        print_config_error_and_exit(section)
github rapid7 / lecli / lecli / api_utils.py View on Github external
def get_named_logkey_group(name):
    """
    Get named log-key group from the config file.

    :param name: name of the group
    """

    section = 'LogGroups'
    try:
        groups = dict(CONFIG.items(section))
        name = name.lower()
        if name in groups:
            logkeys = [line for line in str(groups[name]).splitlines() if line is not None]
            for logkey in logkeys:
                if not validators.uuid(logkey):
                    print_config_error_and_exit(section, 'Named Logkey Group(%s)' % name, logkey)
            return logkeys
        else:
            print_config_error_and_exit(section, 'Named Logkey Group(%s)' % name)
    except ConfigParser.NoSectionError:
        print_config_error_and_exit(section)
github rapid7 / lecli / lecli / api_utils.py View on Github external
def get_account_resource_id():
    """
    Get account resource id from the config file.
    """

    config_key = 'account_resource_id'
    try:
        account_resource_id = CONFIG.get(AUTH_SECTION, config_key)
        if not validators.uuid(account_resource_id):
            print_config_error_and_exit(AUTH_SECTION, 'Account Resource ID(%s)' % config_key,
                                        account_resource_id)
            return
        else:
            return account_resource_id
    except ConfigParser.NoOptionError:
        print_config_error_and_exit(AUTH_SECTION, 'Account Resource ID(%s)' % config_key)
github rapid7 / lecli / lecli / api_utils.py View on Github external
def get_rw_apikey():
    """
    Get read-write api key from the config file.
    """

    config_key = 'rw_api_key'
    try:
        rw_api_key = CONFIG.get(AUTH_SECTION, config_key)
        if not validators.uuid(rw_api_key):
            print_config_error_and_exit(AUTH_SECTION, 'Read/Write API key(%s)' % config_key,
                                        rw_api_key)
        else:
            return rw_api_key
    except ConfigParser.NoOptionError:
        print_config_error_and_exit(AUTH_SECTION, 'Read/Write API key(%s)' % config_key)
github rapid7 / lecli / lecli / api_utils.py View on Github external
def get_owner_apikey():
    """
    Get owner api key from the config file.
    """

    config_key = 'owner_api_key'
    try:
        owner_api_key = CONFIG.get(AUTH_SECTION, config_key)
        if not validators.uuid(owner_api_key):
            print_config_error_and_exit(AUTH_SECTION, 'Owner API key(%s)' % config_key,
                                        owner_api_key)
            return
        else:
            return owner_api_key
    except ConfigParser.NoOptionError:
        print_config_error_and_exit(AUTH_SECTION, 'Owner API key(%s)' % config_key)
github rapid7 / lecli / lecli / api_utils.py View on Github external
def get_ro_apikey():
    """
    Get read-only api key from the config file.
    """

    config_key = 'ro_api_key'
    try:
        ro_api_key = CONFIG.get(AUTH_SECTION, config_key)
        if not validators.uuid(ro_api_key):
            return get_rw_apikey()
        else:
            return ro_api_key
    except ConfigParser.NoOptionError:
        # because read-write api key is a superset of read-only api key
        return get_rw_apikey()
github rapid7 / insightconnect-plugins / microsoft_intune / icon_microsoft_intune / util / api.py View on Github external
def search_managed_devices(self, device):
        if validators.uuid(device):
            return list(filter(lambda iter_device: iter_device['userId'] == device or iter_device['id'] == device,
                               self._call_api("GET", f"deviceManagement/managedDevices")["value"]))
        elif validators.email(device):
            filtering_params = ['emailAddress']
        else:
            filtering_params = ['deviceName']
        filtering_params = " or ".join(map(lambda param: f"{param} eq '{device}'", filtering_params))

        return self._call_api("GET", f"deviceManagement/managedDevices?$filter={filtering_params}")["value"]