howler-api 2.13.0.dev329__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of howler-api might be problematic. Click here for more details.

Files changed (200) hide show
  1. howler/__init__.py +0 -0
  2. howler/actions/__init__.py +167 -0
  3. howler/actions/add_label.py +111 -0
  4. howler/actions/add_to_bundle.py +159 -0
  5. howler/actions/change_field.py +76 -0
  6. howler/actions/demote.py +160 -0
  7. howler/actions/example_plugin.py +104 -0
  8. howler/actions/prioritization.py +93 -0
  9. howler/actions/promote.py +147 -0
  10. howler/actions/remove_from_bundle.py +133 -0
  11. howler/actions/remove_label.py +111 -0
  12. howler/actions/transition.py +200 -0
  13. howler/api/__init__.py +249 -0
  14. howler/api/base.py +88 -0
  15. howler/api/socket.py +114 -0
  16. howler/api/v1/__init__.py +97 -0
  17. howler/api/v1/action.py +372 -0
  18. howler/api/v1/analytic.py +748 -0
  19. howler/api/v1/auth.py +382 -0
  20. howler/api/v1/borealis.py +101 -0
  21. howler/api/v1/configs.py +55 -0
  22. howler/api/v1/dossier.py +222 -0
  23. howler/api/v1/help.py +28 -0
  24. howler/api/v1/hit.py +1181 -0
  25. howler/api/v1/notebook.py +82 -0
  26. howler/api/v1/overview.py +191 -0
  27. howler/api/v1/search.py +715 -0
  28. howler/api/v1/template.py +206 -0
  29. howler/api/v1/tool.py +183 -0
  30. howler/api/v1/user.py +414 -0
  31. howler/api/v1/utils/__init__.py +0 -0
  32. howler/api/v1/utils/etag.py +84 -0
  33. howler/api/v1/view.py +288 -0
  34. howler/app.py +235 -0
  35. howler/common/README.md +144 -0
  36. howler/common/__init__.py +0 -0
  37. howler/common/classification.py +979 -0
  38. howler/common/classification.yml +107 -0
  39. howler/common/exceptions.py +167 -0
  40. howler/common/hexdump.py +48 -0
  41. howler/common/iprange.py +171 -0
  42. howler/common/loader.py +154 -0
  43. howler/common/logging/__init__.py +241 -0
  44. howler/common/logging/audit.py +138 -0
  45. howler/common/logging/format.py +38 -0
  46. howler/common/net.py +79 -0
  47. howler/common/net_static.py +1494 -0
  48. howler/common/random_user.py +316 -0
  49. howler/common/swagger.py +117 -0
  50. howler/config.py +64 -0
  51. howler/cronjobs/__init__.py +29 -0
  52. howler/cronjobs/retention.py +61 -0
  53. howler/cronjobs/rules.py +274 -0
  54. howler/cronjobs/view_cleanup.py +88 -0
  55. howler/datastore/README.md +112 -0
  56. howler/datastore/__init__.py +0 -0
  57. howler/datastore/bulk.py +72 -0
  58. howler/datastore/collection.py +2327 -0
  59. howler/datastore/constants.py +117 -0
  60. howler/datastore/exceptions.py +41 -0
  61. howler/datastore/howler_store.py +105 -0
  62. howler/datastore/migrations/fix_process.py +41 -0
  63. howler/datastore/operations.py +130 -0
  64. howler/datastore/schemas.py +90 -0
  65. howler/datastore/store.py +231 -0
  66. howler/datastore/support/__init__.py +0 -0
  67. howler/datastore/support/build.py +214 -0
  68. howler/datastore/support/schemas.py +90 -0
  69. howler/datastore/types.py +22 -0
  70. howler/error.py +91 -0
  71. howler/external/__init__.py +0 -0
  72. howler/external/generate_mitre.py +96 -0
  73. howler/external/generate_sigma_rules.py +31 -0
  74. howler/external/generate_tlds.py +47 -0
  75. howler/external/reindex_data.py +46 -0
  76. howler/external/wipe_databases.py +58 -0
  77. howler/gunicorn_config.py +25 -0
  78. howler/healthz.py +47 -0
  79. howler/helper/__init__.py +0 -0
  80. howler/helper/azure.py +50 -0
  81. howler/helper/discover.py +59 -0
  82. howler/helper/hit.py +236 -0
  83. howler/helper/oauth.py +247 -0
  84. howler/helper/search.py +92 -0
  85. howler/helper/workflow.py +110 -0
  86. howler/helper/ws.py +378 -0
  87. howler/odm/README.md +102 -0
  88. howler/odm/__init__.py +1 -0
  89. howler/odm/base.py +1504 -0
  90. howler/odm/charter.txt +146 -0
  91. howler/odm/helper.py +416 -0
  92. howler/odm/howler_enum.py +25 -0
  93. howler/odm/models/__init__.py +0 -0
  94. howler/odm/models/action.py +33 -0
  95. howler/odm/models/analytic.py +90 -0
  96. howler/odm/models/assemblyline.py +48 -0
  97. howler/odm/models/aws.py +23 -0
  98. howler/odm/models/azure.py +16 -0
  99. howler/odm/models/cbs.py +44 -0
  100. howler/odm/models/config.py +558 -0
  101. howler/odm/models/dossier.py +33 -0
  102. howler/odm/models/ecs/__init__.py +0 -0
  103. howler/odm/models/ecs/agent.py +17 -0
  104. howler/odm/models/ecs/autonomous_system.py +16 -0
  105. howler/odm/models/ecs/client.py +149 -0
  106. howler/odm/models/ecs/cloud.py +141 -0
  107. howler/odm/models/ecs/code_signature.py +27 -0
  108. howler/odm/models/ecs/container.py +32 -0
  109. howler/odm/models/ecs/dns.py +62 -0
  110. howler/odm/models/ecs/egress.py +10 -0
  111. howler/odm/models/ecs/elf.py +74 -0
  112. howler/odm/models/ecs/email.py +122 -0
  113. howler/odm/models/ecs/error.py +14 -0
  114. howler/odm/models/ecs/event.py +140 -0
  115. howler/odm/models/ecs/faas.py +24 -0
  116. howler/odm/models/ecs/file.py +84 -0
  117. howler/odm/models/ecs/geo.py +30 -0
  118. howler/odm/models/ecs/group.py +18 -0
  119. howler/odm/models/ecs/hash.py +16 -0
  120. howler/odm/models/ecs/host.py +17 -0
  121. howler/odm/models/ecs/http.py +37 -0
  122. howler/odm/models/ecs/ingress.py +12 -0
  123. howler/odm/models/ecs/interface.py +21 -0
  124. howler/odm/models/ecs/network.py +30 -0
  125. howler/odm/models/ecs/observer.py +45 -0
  126. howler/odm/models/ecs/organization.py +12 -0
  127. howler/odm/models/ecs/os.py +21 -0
  128. howler/odm/models/ecs/pe.py +17 -0
  129. howler/odm/models/ecs/process.py +216 -0
  130. howler/odm/models/ecs/registry.py +26 -0
  131. howler/odm/models/ecs/related.py +45 -0
  132. howler/odm/models/ecs/rule.py +51 -0
  133. howler/odm/models/ecs/server.py +24 -0
  134. howler/odm/models/ecs/threat.py +247 -0
  135. howler/odm/models/ecs/tls.py +58 -0
  136. howler/odm/models/ecs/url.py +51 -0
  137. howler/odm/models/ecs/user.py +57 -0
  138. howler/odm/models/ecs/user_agent.py +20 -0
  139. howler/odm/models/ecs/vulnerability.py +41 -0
  140. howler/odm/models/gcp.py +16 -0
  141. howler/odm/models/hit.py +356 -0
  142. howler/odm/models/howler_data.py +328 -0
  143. howler/odm/models/lead.py +33 -0
  144. howler/odm/models/localized_label.py +13 -0
  145. howler/odm/models/overview.py +16 -0
  146. howler/odm/models/pivot.py +40 -0
  147. howler/odm/models/template.py +24 -0
  148. howler/odm/models/user.py +83 -0
  149. howler/odm/models/view.py +34 -0
  150. howler/odm/random_data.py +888 -0
  151. howler/odm/randomizer.py +606 -0
  152. howler/patched.py +5 -0
  153. howler/plugins/__init__.py +25 -0
  154. howler/plugins/config.py +123 -0
  155. howler/remote/__init__.py +0 -0
  156. howler/remote/datatypes/README.md +355 -0
  157. howler/remote/datatypes/__init__.py +98 -0
  158. howler/remote/datatypes/counters.py +63 -0
  159. howler/remote/datatypes/events.py +66 -0
  160. howler/remote/datatypes/hash.py +206 -0
  161. howler/remote/datatypes/lock.py +42 -0
  162. howler/remote/datatypes/queues/__init__.py +0 -0
  163. howler/remote/datatypes/queues/comms.py +59 -0
  164. howler/remote/datatypes/queues/multi.py +32 -0
  165. howler/remote/datatypes/queues/named.py +93 -0
  166. howler/remote/datatypes/queues/priority.py +215 -0
  167. howler/remote/datatypes/set.py +118 -0
  168. howler/remote/datatypes/user_quota_tracker.py +54 -0
  169. howler/security/__init__.py +253 -0
  170. howler/security/socket.py +108 -0
  171. howler/security/utils.py +185 -0
  172. howler/services/__init__.py +0 -0
  173. howler/services/action_service.py +111 -0
  174. howler/services/analytic_service.py +128 -0
  175. howler/services/auth_service.py +323 -0
  176. howler/services/config_service.py +128 -0
  177. howler/services/dossier_service.py +252 -0
  178. howler/services/event_service.py +93 -0
  179. howler/services/hit_service.py +893 -0
  180. howler/services/jwt_service.py +158 -0
  181. howler/services/lucene_service.py +286 -0
  182. howler/services/notebook_service.py +119 -0
  183. howler/services/overview_service.py +44 -0
  184. howler/services/template_service.py +45 -0
  185. howler/services/user_service.py +330 -0
  186. howler/utils/__init__.py +0 -0
  187. howler/utils/annotations.py +28 -0
  188. howler/utils/chunk.py +38 -0
  189. howler/utils/dict_utils.py +200 -0
  190. howler/utils/isotime.py +17 -0
  191. howler/utils/list_utils.py +11 -0
  192. howler/utils/lucene.py +77 -0
  193. howler/utils/path.py +27 -0
  194. howler/utils/socket_utils.py +61 -0
  195. howler/utils/str_utils.py +256 -0
  196. howler/utils/uid.py +47 -0
  197. howler_api-2.13.0.dev329.dist-info/METADATA +71 -0
  198. howler_api-2.13.0.dev329.dist-info/RECORD +200 -0
  199. howler_api-2.13.0.dev329.dist-info/WHEEL +4 -0
  200. howler_api-2.13.0.dev329.dist-info/entry_points.txt +8 -0
