|
| 1 | +# Copyright ©, 2022-present, Lightspark Group, Inc. - All Rights Reserved |
| 2 | + |
| 3 | +from dataclasses import dataclass |
| 4 | +from datetime import datetime |
| 5 | +from typing import Any, Mapping |
| 6 | + |
| 7 | +from lightspark.exceptions import LightsparkException |
| 8 | +from lightspark.requests.requester import Requester |
| 9 | +from lightspark.utils.enums import parse_enum_list |
| 10 | + |
| 11 | +from .Entity import Entity |
| 12 | +from .Permission import Permission |
| 13 | + |
| 14 | + |
| 15 | +@dataclass |
| 16 | +class AuditLogActor(Entity): |
| 17 | + """Audit log actor who called the GraphQL mutation""" |
| 18 | + |
| 19 | + requester: Requester |
| 20 | + |
| 21 | + id: str |
| 22 | + """The unique identifier of this entity across all Lightspark systems. Should be treated as an opaque string.""" |
| 23 | + |
| 24 | + created_at: datetime |
| 25 | + """The date and time when the entity was first created.""" |
| 26 | + |
| 27 | + updated_at: datetime |
| 28 | + """The date and time when the entity was last updated.""" |
| 29 | + typename: str |
| 30 | + |
| 31 | + def to_json(self) -> Mapping[str, Any]: |
| 32 | + return { |
| 33 | + "__typename": self.typename, |
| 34 | + "audit_log_actor_id": self.id, |
| 35 | + "audit_log_actor_created_at": self.created_at.isoformat(), |
| 36 | + "audit_log_actor_updated_at": self.updated_at.isoformat(), |
| 37 | + } |
| 38 | + |
| 39 | + |
| 40 | +FRAGMENT = """ |
| 41 | +fragment AuditLogActorFragment on AuditLogActor { |
| 42 | + __typename |
| 43 | + ... on ApiToken { |
| 44 | + __typename |
| 45 | + api_token_id: id |
| 46 | + api_token_created_at: created_at |
| 47 | + api_token_updated_at: updated_at |
| 48 | + api_token_client_id: client_id |
| 49 | + api_token_name: name |
| 50 | + api_token_permissions: permissions |
| 51 | + api_token_is_deleted: is_deleted |
| 52 | + } |
| 53 | +} |
| 54 | +""" |
| 55 | + |
| 56 | + |
| 57 | +def from_json(requester: Requester, obj: Mapping[str, Any]) -> AuditLogActor: |
| 58 | + if obj["__typename"] == "ApiToken": |
| 59 | + # pylint: disable=import-outside-toplevel |
| 60 | + from lightspark.objects.ApiToken import ApiToken |
| 61 | + |
| 62 | + return ApiToken( |
| 63 | + requester=requester, |
| 64 | + typename="ApiToken", |
| 65 | + id=obj["api_token_id"], |
| 66 | + created_at=datetime.fromisoformat(obj["api_token_created_at"]), |
| 67 | + updated_at=datetime.fromisoformat(obj["api_token_updated_at"]), |
| 68 | + client_id=obj["api_token_client_id"], |
| 69 | + name=obj["api_token_name"], |
| 70 | + permissions=parse_enum_list(Permission, obj["api_token_permissions"]), |
| 71 | + is_deleted=obj["api_token_is_deleted"], |
| 72 | + ) |
| 73 | + graphql_typename = obj["__typename"] |
| 74 | + raise LightsparkException( |
| 75 | + "UNKNOWN_INTERFACE", |
| 76 | + f"Couldn't find a concrete type for interface AuditLogActor corresponding to the typename={graphql_typename}", |
| 77 | + ) |
0 commit comments