Ejemplo n.º 1
0
class FingerprintSerializer(NotEmptySerializer):
    """Serializer for the Fingerprint model."""

    os_name = CharField(required=True, max_length=64)
    os_release = CharField(required=True, max_length=128)
    os_version = CharField(required=True, max_length=64)

    connection_host = CharField(required=False, max_length=256)
    connection_port = IntegerField(required=False, min_value=0)
    connection_uuid = UUIDField(required=True)

    cpu_count = IntegerField(required=False, min_value=0)
    cpu_core_per_socket = IntegerField(required=False, min_value=0)
    cpu_siblings = IntegerField(required=False, min_value=0)
    cpu_hyperthreading = NullBooleanField(required=False)
    cpu_socket_count = IntegerField(required=False, min_value=0)
    cpu_core_count = IntegerField(required=False, min_value=0)

    system_creation_date = DateField(required=False)
    infrastructure_type = ChoiceField(
        required=True, choices=SystemFingerprint.INFRASTRUCTURE_TYPE)

    virtualized_is_guest = NullBooleanField(required=True)
    virtualized_type = CharField(required=False, max_length=64)
    virtualized_num_guests = IntegerField(required=False, min_value=0)
    virtualized_num_running_guests = IntegerField(required=False, min_value=0)

    class Meta:
        """Meta class for FingerprintSerializer."""

        model = SystemFingerprint
        fields = '__all__'
Ejemplo n.º 2
0
class SourceOptionsSerializer(NotEmptySerializer):
    """Serializer for the SourceOptions model."""

    ssl_protocol = ValidStringChoiceField(
        required=False, choices=SourceOptions.SSL_PROTOCOL_CHOICES)
    ssl_cert_verify = NullBooleanField(required=False)
    disable_ssl = NullBooleanField(required=False)

    class Meta:
        """Metadata for serializer."""

        model = SourceOptions
        fields = ['ssl_protocol', 'ssl_cert_verify', 'disable_ssl']
Ejemplo n.º 3
0
class SystemFactsSerializer(NotEmptySerializer):
    """Serializer for the SystemFacts model."""

    connection_host = CharField(required=False, max_length=256)
    connection_port = IntegerField(required=False, min_value=0)
    connection_uuid = UUIDField(required=True)
    cpu_count = IntegerField(required=False, min_value=0)
    cpu_core_per_socket = IntegerField(required=False, min_value=0)
    cpu_siblings = IntegerField(required=False, min_value=0)
    cpu_hyperthreading = NullBooleanField(required=False)
    cpu_socket_count = IntegerField(required=False, min_value=0)
    cpu_core_count = IntegerField(required=False, min_value=0)
    date_anaconda_log = DateField(required=False)
    date_yum_history = DateField(required=False)
    etc_release_name = CharField(required=True, max_length=64)
    etc_release_version = CharField(required=True, max_length=64)
    etc_release_release = CharField(required=True, max_length=128)
    virt_virt = CharField(required=False, max_length=64)
    virt_type = CharField(required=False, max_length=64)
    virt_num_guests = IntegerField(required=False, min_value=0)
    virt_num_running_guests = IntegerField(required=False, min_value=0)
    virt_what_type = CharField(required=False, max_length=64)

    class Meta:
        """Meta class for SystemFactsSerializer."""

        model = SystemFacts
        exclude = ('id', )
class OfficerAllegationXlsxSerializer(Serializer):
    # from allegation
    crid = CharField(source='allegation.crid')
    officer_name = CharField(allow_blank=True, source='officer.full_name')
    address = CharField(allow_blank=True, source='allegation.address')
    old_complaint_address = CharField(
        allow_null=True, source='allegation.old_complaint_address')
    incident_date = DateTimeField(format='%Y-%m-%d',
                                  allow_null=True,
                                  source='allegation.incident_date',
                                  default_timezone=pytz.utc)
    is_officer_complaint = BooleanField(
        source='allegation.is_officer_complaint')
    beat = CharField(source='allegation.beat.name', allow_null=True)
    coaccused_count = IntegerField(allow_null=True,
                                   source='allegation.coaccused_count')

    category = CharField(allow_null=True)
    subcategory = CharField(allow_null=True)
    start_date = DateField(allow_null=True)
    end_date = DateField(allow_null=True)
    recc_finding = CharField(allow_blank=True, source='recc_finding_display')
    recc_outcome = CharField(allow_blank=True)
    final_finding = CharField(allow_blank=True, source='final_finding_display')
    final_outcome = CharField(allow_blank=True)
    disciplined = NullBooleanField()
