示例#1
0
class TrustFactorsV2(Resource):
    class Meta:
        unknown = EXCLUDE

    score_id: str = field(metadata={'data_key': 'Id'})
    algorithm_id: str = field(metadata={'data_key': 'AlgorithmId'})
    resource_id: str = field(metadata={'data_key': 'ResourceId'})
    score: int = field(metadata={'data_key': 'Score'})
    score_type: str = field(metadata={'data_key': 'ScoreType'})
    timestamp: datetime = field(metadata={'marshmallow_field': NanoTimestampField(data_key='Timestamp')})
    explanation: TrustFactorDetailsV2 = field(metadata={'data_key': 'Explanation'})
    created_at: datetime = field(metadata={'marshmallow_field': NanoTimestampField(data_key='CreatedAt')})
    updated_at: datetime = field(metadata={'marshmallow_field': NanoTimestampField(data_key='UpdatedAt')})
    factors_updated_at: datetime = field(metadata={'marshmallow_field':
                                                   NanoTimestampField(data_key='FactorsUpdatedAt')})
    active_factors: List[TrustFactorV2] = field(default_factory=list, metadata={'data_key': 'ActiveFactors'})
    inactive_factors: List[TrustFactorV2] = field(default_factory=list, metadata={'data_key': 'InactiveFactors'})
    Schema: ClassVar[Schema] = Schema

    @property
    def name(self) -> str:
        return self.score_id

    @property
    def id(self) -> str:
        return self.score_id
示例#2
0
class User(Resource):
    class Meta:
        unknown = EXCLUDE

    username: str = field(metadata={'data_key': 'Name'})
    email: str = field(metadata={'data_key': 'Email'})
    groups: str = field(metadata={'data_key': 'Groups'})
    created_at: datetime = field(
        metadata={
            "marshmallow_field": NanoTimestampField(data_key='CreatedAt')
        })
    last_login: datetime = field(
        metadata={
            "marshmallow_field": NanoTimestampField(data_key='LastLogin')
        })
    login_count: int = field(metadata={'data_key': 'LoginCount'})
    trust_data: TrustDataV1 = field(metadata={'data_key': 'TrustData'})
    serial_numbers: List[str] = field(default_factory=list,
                                      metadata={'data_key': 'SerialNumbers'})
    roles: List[str] = field(default_factory=list,
                             metadata={
                                 'data_key': 'Roles',
                                 'allow_none': True
                             })
    is_deleted: bool = False
    Schema: ClassVar[Type[Schema]] = Schema

    @property
    def name(self) -> str:
        return self.username

    @property
    def id(self) -> str:
        return self.email
示例#3
0
class Device(Resource):
    class Meta:
        unknown = EXCLUDE

    serial_number: str = field(metadata={'data_key': 'SerialNumber'})
    device_id: str = field(metadata={
        'data_key': 'DeviceID',
        'allow_none': True
    })
    device_friendly_name: str = field(
        metadata={'data_key': 'DeviceFriendlyName'})
    created_at: datetime = field(
        metadata={
            "marshmallow_field": NanoTimestampField(data_key='CreatedAt')
        })
    last_login: datetime = field(
        metadata={
            "marshmallow_field": NanoTimestampField(data_key='LastLogin')
        })
    login_count: int = field(metadata={'data_key': 'LoginCount'})
    ownership: str = field(
        metadata={
            'data_key':
            'Ownership',
            'validate':
            validate.OneOf(DeviceOwnership.choices() +
                           ['UNKNOWN', 'Undefined', ''])
        })
    platform: str = field(metadata={'data_key': 'Platform'})
    model: str = field(metadata={'data_key': 'Model'})
    architecture: str = field(metadata={'data_key': 'Architecture'})
    registered_status: bool = field(metadata={'data_key': 'RegisteredStatus'})
    is_banned: bool = field(metadata={'data_key': 'Banned'})
    os_level: str = field(metadata={'data_key': 'OS'})
    app_version: Optional[VersionInfo] = field(
        metadata={
            'marshmallow_field': VersionField(data_key='AppVersion'),
            "missing": None
        })
    mdm_data: MdmData = field(metadata={'data_key': 'MdmData'})
    trust_data: TrustDataV1 = field(metadata={'data_key': 'TrustData'})
    emails: List[str] = field(default_factory=list,
                              metadata={'data_key': 'Emails'})
    roles: List[str] = field(default_factory=list,
                             metadata={
                                 'data_key': 'Roles',
                                 'allow_none': True
                             })
    is_deleted: bool = False
    Schema: ClassVar[Type[Schema]] = Schema

    @property
    def name(self) -> str:
        return self.device_friendly_name

    @property
    def id(self) -> str:
        return self.serial_number
