当前位置: 首页>>代码示例>>Python>>正文


Python ValidationException.add方法代码示例

本文整理汇总了Python中task.ValidationException.add方法的典型用法代码示例。如果您正苦于以下问题:Python ValidationException.add方法的具体用法?Python ValidationException.add怎么用?Python ValidationException.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在task.ValidationException的用法示例。


在下文中一共展示了ValidationException.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: verify

# 需要导入模块: from task import ValidationException [as 别名]
# 或者: from task.ValidationException import add [as 别名]
    def verify(self, certificate):

        if self.datastore.exists('crypto.certificates', ('name', '=', certificate['name'])):
            raise VerifyException(errno.EEXIST, 'Certificate with given name already exists')

        if certificate['type'] not in ('CERT_EXISTING', 'CA_EXISTING'):
            raise VerifyException(errno.EINVAL, 'Invalid certificate type')

        errors = ValidationException()
        for i in ('country', 'state', 'city', 'organization', 'email', 'common'):
            if i in certificate:
                errors.add((0, i), '{0} is not valid in certificate import'.format(i))
        if errors:
            raise errors

        if certificate['type'] == 'CERT_EXISTING' and (
            'privatekey' not in certificate or
            'passphrase' not in certificate
        ):
            raise VerifyException(
                errno.EINVAL, 'privatekey and passphrase required to import certificate'
            )

        try:
            if 'privatekey' in certificate:
                load_privatekey(certificate['privatekey'], certificate.get('passphrase'))
        except Exception:
            raise VerifyException(errno.EINVAL, 'Invalid passphrase')

        return ['system']
开发者ID:jatinder-kumar-calsoft,项目名称:middleware,代码行数:32,代码来源:CryptoPlugin.py

示例2: verify

# 需要导入模块: from task import ValidationException [as 别名]
# 或者: from task.ValidationException import add [as 别名]
    def verify(self, smb):
        errors = ValidationException()
        node = ConfigNode('service.smb', self.configstore).__getstate__()

        netbiosname = smb.get('netbiosname')
        if netbiosname is not None:
            for n in netbiosname:
                if not validate_netbios_name(n):
                    errors.add((0, 'netbiosname'), 'Invalid name {0}'.format(n))
        else:
            netbiosname = node['netbiosname']

        workgroup = smb.get('workgroup')
        if workgroup is not None:
            if not validate_netbios_name(workgroup):
                errors.add((0, 'workgroup'), 'Invalid name')
        else:
            workgroup = node['workgroup']

        if workgroup.lower() in [i.lower() for i in netbiosname]:
            errors.add((0, 'netbiosname'), 'NetBIOS and Workgroup must be unique')

        dirmask = smb.get('dirmask')
        if dirmask and (int(dirmask, 8) & ~0o11777):
            errors.add((0, 'dirmask'), 'This is not a valid mask')

        filemask = smb.get('filemask')
        if filemask and (int(filemask, 8) & ~0o11777):
            errors.add((0, 'filemask'), 'This is not a valid mask')

        if errors:
            raise errors

        return ['system']
开发者ID:jatinder-kumar-calsoft,项目名称:middleware,代码行数:36,代码来源:SMBPlugin.py

示例3: verify

# 需要导入模块: from task import ValidationException [as 别名]
# 或者: from task.ValidationException import add [as 别名]
    def verify(self, id, updated_fields):
        errors = ValidationException()
        normalize_name(updated_fields, 'username')

        if updated_fields.get('full_name') and ':' in updated_fields['full_name']:
            errors.add((1, 'full_name'), 'The character ":" is not allowed')

        if 'groups' in updated_fields and len(updated_fields['groups']) > 64:
            errors.add((1, 'groups'), 'User cannot belong to more than 64 auxiliary groups')

        if 'username' in updated_fields:
            for code, message in check_unixname(updated_fields['username']):
                errors.add((1, 'username'), message, code=code)

        if updated_fields.get('email'):
            if not EMAIL_REGEX.match(updated_fields['email']):
                errors.add(
                    (1, 'email'),
                    "{0} is an invalid email address".format(updated_fields['email'])
                )

        if 'home' in updated_fields and updated_fields['home'] not in (None, '/nonexistent'):
            volumes_root = self.dispatcher.call_sync('volume.get_volumes_root')
            updated_fields['home'] = os.path.normpath(updated_fields['home'])
            if not updated_fields['home'].startswith(volumes_root) or updated_fields['home'] == volumes_root:
                errors.add(
                    (1, 'home directory'),
                    "Invalid mountpoint specified for home directory: {0}.\n".format(updated_fields['home']) +
                    "Provide a path within zfs pool or dataset mounted under {0}".format(volumes_root)
                )

        if errors:
            raise errors

        return ['system']
