-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcore_definitions.py
More file actions
50 lines (30 loc) · 2.07 KB
/
core_definitions.py
File metadata and controls
50 lines (30 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""Core enumerations and structures used throughout INTERSECT, for both client and service."""
from enum import Enum
from typing import Annotated, Literal
from pydantic import Field
from .constants import MIME_TYPE_REGEX
class IntersectDataHandler(Enum):
"""What data transfer type do you want to use for handling the request/response?
Default: MESSAGE
"""
MESSAGE = 'MESSAGE'
MINIO = 'MINIO'
IntersectMimeType = Annotated[str, Field(pattern=MIME_TYPE_REGEX)]
"""
Special typing which represents a "Content-Type" value (i.e. `application/json`).
The value should be a MIME type; references can be found at:
- https://www.iana.org/assignments/media-types/media-types.xhtml
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
These values are used to help map an output (or a part of an output) from an arbitrary microservice to an input (or a part of an input) of another arbitrary microservice.
In general, mime types follow one of two rules:
- Complex types (types which cannot be represented as a sequence of bytes) MUST be represented by a Content-Type of 'application/json' (this is default).
If a complex type has binary data in a field, this field MUST be Base64 encoded.
You can mark the type with either 'pydantic.Base64Bytes', or if you need the value to be URL safe, 'pydantic.Base64UrlBytes'. You MUST also specify the "contentType" property, like this:
```
field: Annotated[pydantic.Base64Bytes, pydantic.Field(json_schema_extra={"contentType": "image/png"})]
```
INTERSECT is able to handle serialization/deserialization of 'application/json' types for you, though note that you will need to verify binary data (incoming and outgoing) yourself. INTERSECT will handle the Base64 encoding/decoding, though.
- If your Content-Type value is ANYTHING ELSE, you MUST mark it as "bytes" . In this instance, INTERSECT will not base64-encode or base64-decode the value.
"""
IntersectEncryptionScheme = Literal['NONE', 'RSA']
"""Supported encryption schemes throughout INTERSECT. 'NONE' implies no encryption scheme."""