示例#4
0
class EventTrustScore:
    class Meta:
        unknown = EXCLUDE

    trustscore_id: str = field(metadata={"data_key": "id"})
    trustscore_type: str = field(metadata={"data_key": "type"})
    timestamp: datetime = field(
        metadata={'marshmallow_field': NanoTimestampField()})
    score: int
示例#5
0
文件: policy.py 项目: rb-nr/pybanyan
class PolicyAttachInfo:
    class Meta:
        unknown = EXCLUDE

    enabled: bool = field(metadata={'data_key': 'Enabled'})
    policy_id: UUID = field(metadata={'data_key': 'PolicyID'})
    service_id: str = field(metadata={'data_key': 'ServiceID'})
    attached_by: str = field(metadata={'data_key': 'AttachedBy'})
    detached_by: str = field(metadata={'data_key': 'DetachedBy'})
    attached_at: datetime = field(
        metadata={
            'marshmallow_field': NanoTimestampField(data_key='AttachedAt')
        })
    detached_at: datetime = field(
        metadata={
            'marshmallow_field': NanoTimestampField(data_key='DetachedAt')
        })
    Schema: ClassVar[Schema] = Schema
示例#6
0
class EventRoleInfo:
    class Meta:
        unknown = EXCLUDE

    role_id: UUID = field(metadata={"data_key": "id"})
    role_name: str = field(metadata={"data_key": "name"})
    version: int
    bound_by: str
    bound_at: datetime = field(
        metadata={'marshmallow_field': NanoTimestampField()})
示例#7
0
class MdmData:
    class Meta:
        unknown = EXCLUDE

    timestamp: datetime = field(
        metadata={
            "marshmallow_field": NanoTimestampField(data_key='Timestamp')
        })
    source: str = field(metadata={'data_key': 'Source'})
    compromised_status: str = field(metadata={'data_key': 'CompromisedStatus'})
    compliant_status: str = field(metadata={'data_key': 'CompliantStatus'})
示例#8
0
class AuditEvent(Resource):
    class Meta:
        unknown = EXCLUDE

    event_id: str = field(metadata={"data_key": "id"})
    event_type: str = field(metadata={"data_key": "type", "validate": validate.OneOf(AuditEventType.choices())})
    org_id: UUID
    created_at: datetime = field(metadata={"marshmallow_field": NanoTimestampField()})
    message: str
    action: str = field(metadata={"validate": validate.OneOf(AuditAction.choices())})
    admin_email: str
    changes_new: Optional[str]
    changes_old: Optional[str]
    Schema: ClassVar[Type[Schema]] = Schema

    @property
    def name(self) -> str:
        return self.id

    @property
    def id(self) -> str:
        return str(self.event_id)

    def _extract_obj(self, obj_str: str) -> Resource:
        if self.event_type == AuditEventType.REGISTERED_SERVICE:
            return ServiceInfo.Schema().loads(obj_str)
        elif self.event_type == AuditEventType.POLICY:
            return PolicyInfo.Schema().loads(obj_str)
        elif self.event_type == AuditEventType.ROLE:
            return RoleInfo.Schema().loads(obj_str)
        elif self.event_type == AuditEventType.SECURITY_ATTACH_POLICY:
            return Attachment.Schema().loads(obj_str)
        else:
            raise ValueError(f'unknown object type for deserialization: {self.event_type}')

    @property
    def object_old(self) -> Resource:
        return self._extract_obj(self.changes_old) if self.changes_old else None

    @property
    def object_new(self) -> Resource:
        return self._extract_obj(self.changes_new) if self.changes_new else None

    # noinspection PyUnusedLocal
    # pylint: disable=W0613,R0201
    @pre_load
    def _remove_empty_dates(self, data, many, **kwargs):
        if "changes_new" in data and data["changes_new"] is not None:
            data["changes_new"] = json.dumps(data["changes_new"])
        if "changes_old" in data and data["changes_old"] is not None:
            data["changes_old"] = json.dumps(data["changes_old"])
        return data