howler/helper/ws.py ADDED
@@ -0,0 +1,378 @@
1
+ # Taken from https://pypi.org/project/simple-websocket/
2
+
3
+ import selectors
4
+ from time import time
5
+
6
+ from wsproto import ConnectionType, WSConnection
7
+ from wsproto.events import (
8
+ AcceptConnection,
9
+ BytesMessage,
10
+ CloseConnection,
11
+ Message,
12
+ Ping,
13
+ Pong,
14
+ Request,
15
+ TextMessage,
16
+ )
17
+ from wsproto.extensions import PerMessageDeflate
18
+ from wsproto.frame_protocol import CloseReason
19
+ from wsproto.utilities import LocalProtocolError
20
+
21
+
22
+ class ConnectionError(RuntimeError): # pragma: no cover
23
+ """Connection error exception class."""
24
+
25
+ def __init__(self, status_code=None):
26
+ self.status_code = status_code
27
+ super().__init__(f"Connection error: {status_code}")
28
+
29
+
30
+ class ConnectionClosed(RuntimeError):
31
+ """Connection closed exception class."""
32
+
33
+ def __init__(self, reason=CloseReason.NO_STATUS_RCVD, message=None):
34
+ self.reason = reason
35
+ self.message = message
36
+ super().__init__(f'Connection closed: {reason} {message or ""}')
37
+
38
+
39
+ class Base:
40
+ def __init__(
41
+ self,
42
+ sock=None,
43
+ connection_type=None,
44
+ receive_bytes=4096,
45
+ ping_interval=None,
46
+ max_message_size=None,
47
+ thread_class=None,
48
+ event_class=None,
49
+ selector_class=None,
50
+ ):
51
+ #: The name of the subprotocol chosen for the WebSocket connection.
52
+ self.subprotocol = None
53
+
54
+ self.sock = sock
55
+ self.receive_bytes = receive_bytes
56
+ self.ping_interval = ping_interval
57
+ self.max_message_size = max_message_size
58
+ self.pong_received = True
59
+ self.input_buffer = []
60
+ self.incoming_message = None
61
+ self.incoming_message_len = 0
62
+ self.connected = False
63
+ self.is_server = connection_type == ConnectionType.SERVER
64
+ self.close_reason = CloseReason.NO_STATUS_RCVD
65
+ self.close_message = None
66
+
67
+ if thread_class is None:
68
+ import threading
69
+
70
+ thread_class = threading.Thread
71
+ if event_class is None: # pragma: no branch
72
+ import threading
73
+
74
+ event_class = threading.Event
75
+ if selector_class is None:
76
+ selector_class = selectors.DefaultSelector
77
+ self.selector_class = selector_class
78
+ self.event = event_class()
79
+
80
+ self.ws = WSConnection(connection_type)
81
+ self.handshake()
82
+
83
+ if not self.connected: # pragma: no cover
84
+ raise ConnectionError()
85
+ self.thread = thread_class(target=self._thread)
86
+ self.thread.start()
87
+
88
+ def handshake(self): # pragma: no cover
89
+ # to be implemented by subclasses
90
+ pass
91
+
92
+ def send(self, data):
93
+ """Send data over the WebSocket connection.
94
+
95
+ :param data: The data to send. If ``data`` is of type ``bytes``, then
96
+ a binary message is sent. Else, the message is sent in
97
+ text format.
98
+ """
99
+ if not self.connected:
100
+ raise ConnectionClosed(self.close_reason, self.close_message)
101
+ if isinstance(data, bytes):
102
+ out_data = self.ws.send(Message(data=data))
103
+ else:
104
+ out_data = self.ws.send(TextMessage(data=str(data)))
105
+ self.sock.send(out_data)
106
+
107
+ def receive(self, timeout=None):
108
+ """Receive data over the WebSocket connection.
109
+
110
+ :param timeout: Amount of time to wait for the data, in seconds. Set
111
+ to ``None`` (the default) to wait indefinitely. Set
112
+ to 0 to read without blocking.
113
+
114
+ The data received is returned, as ``bytes`` or ``str``, depending on
115
+ the type of the incoming message.
116
+ """
117
+ while self.connected and not self.input_buffer:
118
+ if not self.event.wait(timeout=timeout):
119
+ return None
120
+ self.event.clear()
121
+ if not self.connected: # pragma: no cover
122
+ raise ConnectionClosed(self.close_reason, self.close_message)
123
+ return self.input_buffer.pop(0)
124
+
125
+ def close(self, reason=None, message=None):
126
+ """Close the WebSocket connection.
127
+
128
+ :param reason: A numeric status code indicating the reason of the
129
+ closure, as defined by the WebSocket specification. The
130
+ default is 1000 (normal closure).
131
+ :param message: A text message to be sent to the other side.
132
+ """
133
+ if not self.connected:
134
+ raise ConnectionClosed(self.close_reason, self.close_message)
135
+ out_data = self.ws.send(CloseConnection(reason or CloseReason.NORMAL_CLOSURE, message))
136
+ try:
137
+ self.sock.send(out_data)
138
+ except BrokenPipeError: # pragma: no cover
139
+ pass
140
+ self.connected = False
141
+
142
+ def choose_subprotocol(self, request): # pragma: no cover
143
+ # The method should return the subprotocol to use, or ``None`` if no
144
+ # subprotocol is chosen. Can be overridden by subclasses that implement
145
+ # the server-side of the WebSocket protocol.
146
+ return None
147
+
148
+ def _thread(self):
149
+ sel = None
150
+ if self.ping_interval:
151
+ next_ping = time() + self.ping_interval
152
+ sel = self.selector_class()
153
+ sel.register(self.sock, selectors.EVENT_READ, True)
154
+
155
+ while self.connected:
156
+ try:
157
+ if sel:
158
+ now = time()
159
+ if next_ping <= now or not sel.select(next_ping - now):
160
+ # we reached the timeout, we have to send a ping
161
+ if not self.pong_received:
162
+ self.close(
163
+ reason=CloseReason.POLICY_VIOLATION,
164
+ message="Ping/Pong timeout",
165
+ )
166
+ break
167
+ self.pong_received = False
168
+ self.sock.send(self.ws.send(Ping()))
169
+ next_ping = max(now, next_ping) + self.ping_interval
170
+ continue
171
+ in_data = self.sock.recv(self.receive_bytes)
172
+ if len(in_data) == 0:
173
+ raise OSError() # noqa: TRY301
174
+ except (
175
+ OSError,
176
+ ConnectionResetError,
177
+ # CCCS EDIT: Not including this exception causes uncaught errors in the thread
178
+ LocalProtocolError,
179
+ ): # pragma: no cover
180
+ self.connected = False
181
+ self.event.set()
182
+ break
183
+
184
+ self.ws.receive_data(in_data)
185
+ self.connected = self._handle_events()
186
+ sel.close() if sel else None
187
+ self.sock.close()
188
+
189
+ def _handle_events(self):
190
+ keep_going = True
191
+ out_data = b""
192
+ for event in self.ws.events():
193
+ try:
194
+ if isinstance(event, Request):
195
+ self.subprotocol = self.choose_subprotocol(event)
196
+ out_data += self.ws.send(
197
+ AcceptConnection(
198
+ subprotocol=self.subprotocol,
199
+ extensions=[PerMessageDeflate()],
200
+ )
201
+ )
202
+ elif isinstance(event, CloseConnection):
203
+ if self.is_server:
204
+ out_data += self.ws.send(event.response())
205
+ self.close_reason = event.code # type: ignore
206
+ self.close_message = event.reason
207
+ self.connected = False
208
+ self.event.set()
209
+ keep_going = False
210
+ elif isinstance(event, Ping):
211
+ out_data += self.ws.send(event.response())
212
+ elif isinstance(event, Pong):
213
+ self.pong_received = True
214
+ elif isinstance(event, (TextMessage, BytesMessage)):
215
+ self.incoming_message_len += len(event.data)
216
+ if self.max_message_size and self.incoming_message_len > self.max_message_size:
217
+ out_data += self.ws.send(CloseConnection(CloseReason.MESSAGE_TOO_BIG, "Message is too big"))
218
+ self.event.set()
219
+ keep_going = False
220
+ break
221
+ if self.incoming_message is None:
222
+ # store message as is first
223
+ # if it is the first of a group, the message will be
224
+ # converted to bytearray on arrival of the second
225
+ # part, since bytearrays are mutable and can be
226
+ # concatenated more efficiently
227
+ self.incoming_message = event.data
228
+ elif isinstance(event, TextMessage):
229
+ if not isinstance(self.incoming_message, bytearray):
230
+ # convert to bytearray and append
231
+ self.incoming_message = bytearray((self.incoming_message + event.data).encode())
232
+ else:
233
+ # append to bytearray
234
+ self.incoming_message += event.data.encode()
235
+ else:
236
+ if not isinstance(self.incoming_message, bytearray):
237
+ # convert to mutable bytearray and append
238
+ self.incoming_message = bytearray(self.incoming_message + event.data)
239
+ else:
240
+ # append to bytearray
241
+ self.incoming_message += event.data
242
+ if not event.message_finished: # type: ignore
243
+ continue
244
+ if isinstance(self.incoming_message, (str, bytes)):
245
+ # single part message
246
+ self.input_buffer.append(self.incoming_message)
247
+ elif isinstance(event, TextMessage):
248
+ # convert multi-part message back to text
249
+ self.input_buffer.append(self.incoming_message.decode())
250
+ else:
251
+ # convert multi-part message back to bytes
252
+ self.input_buffer.append(bytes(self.incoming_message))
253
+ self.incoming_message = None
254
+ self.incoming_message_len = 0
255
+ self.event.set()
256
+ else: # pragma: no cover
257
+ pass
258
+ except LocalProtocolError: # pragma: no cover
259
+ out_data = b""
260
+ self.event.set()
261
+ keep_going = False
262
+ if out_data:
263
+ self.sock.send(out_data)
264
+ return keep_going
265
+
266
+
267
+ class Server(Base):
268
+ """This class implements a WebSocket server.
269
+
270
+ :param environ: A WSGI ``environ`` dictionary with the request details.
271
+ Among other things, this class expects to find the
272
+ low-level network socket for the connection somewhere in
273
+ this dictionary. Since the WSGI specification does not
274
+ cover where or how to store this socket, each web server
275
+ does this in its own different way. Werkzeug, Gunicorn,
276
+ Eventlet and Gevent are the only web servers that are
277
+ currently supported.
278
+ :param subprotocols: A list of supported subprotocols, or ``None`` (the
279
+ default) to disable subprotocol negotiation.
280
+ :param receive_bytes: The size of the receive buffer, in bytes. The
281
+ default is 4096.
282
+ :param ping_interval: Send ping packets to clients at the requested
283
+ interval in seconds. Set to ``None`` (the default) to
284
+ disable ping/pong logic. Enable to prevent
285
+ disconnections when the line is idle for a certain
286
+ amount of time, or to detect unresponsive clients and
287
+ disconnect them. A recommended interval is 25
288
+ seconds.
289
+ :param max_message_size: The maximum size allowed for a message, in bytes,
290
+ or ``None`` for no limit. The default is ``None``.
291
+ :param thread_class: The ``Thread`` class to use when creating background
292
+ threads. The default is the ``threading.Thread``
293
+ class from the Python standard library.
294
+ :param event_class: The ``Event`` class to use when creating event
295
+ objects. The default is the `threading.Event`` class
296
+ from the Python standard library.
297
+ :param selector_class: The ``Selector`` class to use when creating
298
+ selectors. The default is the
299
+ ``selectors.DefaultSelector`` class from the Python
300
+ standard library.
301
+ """
302
+
303
+ def __init__(
304
+ self,
305
+ environ,
306
+ subprotocols=None,
307
+ receive_bytes=4096,
308
+ ping_interval=None,
309
+ max_message_size=None,
310
+ thread_class=None,
311
+ event_class=None,
312
+ selector_class=None,
313
+ ):
314
+ self.environ = environ
315
+ self.subprotocols = subprotocols or []
316
+ if isinstance(self.subprotocols, str):
317
+ self.subprotocols = [self.subprotocols]
318
+ self.mode = "unknown"
319
+ sock = None
320
+ if "werkzeug.socket" in environ:
321
+ # extract socket from Werkzeug's WSGI environment
322
+ sock = environ.get("werkzeug.socket")
323
+ self.mode = "werkzeug"
324
+ elif "gunicorn.socket" in environ:
325
+ # extract socket from Gunicorn WSGI environment
326
+ sock = environ.get("gunicorn.socket")
327
+ self.mode = "gunicorn"
328
+ elif "eventlet.input" in environ: # pragma: no cover
329
+ # extract socket from Eventlet's WSGI environment
330
+ sock = environ.get("eventlet.input").get_socket()
331
+ self.mode = "eventlet"
332
+ elif environ.get("SERVER_SOFTWARE", "").startswith("gevent"): # pragma: no cover
333
+ # extract socket from Gevent's WSGI environment
334
+ wsgi_input = environ["wsgi.input"]
335
+ if not hasattr(wsgi_input, "raw") and hasattr(wsgi_input, "rfile"):
336
+ wsgi_input = wsgi_input.rfile
337
+ if hasattr(wsgi_input, "raw"):
338
+ sock = wsgi_input.raw._sock
339
+ self.mode = "gevent"
340
+ if sock is None:
341
+ raise RuntimeError("Cannot obtain socket from WSGI environment.")
342
+ super().__init__(
343
+ sock,
344
+ connection_type=ConnectionType.SERVER,
345
+ receive_bytes=receive_bytes,
346
+ ping_interval=ping_interval,
347
+ max_message_size=max_message_size,
348
+ thread_class=thread_class,
349
+ event_class=event_class,
350
+ selector_class=selector_class,
351
+ )
352
+
353
+ def handshake(self):
354
+ in_data = b"GET / HTTP/1.1\r\n"
355
+ for key, value in self.environ.items():
356
+ if key.startswith("HTTP_"):
357
+ header = "-".join([p.capitalize() for p in key[5:].split("_")])
358
+ in_data += f"{header}: {value}\r\n".encode()
359
+ in_data += b"\r\n"
360
+ self.ws.receive_data(in_data)
361
+ self.connected = self._handle_events()
362
+
363
+ def choose_subprotocol(self, request):
364
+ """Choose a subprotocol to use for the WebSocket connection.
365
+
366
+ The default implementation selects the first protocol requested by the
367
+ client that is accepted by the server. Subclasses can override this
368
+ method to implement a different subprotocol negotiation algorithm.
369
+
370
+ :param request: A ``Request`` object.
371
+
372
+ The method should return the subprotocol to use, or ``None`` if no
373
+ subprotocol is chosen.
374
+ """
375
+ for subprotocol in request.subprotocols:
376
+ if subprotocol in self.subprotocols:
377
+ return subprotocol
378
+ return None
howler/odm/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # Object Data Model (ODM) Support
2
+
3
+ To ensure that the data in your application is always of the right type and is always saved in a normalize way, you can use the ODM to define how your data is structured. The ODM also works in conjunction with the datastore to automatically create associated Elasticsearch indices that will match your data and provide you with the best search experience.
4
+
5
+ ## Define a new Model
6
+
7
+ When defining a new model object to be used in the system, you must create a class the inherit from the `odm.Model` class and use the `@odm.model()` decorator to set some default class parameters. Each parameters of your model object has to be of type `odm._Field`. You can find out about the different types of field in a section below.
8
+
9
+ Here's example of a user model with settings and stats:
10
+
11
+ ```python
12
+ from howler import odm
13
+
14
+ @odm.model(index=True, store=False, description="Settings of user")
15
+ class Settings(odm.Model):
16
+ default_view: str = odm.Enum(value=['detail', 'simple'], default='simple', description="Some random setting")
17
+
18
+ @odm.model(index=True, store=False, description="Settings of user")
19
+ class Stats(odm.Model):
20
+ last_login: str = odm.Date(default='NOW', description="Last time user logged in")
21
+ login_count: str = odm.Integer(default=0, description="Number of time the user logged in")
22
+
23
+ @odm.model(index=True, store=True, description="User example")
24
+ class User(odm.Model):
25
+ username: str = odm.Keyword(description="Username of the user")
26
+ password: str = odm.Keyword(description="Password of the user")
27
+ settings: Settings = odm.Compound(Settings, default={}, description="User's settings")
28
+ stats: Stats = odm.Compound(Stats, default={}, description="User's statistics")
29
+ ```
30
+
31
+ As a YAML representation, this model would look like this:
32
+
33
+ ```yaml
34
+ username: ...
35
+ password: ...
36
+ settings:
37
+ default_view: simple
38
+ stats:
39
+ last_login: '2022-06-21T03:33:37.452270Z'
40
+ login_count: 0
41
+ ```
42
+
43
+ ### Model class decorator options
44
+
45
+ There are 3 options you can pass to the object class decorator:
46
+
47
+ - `index`: Default index value for the field inside the object class
48
+ - `store`: Default store value for the field inside the object class
49
+ - `description`: Description of the object class (used by auto markdown documentation)
50
+
51
+ ### Generic field options
52
+
53
+ There are 5 generic options that all fields can take:
54
+
55
+ - `index`: Should Elastic index the values of that field (inherit from class default if not set)
56
+ - `store`: Should the value of that field be returned in the default search response (inherit from class default if not set)
57
+ - `copyto`: Which field to copy the value into for easier search
58
+ - `default`: Default value for this field
59
+ - `description`: Description of the field (used by auto markdown documentation)
60
+
61
+ ***Note***: Some fields that are more complex may use options.
62
+
63
+ ### Supported field types
64
+
65
+ Here is the list of supported field type and their extra options if any:
66
+
67
+ - `odm.Date`: A field storing an ISO date (if the default value is set to NOW, it will be the time the field get created)
68
+ - `odm.Boolean`: A field storing a boolean and is normalized using the python `bool()` function.
69
+ - `odm.Keyword`: A field storing a string with strict search values and is normalized using the `str()` function.
70
+ - `odm.EmptyableKeyword`: An `odm.Keyword` field that allow `None` values.
71
+ - `odm.LowerKeyword`: An `odm.Keyword` field that is always saved in lowercase mode.
72
+ - `odm.UpperKeyword`: An `odm.Keyword` field that is always saved in uppercase mode.
73
+ - `odm.ValidatedKeyword(regex)`: An `odm.Keyword` validated by a regular expression.
74
+ - `odm.IP`: A validated IP field stored as IP in Elastic to allow CIDR queries.
75
+ - `odm.Domain`: A validated domain field
76
+ - `odm.Email`: A validated email address field
77
+ - `odm.URI`: A validated URI field
78
+ - `odm.URIPath`: A validated URI path field
79
+ - `odm.MAC`: A validated Mac address field
80
+ - `odm.PhoneNumber`: A validated Phone Number field
81
+ - `odm.SSDeepHash`: A validated SSDeep hash field indexed in two parts to allow proximity searches
82
+ - `odm.SHA1`: A validated SHA1 hash field
83
+ - `odm.SHA256`: A validated SHA256 hash field
84
+ - `odm.MD5`: A validated MD5 hash field
85
+ - `odm.Platform`: A validated Plaform field
86
+ - `odm.Processor`: A validated Processor field
87
+ - `odm.Classification`: A field storing access control classification.
88
+ - `odm.ClassificationString`: A field storing the classification as a string only.
89
+ - `odm.Enum(values)`: A field storing short string form a list of possible values
90
+ - `odm.UUID`: A field storing an auto-generated unique ID if none is provided
91
+ - `odm.Json`: A field storing a JSON serialized string and is normalized using the `json.dumps()` function.
92
+ - `odm.Text`: A field storing human readable text data
93
+ - `odm.IndexText`: A special field with special processing rules to simplify searching.
94
+ - `odm.Integer`: A field storing an integer value.
95
+ - `odm.Float`: A field storing a floating point value.
96
+ - `odm.List(child_object)`: A field storing a sequence of `odm._Field` or `odm.Model`.
97
+ - `odm.Mapping(child_object)`: A field storing a dictionary of `odm._Field`.
98
+ - `odm.FlattenedListObject(child_object)`: An `odm.Mapping` field storing a list of flattened `odm.Json` objects.
99
+ - `odm.FlattenedObject(child_object)`: A `odm.Mapping` field storing a flattened `odm.Json` object.
100
+ - `odm.Compound(child_type)`: A field storing a second level `odm.Model` object.
101
+ - `odm.Any`: A field that store the data as is and does not try to validate it. (never indexed, never stored)
102
+ - `odm.Optional(child_object)`: A wrapper field to allow simple types to take None values.
howler/odm/__init__.py ADDED
@@ -0,0 +1 @@
1
+ from howler.odm.base import * # noqa: F403