开发者ID:freenas,项目名称:middleware,代码行数:37,代码来源:UserPlugin.py

示例4: verify

# 需要导入模块: from task import ValidationException [as 别名]
# 或者: from task.ValidationException import add [as 别名]
 def verify(self, path, logs=True, cores=False):
     errors = ValidationException()
     if path in [None, ''] or path.isspace():
         errors.add((0, 'path'), 'The Path is required', code=errno.EINVAL)
     if errors:
         raise errors
     return []
开发者ID:erinix,项目名称:middleware,代码行数:9,代码来源:DebugPlugin.py

示例5: verify

# 需要导入模块: from task import ValidationException [as 别名]
# 或者: from task.ValidationException import add [as 别名]
    def verify(self, id, updated_fields):

        tunable = self.datastore.get_by_id('tunables', id)
        if tunable is None:
            raise VerifyException(errno.ENOENT, 'Tunable with given ID does not exist')

        errors = ValidationException()

        if 'var' in updated_fields and self.datastore.exists(
            'tunables', ('and', [('var', '=', updated_fields['var']), ('id', '!=', id)])
        ):
            errors.add((1, 'var'), 'This variable already exists.', code=errno.EEXIST)

        if 'value' in updated_fields and '"' in updated_fields['value'] or "'" in updated_fields['value']:
            errors.add((1, 'value'), 'Quotes are not allowed')

        if 'type' in updated_fields:
            if updated_fields['type'] in ('LOADER', 'RC') and not VAR_LOADER_RC_RE.match(tunable['var']):
                errors.add((1, 'var'), VAR_SYSCTL_FORMAT)
            elif updated_fields['type'] == 'SYSCTL':
                if not VAR_SYSCTL_RE.match(tunable['var']):
                    errors.add((1, 'var'), VAR_LOADER_RC_FORMAT)
                try:
                    sysctl.sysctlnametomib(tunable['var'])
                except OSError:
                    errors.add((1, 'var'), 'Sysctl variable does not exist')

        if errors:
            raise errors

        return ['system']
开发者ID:jatinder-kumar-calsoft,项目名称:middleware,代码行数:33,代码来源:TunablePlugin.py

示例6: verify

# 需要导入模块: from task import ValidationException [as 别名]
# 或者: from task.ValidationException import add [as 别名]
 def verify(self, path):
     errors = ValidationException()
     if path in [None, ''] or path.isspace():
         errors.add((0, 'path'), 'The Path is required', code=errno.EINVAL)
     if errors:
         raise errors
     return ['system']
开发者ID:freenas,项目名称:middleware,代码行数:9,代码来源:DebugPlugin.py

示例7: verify

# 需要导入模块: from task import ValidationException [as 别名]
# 或者: from task.ValidationException import add [as 别名]
    def verify(self, rsyncmod):
        errors = ValidationException()

        if re.search(r'[/\]]', rsyncmod['name']):
            errors.add((0, 'name'), 'The name cannot contain slash or a closing square backet.')

        if errors:
            raise errors

        return ['system']
开发者ID:freenas,项目名称:middleware,代码行数:12,代码来源:RsyncdPlugin.py

示例8: verify

# 需要导入模块: from task import ValidationException [as 别名]
# 或者: from task.ValidationException import add [as 别名]
    def verify(self, ipfs):
        errors = ValidationException()

        if 'path' in ipfs:
            if ipfs['path'] in [None, ''] or ipfs['path'].isspace():
                errors.add((0, path), "The provided path: '{0}' is not valid".format(ipfs['path']))

        if errors:
            raise errors

        return ['system']
开发者ID:650elx,项目名称:middleware,代码行数:13,代码来源:IPFSPlugin.py

示例9: verify

# 需要导入模块: from task import ValidationException [as 别名]
# 或者: from task.ValidationException import add [as 别名]
    def verify(self, props):
        errors = ValidationException()
        if 'timezone' in props:
            timezones = self.dispatcher.call_sync('system.general.timezones')
            if props['timezone'] not in timezones:
                errors.add((0, 'timezone'), 'Invalid timezone: {0}'.format(props['timezone']))

        if errors:
            raise errors

        return ['system']
开发者ID:jatinder-kumar-calsoft,项目名称:middleware,代码行数:13,代码来源:SystemInfoPlugin.py

示例10: verify