Ejemplo n.º 5
0
class CarrierFilters(Serializer):
    carrierName = ChoiceField(choices=CARRIERS,
                              required=False,
                              help_text="Indicates a carrier (type)")
    carrierId = CharField(
        required=False,
        help_text="Indicates a specific carrier configuration name.")
    test = NullBooleanField(required=False,
                            help_text="""
    The test flag indicates whether to use a carrier configured for test. 
    """)
Ejemplo n.º 6
0
class LockUnLockUserSerializer(Serializer):
    """
    效验创建用户的字段
  """
    dn = CharField(required=True,
                   min_length=4,
                   allow_blank=False,
                   error_messages={
                       'min_length': '用户名(dn)不能小于4个字符',
                       'blank': "字段(dn)不能为空。"
                   })
    lock = NullBooleanField(required=True)
Ejemplo n.º 7
0
class MapRequestSerializer(Serializer):
    basemap = CharField(max_length=200,
                        allow_blank=True,
                        allow_null=True,
                        required=False)
    case_insensitive = NullBooleanField(required=False)
    end_user_timezone = CharField(max_length=200,
                                  allow_null=True,
                                  required=False)
    map_format = ChoiceField(["all", "geojson", "gif", "jpg", "png", "xy"],
                             required=False)
    text = CharField(max_length=1e10,
                     trim_whitespace=True,
                     allow_null=True,
                     required=False)
    url = URLField(allow_null=True, required=False)
class FeedbackSerializer(ModelSerializer):
    was_helpful = NullBooleanField(required=True)
    user = UserSerializers(required=False)

    class Meta:
        model = Feedback
        fields = ('was_helpful', 'description', 'user')
        extra_kwargs = {
            'was_helpful': {
                'required': True,
                'allow_null': False
            },
            'user': {
                'read_only': True
            }
        }

    def create(self, validated_data):
        feedback = Feedback(**dict(validated_data,
                                   user=self.context['user'],
                                   comment=self.context['comment']))
        feedback.save()
        return feedback
Ejemplo n.º 9
0
 class TestSerializer(Serializer):  # pylint: disable=abstract-method
     boolean_field = BooleanField()
     char_field = CharField()
     choice_field = ChoiceField([])
     date_field = DateField()
     date_time_field = DateTimeField()
     decimal_field = DecimalField(1, 1)
     dict_field = DictField()
     duration_field = DurationField()
     email_field = EmailField()
     file_field = FileField()
     file_path_field = FilePathField('')
     float_field = FloatField()
     image_field = ImageField()
     integer_field = IntegerField()
     ip_address_field = IPAddressField()
     json_field = JSONField()
     string_list_field = ListField(child=CharField())
     int_list_field = ListField(child=IntegerField())
     int_list_list_field = ListField(
         child=ListField(
             child=IntegerField(),
         ),
     )
     multiple_choice_field = MultipleChoiceField([])
     null_boolean_field = NullBooleanField()
     regex_field = RegexField('')
     slug_field = SlugField()
     time_field = TimeField()
     url_field = URLField()
     uuid_field = UUIDField()
     nullable_char_field = CharField(allow_null=True)
     nullable_char_listfield = ListField(
         child=CharField(allow_null=True),
     )
     write_only_field = CharField(write_only=True)
