def Validate(self, value, unused_key=None):
        """Validates a subnet."""
        if value is None:
            raise validation.MissingAttribute('subnet must be specified')
        if not isinstance(value, six_subset.string_types):
            raise validation.ValidationError(
                'subnet must be a string, not \'%r\'' % type(value))
        # If we're running on py3 and don't have access to the ipaddr module,
        # then the server will still do the validation on the IP address.
        if ipaddr:
            try:
                ipaddr.IPNetwork(value)
            except ValueError:
                raise validation.ValidationError(
                    '%s is not a valid IPv4 or IPv6 subnet' % value)

        # Extra validation check since ipaddr accepts quad-dotted subnet masks.
        parts = value.split('/')
        if len(parts) == 2 and not re.match('^[0-9]+$', parts[1]):
            raise validation.ValidationError(
                'Prefix length of subnet %s must be an '
                'integer (quad-dotted masks are not '
                'supported)' % value)

        return value
Exemple #2
0
 def Validate(self, value, key=None):
   """Validates a schedule."""
   if value is None:
     raise validation.MissingAttribute('schedule must be specified')
   if not isinstance(value, basestring):
     raise TypeError('schedule must be a string, not \'%r\''%type(value))
   try:
     groctimespecification.GrocTimeSpecification(value)
   except groc.GrocException, e:
     raise validation.ValidationError('schedule \'%s\' failed to parse: %s'%(
         value, e.args[0]))
Exemple #3
0
 def Validate(self, value):
   """Validates a subnet."""
   if value is None:
     raise validation.MissingAttribute('subnet must be specified')
   try:
     ipaddr.IP(value)
   except ValueError:
     raise validation.ValidationError('%s is not a valid IPv4 or IPv6 subnet' %
                                      value)
   else:
     return value
 def Validate(self, value, key=None):
   """Validates a schedule."""
   if value is None:
     raise validation.MissingAttribute('schedule must be specified')
   if not isinstance(value, six_subset.string_types):
     raise TypeError('schedule must be a string, not \'%r\''%type(value))
   # If we're running on py3 and don't have access to groctimespecification,
   # then the server will still do the validation on the schedule property.
   if groc and groctimespecification:
     try:
       groctimespecification.GrocTimeSpecification(value)
     except groc.GrocException as e:
       raise validation.ValidationError('schedule \'%s\' failed to parse: %s'%(
           value, e.args[0]))
   return value
Exemple #5
0
    def Validate(self, value, unused_key=None):
        """Validates an URL pattern."""
        if value is None:
            raise validation.MissingAttribute('url must be specified')
        if not isinstance(value, basestring):
            raise validation.ValidationError(
                'url must be a string, not \'%r\'' % type(value))

        url_holder = ParsedURL(value)
        if url_holder.host_exact:
            _ValidateMatch(_URL_HOST_EXACT_PATTERN_RE, url_holder.host,
                           'invalid host_pattern \'%s\'' % url_holder.host)

            _ValidateNotIpV4Address(url_holder.host)
        else:
            _ValidateMatch(
                _URL_HOST_SUFFIX_PATTERN_RE, url_holder.host_pattern,
                'invalid host_pattern \'%s\'' % url_holder.host_pattern)

        return value
Exemple #6
0
  def Validate(self, value, unused_key=None):
    """Validates a subnet."""
    if value is None:
      raise validation.MissingAttribute('subnet must be specified')
    if not isinstance(value, basestring):
      raise validation.ValidationError('subnet must be a string, not \'%r\'' %
                                       type(value))
    try:
      ipaddr.IPNetwork(value)
    except ValueError:
      raise validation.ValidationError('%s is not a valid IPv4 or IPv6 subnet' %
                                       value)

    # Extra validation check since ipaddr accepts quad-dotted subnet masks.
    parts = value.split('/')
    if len(parts) == 2 and not re.match('^[0-9]+$', parts[1]):
      raise validation.ValidationError('Prefix length of subnet %s must be an '
                                       'integer (quad-dotted masks are not '
                                       'supported)' % value)

    return value
Exemple #7
0
  def Validate(self, value, unused_key=None):
    """Validates an URL pattern."""
    if value is None:
      raise validation.MissingAttribute('url must be specified')
    if not isinstance(value, six_subset.string_types):
      raise validation.ValidationError('url must be a string, not \'%r\'' %
                                       type(value))

    url_holder = ParsedURL(value)
    if url_holder.host_exact:
      _ValidateMatch(_URL_HOST_EXACT_PATTERN_RE, url_holder.host,
                     'invalid host_pattern \'%s\'' % url_holder.host)
      # Explicitly disallow IpV4 #.#.#.# addresses. These will match
      # _URL_HOST_EXACT_PATTERN_RE above.
      _ValidateNotIpV4Address(url_holder.host)
    else:
      _ValidateMatch(_URL_HOST_SUFFIX_PATTERN_RE, url_holder.host_pattern,
                     'invalid host_pattern \'%s\'' % url_holder.host_pattern)

    #TODO(user): validate path_pattern and lengths of both patterns.
    #                also validate hostname label lengths 63 charn max)
    return value