# 需要导入模块: from task import ValidationException [as 别名]
# 或者: from task.ValidationException import add [as 别名]
    def verify(self, afp):

        errors = ValidationException()
        dbpath = afp.get('dbpath')
        if dbpath:
            if not os.path.exists(dbpath):
                errors.add((0, 'dbpath'), 'Path does not exist', code=errno.ENOENT)
            elif not os.path.isdir(dbpath):
                errors.add((0, 'dbpath'), 'Path is not a directory')

        if errors:
            raise errors

        return ['system']
开发者ID:650elx,项目名称:middleware,代码行数:16,代码来源:AFPPlugin.py

示例11: verify

# 需要导入模块: from task import ValidationException [as 别名]
# 或者: from task.ValidationException import add [as 别名]
    def verify(self, user):
        errors = ValidationException()
        normalize_name(user, 'username')

        for code, message in check_unixname(user['username']):
            errors.add((0, 'username'), message, code=code)

        if self.datastore.exists('users', ('username', '=', user['username'])):
            raise VerifyException(errno.EEXIST, 'User with given name already exists')

        if 'groups' in user and len(user['groups']) > 64:
            errors.add(
                (0, 'groups'),
                'User cannot belong to more than 64 auxiliary groups'
            )

        if user.get('full_name') and ':' in user['full_name']:
            errors.add((0, 'full_name'), 'The character ":" is not allowed')

        if 'email' in user:
            if not EMAIL_REGEX.match(user['email']):
                errors.add(
                    (0, 'email'),
                    "{0} is an invalid email address".format(user['email'])
                )

        if errors:
            raise errors

        return ['system']
开发者ID:abwaters,项目名称:middleware,代码行数:32,代码来源:UserPlugin.py

示例12: verify

# 需要导入模块: from task import ValidationException [as 别名]
# 或者: from task.ValidationException import add [as 别名]
    def verify(self, lldp):
        errors = ValidationException()
        node = ConfigNode('service.lldp', self.configstore).__getstate__()
        node.update(lldp)

        # Lazy load pycountry due to extra verbose DEBUG logging
        import pycountry
        if node['country_code'] and node['country_code'] not in pycountry.countries.indices['alpha2']:
            errors.add((0, 'country_code'), 'Invalid ISO-3166 alpha 2 code')

        if errors:
            raise errors

        return ['system']
开发者ID:jatinder-kumar-calsoft,项目名称:middleware,代码行数:16,代码来源:LLDPPlugin.py

示例13: verify

# 需要导入模块: from task import ValidationException [as 别名]
# 或者: from task.ValidationException import add [as 别名]
    def verify(self, mail):
        errors = ValidationException()
        node = ConfigNode("mail", self.configstore).__getstate__()

        if mail.get("auth"):
            if not mail.get("user") and not node["user"]:
                errors.add((0, "auth"), "Mail authorization requires a username")
            if not mail.get("pass") and not node["pass"]:
                errors.add((0, "auth"), "Mail authorization requires a password")

        if errors:
            raise errors

        return []
开发者ID:freenas,项目名称:middleware,代码行数:16,代码来源:MailPlugin.py

示例14: verify

# 需要导入模块: from task import ValidationException [as 别名]
# 或者: from task.ValidationException import add [as 别名]
    def verify(self, id, updated_fields):

        errors = ValidationException()

        if 'var' in updated_fields and self.datastore.exists(
            'tunables', ('and', [('var', '=', updated_fields['var']), ('id', '!=', id)])
        ):
            errors.add((1, 'var'), 'This variable already exists.', code=errno.EEXIST)

        if 'value' in updated_fields:
            if '"' in updated_fields['value'] or "'" in updated_fields['value']:
                errors.add((1, 'value'), 'Quotes are not allowed')

        if errors:
            raise errors

        return ['system']
开发者ID:erinix,项目名称:middleware,代码行数:19,代码来源:TunablePlugin.py

示例15: verify

# 需要导入模块: from task import ValidationException [as 别名]
# 或者: from task.ValidationException import add [as 别名]
    def verify(self, uuid, updated_fields):

        rsyncmod = self.datastore.get_by_id('rsyncd-module', uuid)
        if rsyncmod is None:
            raise VerifyException(errno.ENOENT, 'Rsync module {0} does not exist'.format(uuid))

        rsyncmod.update(updated_fields)

        errors = ValidationException()

        if re.search(r'[/\]]', rsyncmod['name']):
            errors.add((1, 'name'), 'The name cannot contain slash or a closing square backet.')

        if errors:
            raise errors

        return ['system']
开发者ID:jatinder-kumar-calsoft,项目名称:middleware,代码行数:19,代码来源:RsyncdPlugin.py


注:本文中的task.ValidationException.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。