Ejemplo n.º 10
0
class SystemFingerprintSerializer(NotEmptySerializer):
    """Serializer for the Fingerprint model."""

    # Common facts
    system_platform_id = UUIDField(format='hex_verbose', read_only=True)
    name = CharField(required=False, max_length=256)

    os_name = CharField(required=False, max_length=64)
    os_release = CharField(required=False, max_length=128)
    os_version = CharField(required=False, max_length=64)

    infrastructure_type = ChoiceField(
        required=False, choices=SystemFingerprint.INFRASTRUCTURE_TYPE)

    mac_addresses = CustomJSONField(required=False)
    ip_addresses = CustomJSONField(required=False)

    cpu_count = IntegerField(required=False, min_value=0)

    architecture = CharField(required=False, max_length=64)

    # Network scan facts
    bios_uuid = CharField(required=False, max_length=36)
    subscription_manager_id = CharField(required=False, max_length=36)

    cpu_socket_count = IntegerField(required=False, min_value=0)
    cpu_core_count = FloatField(required=False, min_value=0)
    cpu_core_per_socket = IntegerField(required=False, min_value=0)

    system_creation_date = DateField(required=False)
    system_last_checkin_date = DateField(required=False)

    system_role = CharField(required=False, max_length=128)
    system_addons = JSONField(required=False)
    system_service_level_agreement = CharField(required=False, max_length=128)
    system_usage_type = CharField(required=False, max_length=128)

    insights_client_id = CharField(required=False, max_length=128)

    virtualized_type = CharField(required=False, max_length=64)

    # VCenter scan facts
    vm_state = CharField(required=False, max_length=24)
    vm_uuid = CharField(required=False, max_length=36)
    vm_dns_name = CharField(required=False, max_length=256)

    vm_host = CharField(required=False, max_length=128)
    vm_host_socket_count = IntegerField(required=False, min_value=0)
    vm_host_core_count = IntegerField(required=False, min_value=0)

    vm_cluster = CharField(required=False, max_length=128)
    vm_datacenter = CharField(required=False, max_length=128)

    products = ProductSerializer(many=True, allow_null=True, required=False)
    entitlements = EntitlementSerializer(many=True,
                                         allow_null=True,
                                         required=False)

    # Red Hat facts
    is_redhat = NullBooleanField(required=False)
    redhat_certs = CharField(required=False)
    # pylint: disable=invalid-name
    redhat_package_count = IntegerField(required=False, min_value=0)

    metadata = CustomJSONField(required=True)
    sources = CustomJSONField(required=True)
    etc_machine_id = CharField(required=False, max_length=48)

    class Meta:
        """Meta class for SystemFingerprintSerializer."""

        model = SystemFingerprint
        fields = '__all__'

    def create(self, validated_data):
        """Create a system fingerprint."""
        products_data = validated_data.pop('products', [])
        entitlements_data = validated_data.pop('entitlements', [])
        fingerprint = SystemFingerprint.objects.create(**validated_data)
        for product_data in products_data:
            Product.objects.create(fingerprint=fingerprint, **product_data)
        for entitlement_data in entitlements_data:
            Entitlement.objects.create(fingerprint=fingerprint,
                                       **entitlement_data)
        return fingerprint
Ejemplo n.º 11
0
class FingerprintSerializer(ModelSerializer):
    """Serializer for the Fingerprint model."""

    # Scan information
    fact_collection_id = PrimaryKeyRelatedField(
        queryset=FactCollection.objects.all())

    # Common facts
    name = CharField(required=False, max_length=256)

    os_name = CharField(required=False, max_length=64)
    os_release = CharField(required=False, max_length=128)
    os_version = CharField(required=False, max_length=64)

    infrastructure_type = ChoiceField(
        required=False, choices=SystemFingerprint.INFRASTRUCTURE_TYPE)
    virtualized_is_guest = NullBooleanField(default=None)

    mac_addresses = CustomJSONField(required=False)
    ip_addresses = CustomJSONField(required=False)

    cpu_count = IntegerField(required=False, min_value=0)

    # Network scan facts
    bios_uuid = CharField(required=False, max_length=36)
    subscription_manager_id = CharField(required=False, max_length=36)

    cpu_core_per_socket = IntegerField(required=False, min_value=0)
    cpu_siblings = IntegerField(required=False, min_value=0)
    cpu_hyperthreading = NullBooleanField(required=False)
    cpu_socket_count = IntegerField(required=False, min_value=0)
    cpu_core_count = IntegerField(required=False, min_value=0)

    system_creation_date = DateField(required=False)

    virtualized_type = CharField(required=False, max_length=64)
    virtualized_num_guests = IntegerField(required=False, min_value=0)
    virtualized_num_running_guests = IntegerField(required=False, min_value=0)

    # VCenter scan facts
    vm_state = CharField(required=False, max_length=24)
    vm_uuid = CharField(required=False, max_length=36)
    vm_memory_size = IntegerField(required=False, min_value=0)
    vm_dns_name = CharField(required=False, max_length=128)

    vm_host = CharField(required=False, max_length=128)
    vm_host_socket_count = IntegerField(required=False, min_value=0)
    vm_host_cpu_cores = IntegerField(required=False, min_value=0)

    vm_host_cpu_threads = IntegerField(required=False, min_value=0)

    vm_cluster = CharField(required=False, max_length=128)
    vm_datacenter = CharField(required=False, max_length=128)

    metadata = CustomJSONField(required=True)

    class Meta:
        """Meta class for FingerprintSerializer."""

        model = SystemFingerprint
        fields = '__all__'
