def to_python(self, value):
        Field.to_python(self, value)
        
        # Parse the duration
        m = DurationField.DURATION_RE.match(value)

        # Make sure the duration could be parsed
        if m is None:
            raise FieldValidationException("The value of '%s' for the '%s' parameter is not a valid duration" % (str(value), self.name))
        
        # Get the units and duration
        d = m.groupdict()
        
        units = d['units']
        
        # Parse the value provided
        try:
            duration = int(d['duration'])
        except ValueError:
            raise FieldValidationException("The duration '%s' for the '%s' parameter is not a valid number" % (d['duration'], self.name))
        
        # Make sure the units are valid
        if len(units) > 0 and units not in DurationField.UNITS:
            raise FieldValidationException("The unit '%s' for the '%s' parameter is not a valid unit of duration" % (units, self.name))
        
        # Convert the units to seconds
        if len(units) > 0:
            return duration * DurationField.UNITS[units]
        else:
            return duration
    def to_python(self, value, session_key=None):
        Field.to_python(self, value, session_key=None)

        # Parse the size
        m = DataSizeField.DATA_SIZE_RE.match(value)

        # Make sure the duration could be parsed
        if m is None:
            raise FieldValidationException("The value of '%s' for the '%s' parameter is not a valid size of data" % (str(value), self.name))

        # Get the units and duration
        d = m.groupdict()

        units = d['units'].lower()

        # Parse the value provided
        try:
            size = int(d['size'])
        except ValueError:
            raise FieldValidationException("The size '%s' for the '%s' parameter is not a valid number" % (d['duration'], self.name))

        # Make sure the units are valid
        if len(units) > 0 and units not in DataSizeField.UNITS:
            raise FieldValidationException("The unit '%s' for the '%s' parameter is not a valid unit of duration" % (units, self.name))

        # Convert the units to seconds
        if len(units) > 0:
            return size * DataSizeField.UNITS[units]
        else:
            return size
示例#3
0
    def to_python(self, value, session_key=None):
        Field.to_python(self, value, session_key)

        if value is None:
            return None

        try:
            ports_list = parseIntSet(value, True)
        except ValueError:
            raise FieldValidationException("The value of '%s' for the '%s' parameter is not a valid list" % (str(value), self.name))

        return ports_list
示例#4
0
    def to_python(self, value, session_key=None):
        Field.to_python(self, value, session_key)

        # Resolve the path
        resolved_path = os.path.normpath(
            os.path.join(os.environ['SPLUNK_HOME'], value))

        # This is a list of the paths that we will not allow serving.
        restricted_paths = []

        # The mongo key lives here
        restricted_paths.extend(
            self.resolve_intermediate_paths('var/lib/splunk/kvstore/mongo'))

        # The Splunk secret and certificates live here and the passwd file lives in etc
        restricted_paths.extend(self.resolve_intermediate_paths('etc/auth'))

        # Make sure that user isn't serving one of the paths that is restricted
        if resolved_path in restricted_paths:
            raise FieldValidationException(
                'The path to serve is not allowed for security' +
                'reasons; Splunk paths containing password files, ' +
                'certificates, etc. are not allowed to be served')

        # Make the path if necessary
        try:
            os.mkdir(resolved_path)
        except OSError:
            pass  # Directory likely already exists

        # Ensure that the path exists
        if not os.path.exists(resolved_path):
            raise FieldValidationException(
                'The path to serve does not exist and could not be' +
                'created')

        # Ensure that the path is a directory
        if not os.path.isdir(resolved_path):
            raise FieldValidationException(
                'The path to serve is a file, not a directory')

        # Return the path that is normalized and resolved
        return resolved_path
    def to_python(self, value, session_key=None):
        Field.to_python(self, value, session_key=None)

        # Parse the size
        m = DataSizeField.DATA_SIZE_RE.match(value)

        # Make sure the duration could be parsed
        if m is None:
            raise FieldValidationException(
                "The value of '%s' for the '%s' parameter is not a valid size of data"
                % (str(value), self.name))

        # Get the units and duration
        d = m.groupdict()

        units = d['units'].lower()

        # Parse the value provided
        try:
            size = int(d['size'])
        except ValueError:
            raise FieldValidationException(
                "The size '%s' for the '%s' parameter is not a valid number" %
                (d['duration'], self.name))

        # Make sure the units are valid
        if len(units) > 0 and units not in DataSizeField.UNITS:
            raise FieldValidationException(
                "The unit '%s' for the '%s' parameter is not a valid unit of duration"
                % (units, self.name))

        # Convert the units to seconds
        if len(units) > 0:
            return size * DataSizeField.UNITS[units]
        else:
            return size
 def to_python(self, value):
     Field.to_python(self, value)
     return value
    def to_python(self, value, session_key=None):
        Field.to_python(self, value, session_key=None)

        return value
示例#8
0
    def to_python(self, value, session_key=None):
        Field.to_python(self, value, session_key)

        return SelectorField.parse_selector(value, self.name)
    def to_python(self, value, session_key=None):
        Field.to_python(self, value, session_key)

        return SelectorField.parse_selector(value, self.name)
示例#10
0
    def to_python(self, value, session_key=None):
        Field.to_python(self, value, session_key=None)

        return value