|
| 1 | +from enum import StrEnum |
| 2 | +from functools import cached_property |
| 3 | + |
| 4 | + |
| 5 | +class EventAction(StrEnum): |
| 6 | + """event.action values defined for Curious |
| 7 | +
|
| 8 | + Uses colon-separated format "{resource}:{subject}:{action}": |
| 9 | + - "{resource}" all lowercase or underscore |
| 10 | + - "{subject}" all lowercase or underscore or colon or omitted |
| 11 | + - "{action}" all lowercase or underscore |
| 12 | +
|
| 13 | + Note that "{subject}" can contain colons or be omitted. |
| 14 | +
|
| 15 | + If omitted, "{subject}" is implied to be the same as "{resource}". |
| 16 | + """ |
| 17 | + |
| 18 | + # User auth |
| 19 | + USER_SESSION_LOGIN = "user:session:login" |
| 20 | + USER_SESSION_LOGOUT = "user:session:logout" |
| 21 | + USER_SESSION_REFRESH = "user:session:refresh" |
| 22 | + USER_SESSION_INVALID = "user:session:invalid" |
| 23 | + |
| 24 | + # User IAM |
| 25 | + USER_CREATE = "user:create" |
| 26 | + USER_DELETE = "user:delete" |
| 27 | + USER_PASSWORD_CHANGE = "user:password:change" |
| 28 | + USER_PASSWORD_RECOVERY_INITIATE = "user:password:recovery:initiate" |
| 29 | + USER_PASSWORD_RECOVERY_APPROVE = "user:password:recovery:approve" |
| 30 | + USER_MFA_ENABLE = "user:mfa:enable" |
| 31 | + USER_MFA_DISABLE = "user:mfa:disable" |
| 32 | + USER_MFA_RECOVERY_VIEW = "user:mfa:recovery:view" |
| 33 | + USER_MFA_RECOVERY_DOWNLOAD = "user:mfa:recovery:download" |
| 34 | + USER_MFA_RECOVERY_USE = "user:mfa:recovery:use" |
| 35 | + |
| 36 | + # Workspace IAM |
| 37 | + WORKSPACE_ACCESS_GRANT = "workspace:access:grant" |
| 38 | + WORKSPACE_ACCESS_REVOKE = "workspace:access:revoke" |
| 39 | + |
| 40 | + # Applet IAM |
| 41 | + APPLET_CREATE = "applet:create" |
| 42 | + APPLET_DELETE = "applet:delete" |
| 43 | + APPLET_ENCRYPTION_UPDATE = "applet:encryption:update" |
| 44 | + APPLET_TRANSFER_INITIATE = "applet:transfer:initiate" |
| 45 | + APPLET_TRANSFER_ACCEPT = "applet:transfer:accept" |
| 46 | + APPLET_TRANSFER_DECLINE = "applet:transfer:decline" |
| 47 | + APPLET_INVITE_INITIATE = "applet:invite:initiate" |
| 48 | + APPLET_INVITE_ACCEPT = "applet:invite:accept" |
| 49 | + APPLET_INVITE_DECLINE = "applet:invite:decline" |
| 50 | + |
| 51 | + # Applet data access |
| 52 | + APPLET_SUBJECT_VIEW = "applet:subject:view" |
| 53 | + APPLET_ANSWER_VIEW = "applet:answer:view" |
| 54 | + APPLET_ANSWER_IDENTIFIER_VIEW = "applet:answer:identifier:view" |
| 55 | + APPLET_ANSWER_ASSESSMENT_VIEW = "applet:answer:assessment:view" |
| 56 | + APPLET_ANSWER_NOTE_VIEW = "applet:answer:note:view" |
| 57 | + APPLET_ANSWER_EXPORT = "applet:answer:export" |
| 58 | + |
| 59 | + # Applet file download |
| 60 | + APPLET_ANSWER_EHR_DOWNLOAD = "applet:answer:ehr:download" |
| 61 | + APPLET_ANSWER_FILE_DOWNLOAD = "applet:answer:file:download" |
| 62 | + APPLET_ANSWER_REPORT_DOWNLOAD = "applet:answer:report:download" |
| 63 | + |
| 64 | + @cached_property |
| 65 | + def _parts(self) -> tuple[str, ...]: |
| 66 | + """Split into parts by colon ":" |
| 67 | +
|
| 68 | + - ("a", "b", "c", "d") for event "a:b:c:d" |
| 69 | + - ("foo", "bar", "baz") for event "foo:bar:baz" |
| 70 | + - ("toto", "tata") for event "toto:tata" |
| 71 | + """ |
| 72 | + return tuple(self.value.split(":")) |
| 73 | + |
| 74 | + @cached_property |
| 75 | + def resource(self) -> str: |
| 76 | + """First part of enum value |
| 77 | +
|
| 78 | + - "a" for event "a:b:c:d" |
| 79 | + - "foo" for event "foo:bar:baz" |
| 80 | + - "toto" for event "toto:tata" |
| 81 | + """ |
| 82 | + return self._parts[0] |
| 83 | + |
| 84 | + @cached_property |
| 85 | + def subject(self) -> str: |
| 86 | + """Middle part of enum value, or resource if middle part does not exist |
| 87 | +
|
| 88 | + - "b:c" for event "a:b:c:d" |
| 89 | + - "bar" for event "foo:bar:baz" |
| 90 | + - "toto" for event "toto:tata" |
| 91 | + """ |
| 92 | + return ":".join(self._parts[1:-1]) or self.resource |
| 93 | + |
| 94 | + @cached_property |
| 95 | + def action(self) -> str: |
| 96 | + """Last part of enum value |
| 97 | +
|
| 98 | + - "d" for event "a:b:c:d" |
| 99 | + - "baz" for event "foo:bar:baz" |
| 100 | + - "tata" for event "toto:tata" |
| 101 | + """ |
| 102 | + return self._parts[-1] |
| 103 | + |
| 104 | + |
| 105 | +class EventKind(StrEnum): |
| 106 | + """event.kind values defined by ECS""" |
| 107 | + |
| 108 | + # https://www.elastic.co/docs/reference/ecs/ecs-allowed-values-event-kind |
| 109 | + EVENT = "event" |
| 110 | + |
| 111 | + |
| 112 | +class EventCategory(StrEnum): |
| 113 | + """event.category values defined by ECS""" |
| 114 | + |
| 115 | + # https://www.elastic.co/docs/reference/ecs/ecs-allowed-values-event-category |
| 116 | + AUTHENTICATION = "authentication" |
| 117 | + SESSION = "session" |
| 118 | + DATABASE = "database" |
| 119 | + FILE = "file" |
| 120 | + IAM = "iam" |
| 121 | + CONFIGURATION = "configuration" |
| 122 | + WEB = "web" |
| 123 | + |
| 124 | + |
| 125 | +class EventType(StrEnum): |
| 126 | + """event.type values defined by ECS""" |
| 127 | + |
| 128 | + # https://www.elastic.co/docs/reference/ecs/ecs-allowed-values-event-type |
| 129 | + START = "start" |
| 130 | + END = "end" |
| 131 | + INFO = "info" |
| 132 | + ACCESS = "access" |
| 133 | + CHANGE = "change" |
| 134 | + CREATION = "creation" |
| 135 | + DELETION = "deletion" |
| 136 | + DENIED = "denied" |
| 137 | + |
| 138 | + |
| 139 | +class EventOutcome(StrEnum): |
| 140 | + """event.outcome values defined by ECS""" |
| 141 | + |
| 142 | + # https://www.elastic.co/docs/reference/ecs/ecs-allowed-values-event-outcome |
| 143 | + SUCCESS = "success" |
| 144 | + FAILURE = "failure" |
| 145 | + UNKNOWN = "unknown" |
0 commit comments