Ejemplo n.º 12
0
class FingerprintSerializer(ModelSerializer):
    """Serializer for the Fingerprint model."""

    # Scan information
    report_id = PrimaryKeyRelatedField(queryset=FactCollection.objects.all())

    # Common facts
    name = CharField(required=False, max_length=256)

    os_name = CharField(required=False, max_length=64)
    os_release = CharField(required=False, max_length=128)
    os_version = CharField(required=False, max_length=64)

    infrastructure_type = ChoiceField(
        required=False, choices=SystemFingerprint.INFRASTRUCTURE_TYPE)

    mac_addresses = CustomJSONField(required=False)
    ip_addresses = CustomJSONField(required=False)

    cpu_count = IntegerField(required=False, min_value=0)

    architecture = CharField(required=False, max_length=64)

    # Network scan facts
    bios_uuid = CharField(required=False, max_length=36)
    subscription_manager_id = CharField(required=False, max_length=36)

    cpu_socket_count = IntegerField(required=False, min_value=0)
    cpu_core_count = IntegerField(required=False, min_value=0)

    system_creation_date = DateField(required=False)

    virtualized_type = CharField(required=False, max_length=64)

    # VCenter scan facts
    vm_state = CharField(required=False, max_length=24)
    vm_uuid = CharField(required=False, max_length=36)
    vm_dns_name = CharField(required=False, max_length=128)

    vm_host = CharField(required=False, max_length=128)
    vm_host_socket_count = IntegerField(required=False, min_value=0)

    vm_cluster = CharField(required=False, max_length=128)
    vm_datacenter = CharField(required=False, max_length=128)

    products = ProductSerializer(many=True, allow_null=True, required=False)
    entitlements = EntitlementSerializer(many=True,
                                         allow_null=True,
                                         required=False)

    # Red Hat facts
    is_redhat = NullBooleanField(required=False)
    redhat_certs = CharField(required=False, max_length=128)
    # pylint: disable=invalid-name
    redhat_package_count = IntegerField(required=False, min_value=0)

    metadata = CustomJSONField(required=True)
    sources = CustomJSONField(required=True)

    class Meta:
        """Meta class for FingerprintSerializer."""

        model = SystemFingerprint
        fields = '__all__'

    def create(self, validated_data):
        """Create a system fingerprint."""
        products_data = validated_data.pop('products', [])
        entitlements_data = validated_data.pop('entitlements', [])
        fingerprint = SystemFingerprint.objects.create(**validated_data)
        for product_data in products_data:
            Product.objects.create(fingerprint=fingerprint, **product_data)
        for entitlement_data in entitlements_data:
            Entitlement.objects.create(fingerprint=fingerprint,
                                       **entitlement_data)
        return fingerprint
Ejemplo n.º 13
0
class TRRXlsxSerializer(Serializer):
    id = IntegerField()
    beat = IntegerField(allow_null=True)
    block = CharField(allow_null=True)
    direction = CharField(allow_null=True)
    street = CharField(allow_null=True)
    location = CharField(allow_null=True)
    trr_datetime = DateTimeField(format='%Y-%m-%d',
                                 allow_null=True,
                                 default_timezone=pytz.utc)
    indoor_or_outdoor = CharField(allow_null=True)
    lighting_condition = CharField(allow_null=True)
    weather_condition = CharField(allow_null=True)
    notify_OEMC = NullBooleanField()
    notify_district_sergeant = NullBooleanField()
    notify_OP_command = NullBooleanField()
    notify_DET_division = NullBooleanField()
    number_of_weapons_discharged = IntegerField(allow_null=True)
    party_fired_first = CharField(allow_null=True)
    location_recode = CharField(allow_null=True)
    taser = NullBooleanField()
    total_number_of_shots = IntegerField(allow_null=True)
    firearm_used = NullBooleanField()
    number_of_officers_using_firearm = IntegerField(allow_null=True)
    officer_assigned_beat = CharField(allow_null=True)
    officer_unit = CharField(allow_null=True, source='officer_unit.unit_name')
    officer_unit_detail = CharField(allow_null=True,
                                    source='officer_unit_detail.unit_name')
    officer_on_duty = NullBooleanField()
    officer_in_uniform = NullBooleanField()
    officer_injured = NullBooleanField()
    officer_rank = CharField(allow_null=True)
    subject_id = IntegerField(allow_null=True)
    subject_armed = NullBooleanField()
    subject_injured = NullBooleanField()
    subject_alleged_injury = NullBooleanField()
    subject_age = IntegerField(allow_null=True)
    subject_birth_year = IntegerField(allow_null=True)
    subject_gender = CharField(allow_null=True)
    subject_race = CharField(allow_null=True)