示例#9
0
class TrustScore(Resource):
    class Meta:
        unknown = EXCLUDE

    trust_type: str = field(metadata={
        'data_key': 'TrustType',
        'validate': validate.OneOf(TrustType.choices())
    })
    trust_id: str = field(metadata={'data_key': 'TrustID'})
    score: int = field(metadata={'data_key': 'Score'})
    level: str = field(metadata={'data_key': 'Level'})
    ext_source: str = field(metadata={'data_key': 'ExtSource'})
    reason: str = field(metadata={'data_key': 'Reason'})
    factors_json: str = field(metadata={'data_key': 'FactorsJSON'})
    created_at: datetime = field(
        metadata={
            "marshmallow_field": NanoTimestampField(data_key='CreatedAt')
        })
    deleted_at: datetime = field(
        metadata={
            "marshmallow_field": NanoTimestampField(data_key='DeletedAt')
        })
    last_updated_at: datetime = field(
        metadata={
            "marshmallow_field": NanoTimestampField(data_key='LastUpdatedAt')
        })
    Schema: ClassVar[Type[Schema]] = Schema

    @property
    def name(self) -> str:
        return self.trust_id

    @property
    def id(self) -> str:
        return self.trust_id

    @property
    def factors(self) -> TrustFactorsV2:
        return TrustFactorsV2.Schema().loads(self.factors_json)
示例#10
0
class PolicyAttachInfo:
    class Meta:
        unknown = EXCLUDE

    policy_id: UUID = field(metadata={'data_key': 'PolicyID'})
    policy_name: str = field(metadata={'data_key': 'PolicyName'})
    attached_id: str = field(metadata={'data_key': 'AttachedToID'})
    attached_name: str = field(metadata={'data_key': 'AttachedToName'})
    attached_type: str = field(metadata={'data_key': 'AttachedToType'})
    enabled: bool = field(metadata={'data_key': 'Enabled'})
    attached_at: datetime = field(
        metadata={
            'marshmallow_field': NanoTimestampField(data_key='AttachedAt')
        })
    attached_by: str = field(metadata={'data_key': 'AttachedBy'})
    detached_at: Optional[datetime] = field(
        default=None,
        metadata={
            'marshmallow_field': NanoTimestampField(data_key='DetachedAt')
        })
    detached_by: Optional[str] = field(default=None,
                                       metadata={'data_key': 'DetachedBy'})
    Schema: ClassVar[Schema] = Schema
示例#11
0
class TrustDataV1:
    class Meta:
        unknown = EXCLUDE

    entity_trustscore: int = field(metadata={'data_key': 'EntityTrustscore'})
    override_trustscore: int = field(
        metadata={'data_key': 'OverrideTrustscore'})
    access_trustscore: int = field(metadata={'data_key': 'AccessTrustscore'})
    override_active: bool = field(metadata={'data_key': 'OverrideActive'})
    level: str = field(metadata={
        'data_key': 'Level',
        'validate': validate.OneOf(TrustLevel.choices())
    })
    updated_at: datetime = field(
        metadata={
            "marshmallow_field": NanoTimestampField(data_key='UpdatedAt')
        })
    factors: List[TrustFactorV1] = field(default_factory=list,
                                         metadata={'data_key': 'Factors'})
示例#12
0
class EventDevice:
    class Meta:
        unknown = EXCLUDE

    device_id: Optional[UUID] = field(metadata={"data_key": "id"})
    friendly_name: str
    mac_address: str
    serial_number: str
    registration_status: bool = field(
        metadata={'marshmallow_field': fields.String()})
    compromised_status: str
    compliance_status: str
    oem_info: str
    model: str
    platform: str
    ownership: str
    architecture: str
    udid: str
    source: str
    last_mdm_data_synced_at: datetime = field(
        metadata={'marshmallow_field': NanoTimestampField()})
示例#13
0
class Attachment(Resource):
    class Meta:
        unknown = EXCLUDE

    policy_id: UUID = field(metadata={'data_key': 'PolicyID'})
    policy_name: str = field(metadata={'data_key': 'PolicyName'})
    attached_to_id: str = field(metadata={'data_key': 'AttachedToID'})
    attached_to_name: str = field(metadata={'data_key': 'AttachedToName'})
    attached_to_type: str = field(metadata={'data_key': 'AttachedToType',
                                            'validate': validate.OneOf(AttachmentType.choices())})
    enabled: bool = field(metadata={'data_key': 'Enabled'})
    attached_at: datetime = field(metadata={'marshmallow_field': NanoTimestampField(data_key='AttachedAt')})
    attached_by: str = field(metadata={'data_key': 'AttachedBy'})
    Schema: ClassVar[Type[Schema]] = Schema

    @property
    def name(self) -> str:
        return self.policy_name + '|' + self.attached_to_type + '|' + self.attached_to_name

    @property
    def id(self) -> str:
        return str(self.policy_id) + '|' + self.attached_to_type + '|' + self.attached_to_id