atlan-application-sdk-api 3.58.1__tar.gz → 3.59.0__tar.gz
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.
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/PKG-INFO +2 -2
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/clients/sql.py +132 -5
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/common/sql_filters.py +52 -9
- atlan_application_sdk_api-3.59.0/application_sdk/common/sql_filters_errors.py +34 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/constants.py +2 -1
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/handler/object_routes.py +296 -14
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/handler/request_contract.py +3 -3
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/version.py +2 -2
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/pyproject.toml +2 -2
- atlan_application_sdk_api-3.58.1/application_sdk/common/sql_filters_errors.py +0 -17
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/.gitignore +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/README.md +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/api-files.txt +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/__init__.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/_build_info.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/_context_errors.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/_deprecation.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/_env.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/_install.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/_logging.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/_obstore_config.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/_runtime/__init__.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/_runtime/cgroup.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/_runtime/offload.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/_runtime/progress.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/clients/__init__.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/clients/_interface.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/clients/_sql_failure_classifier.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/clients/base.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/clients/http_errors.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/clients/models.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/clients/sql_errors.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/clients/sql_typecasters.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/clients/ssl_utils.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/common/__init__.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/common/_generated_tree.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/common/_listing.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/common/aws_utils.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/common/aws_utils_errors.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/common/backoff.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/common/build_identity.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/common/concurrency.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/common/errors.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/common/filter_matching.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/common/logger.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/common/models.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/common/ssl_utils.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/common/task_queue.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/common/types.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/common/utils.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/contracts/__init__.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/contracts/base.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/contracts/events.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/contracts/types.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/contracts/types_errors.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/credentials/__init__.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/credentials/errors.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/credentials/extra.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/credentials/ingress.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/credentials/ref.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/credentials/requirements.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/credentials/spec.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/credentials/types.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/credentials/utils.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/errors/__init__.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/errors/_legacy_codes.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/errors/base.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/errors/categories.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/errors/http.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/errors/leaves.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/errors/wire.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/handler/__init__.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/handler/_dispatch.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/handler/_warmup.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/handler/asgi.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/handler/base.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/handler/context.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/handler/contracts.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/handler/manifest.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/handler/metadata_routes.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/handler/routes.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/handler/service_errors.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/server/__init__.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/server/fastapi/models.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/templates/__init__.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/templates/contracts/__init__.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/templates/contracts/base_metadata_extraction.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/templates/contracts/incremental_sql.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/templates/contracts/sql_metadata.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/templates/contracts/sql_query.py +0 -0
- {atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/hatch_build.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: atlan-application-sdk-api
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.59.0
|
|
4
4
|
Summary: Experimental: the handler surface of the Atlan Application SDK, for the consolidated API host
|
|
5
5
|
Project-URL: Homepage, https://github.com/atlanhq/application-sdk
|
|
6
6
|
Project-URL: Source, https://github.com/atlanhq/application-sdk/tree/main/packages/api
|
|
@@ -35,7 +35,7 @@ Provides-Extra: pandas
|
|
|
35
35
|
Requires-Dist: pandas<4.0.0,>=2.2.3; extra == 'pandas'
|
|
36
36
|
Provides-Extra: pyatlan
|
|
37
37
|
Requires-Dist: authlib<2,>=1.9.9; extra == 'pyatlan'
|
|
38
|
-
Requires-Dist: pyatlan<12,>=11.
|
|
38
|
+
Requires-Dist: pyatlan<12,>=11.8.0; extra == 'pyatlan'
|
|
39
39
|
Provides-Extra: sql
|
|
40
40
|
Requires-Dist: httpx<0.29.0,>=0.27.0; extra == 'sql'
|
|
41
41
|
Requires-Dist: python-dotenv<2.0.0,>=1.2.2; extra == 'sql'
|
{atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/clients/sql.py
RENAMED
|
@@ -12,8 +12,10 @@ import contextvars
|
|
|
12
12
|
import datetime
|
|
13
13
|
import functools
|
|
14
14
|
import hashlib
|
|
15
|
+
import ipaddress
|
|
15
16
|
import math
|
|
16
17
|
import re
|
|
18
|
+
import string
|
|
17
19
|
import threading
|
|
18
20
|
import time
|
|
19
21
|
from collections.abc import AsyncIterator, Callable, Iterator, Mapping
|
|
@@ -684,6 +686,117 @@ def _load_failure(exc: Exception) -> AppError:
|
|
|
684
686
|
return SqlClientConnectUnclassifiedError(cause=exc)
|
|
685
687
|
|
|
686
688
|
|
|
689
|
+
# A DNS name or IPv4 address: dot-separated labels of letters, digits, ``-``
|
|
690
|
+
# and ``_`` (seen in internal names), with an optional trailing dot. Nothing
|
|
691
|
+
# that can end the URL's host part (``/ ? # @ :``) or split it.
|
|
692
|
+
_URL_HOSTNAME = re.compile(r"[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)*\.?")
|
|
693
|
+
_URL_HOSTNAME_MAX_LEN = 253
|
|
694
|
+
|
|
695
|
+
|
|
696
|
+
def _template_fields(template: str) -> frozenset[str]:
|
|
697
|
+
"""The ``{name}`` fields a ``DatabaseConfig.template`` substitutes."""
|
|
698
|
+
return frozenset(
|
|
699
|
+
name for _, name, _, _ in string.Formatter().parse(template) if name
|
|
700
|
+
)
|
|
701
|
+
|
|
702
|
+
|
|
703
|
+
def _is_ipv6_without_zone(text: str) -> bool:
|
|
704
|
+
"""Whether ``text`` is an IPv6 address with no zone id.
|
|
705
|
+
|
|
706
|
+
A zone id (``fe80::1%eth0``) is free text, so it is refused.
|
|
707
|
+
"""
|
|
708
|
+
if "%" in text:
|
|
709
|
+
return False
|
|
710
|
+
try:
|
|
711
|
+
ipaddress.IPv6Address(text)
|
|
712
|
+
except ValueError:
|
|
713
|
+
# Not an address: the caller rejects the host with a typed error.
|
|
714
|
+
# The value itself is form input, so it is not logged.
|
|
715
|
+
logger.debug("Bracketed SQL host is not a valid IPv6 address")
|
|
716
|
+
return False
|
|
717
|
+
return True
|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
def _url_host(value: object) -> str:
|
|
721
|
+
"""Return ``value`` if it is a hostname, IPv4 address or bracketed IPv6.
|
|
722
|
+
|
|
723
|
+
The host cannot be percent-encoded like the other fields: SQLAlchemy's
|
|
724
|
+
URL parser never decodes it, so an encoded host would reach the driver
|
|
725
|
+
still encoded. It is validated instead, so a value carrying ``/`` or
|
|
726
|
+
``?`` cannot end the host part and start a path or query of its own.
|
|
727
|
+
|
|
728
|
+
Raises:
|
|
729
|
+
SqlCredentialsParseError: If ``value`` is none of those. The message
|
|
730
|
+
never quotes the value.
|
|
731
|
+
"""
|
|
732
|
+
host = str(value)
|
|
733
|
+
if host.startswith("[") and host.endswith("]"):
|
|
734
|
+
if _is_ipv6_without_zone(host[1:-1]):
|
|
735
|
+
return host
|
|
736
|
+
elif len(host) <= _URL_HOSTNAME_MAX_LEN and _URL_HOSTNAME.fullmatch(host):
|
|
737
|
+
return host
|
|
738
|
+
raise SqlCredentialsParseError(
|
|
739
|
+
field="host",
|
|
740
|
+
message=(
|
|
741
|
+
"host must be a hostname, an IPv4 address or an IPv6 address in "
|
|
742
|
+
"square brackets, with no scheme, port, path or query"
|
|
743
|
+
),
|
|
744
|
+
)
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
def _url_port(value: object) -> str:
|
|
748
|
+
"""Return ``value`` as a port number between 1 and 65535.
|
|
749
|
+
|
|
750
|
+
Accepts an ``int`` or a string of digits, the shapes a connection form
|
|
751
|
+
sends.
|
|
752
|
+
|
|
753
|
+
Raises:
|
|
754
|
+
SqlCredentialsParseError: If ``value`` is not such a number. The
|
|
755
|
+
message never quotes the value.
|
|
756
|
+
"""
|
|
757
|
+
port: int | None = None
|
|
758
|
+
if isinstance(value, int) and not isinstance(value, bool):
|
|
759
|
+
port = value
|
|
760
|
+
elif isinstance(value, str) and value.isascii() and value.isdigit():
|
|
761
|
+
port = int(value)
|
|
762
|
+
if port is None or not 1 <= port <= 65535:
|
|
763
|
+
raise SqlCredentialsParseError(
|
|
764
|
+
field="port",
|
|
765
|
+
message="port must be a whole number between 1 and 65535",
|
|
766
|
+
)
|
|
767
|
+
return str(port)
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
def _absent(value: object) -> bool:
|
|
771
|
+
"""Whether a required connection value counts as not supplied.
|
|
772
|
+
|
|
773
|
+
``None`` and other falsy values (``""``) do, as before; a numeric ``0``
|
|
774
|
+
does not, so ``port: 0`` reaches ``_url_port`` and is rejected as out of
|
|
775
|
+
range instead of being reported missing.
|
|
776
|
+
"""
|
|
777
|
+
if isinstance(value, int) and not isinstance(value, bool):
|
|
778
|
+
return False
|
|
779
|
+
return not value
|
|
780
|
+
|
|
781
|
+
|
|
782
|
+
def _url_component(param: str, value: object, template_fields: frozenset[str]) -> str:
|
|
783
|
+
"""Make one ``DatabaseConfig.required`` value safe to put in the URL.
|
|
784
|
+
|
|
785
|
+
Every value comes from the connection form, so none may add URL
|
|
786
|
+
structure: ``host`` and ``port`` are validated (see ``_url_host`` and
|
|
787
|
+
``_url_port``); every other field is percent-encoded with ``safe=""``,
|
|
788
|
+
which SQLAlchemy decodes back to the original value whether the field
|
|
789
|
+
sits in the userinfo, the database path or a query value. ``host`` and
|
|
790
|
+
``port`` are only validated when the template uses them; a template that
|
|
791
|
+
builds its target elsewhere (an Oracle DSN) gets the value untouched.
|
|
792
|
+
"""
|
|
793
|
+
if param == "host" and param in template_fields:
|
|
794
|
+
return _url_host(value)
|
|
795
|
+
if param == "port" and param in template_fields:
|
|
796
|
+
return _url_port(value)
|
|
797
|
+
return quote(str(value), safe="")
|
|
798
|
+
|
|
799
|
+
|
|
687
800
|
class BaseSQLClient(ClientInterface):
|
|
688
801
|
"""SQL client for database operations.
|
|
689
802
|
|
|
@@ -1024,6 +1137,11 @@ class BaseSQLClient(ClientInterface):
|
|
|
1024
1137
|
parameters and credentials. It handles different authentication methods
|
|
1025
1138
|
and includes necessary connection parameters.
|
|
1026
1139
|
|
|
1140
|
+
Every ``DB_CONFIG.required`` value is made URL-safe before it is put
|
|
1141
|
+
into ``DB_CONFIG.template``: ``host`` and ``port`` are validated, and
|
|
1142
|
+
every other field is percent-encoded. Pass raw values, not
|
|
1143
|
+
pre-encoded ones, or they will be encoded twice.
|
|
1144
|
+
|
|
1027
1145
|
For ``authType`` ``iam_user`` and ``iam_role`` this is called again
|
|
1028
1146
|
after ``load()``, each time the RDS IAM token it put in the URL is
|
|
1029
1147
|
about to expire and a new connection is opened. It always runs on a
|
|
@@ -1037,6 +1155,9 @@ class BaseSQLClient(ClientInterface):
|
|
|
1037
1155
|
Raises:
|
|
1038
1156
|
SqlClientConfigError: If DB_CONFIG is not set.
|
|
1039
1157
|
MissingSqlParamError: If required connection parameters are missing.
|
|
1158
|
+
SqlCredentialsParseError: If the template uses ``host`` and the
|
|
1159
|
+
value is not a hostname, IPv4 address or bracketed IPv6
|
|
1160
|
+
address, or uses ``port`` and the value is not a port number.
|
|
1040
1161
|
"""
|
|
1041
1162
|
if not self.DB_CONFIG:
|
|
1042
1163
|
raise SqlClientConfigError()
|
|
@@ -1045,16 +1166,22 @@ class BaseSQLClient(ClientInterface):
|
|
|
1045
1166
|
|
|
1046
1167
|
auth_token = self.get_auth_token()
|
|
1047
1168
|
|
|
1048
|
-
# Prepare parameters
|
|
1049
|
-
|
|
1169
|
+
# Prepare parameters. Each value is made URL-safe before it is
|
|
1170
|
+
# substituted (the password already is, by get_auth_token), so a
|
|
1171
|
+
# connection-form value cannot add a driver parameter or override a
|
|
1172
|
+
# pinned default such as sslmode.
|
|
1173
|
+
template_fields = _template_fields(self.DB_CONFIG.template)
|
|
1174
|
+
param_values: dict[str, str] = {}
|
|
1050
1175
|
for param in self.DB_CONFIG.required:
|
|
1051
1176
|
if param == "password":
|
|
1052
1177
|
param_values[param] = auth_token
|
|
1053
1178
|
else:
|
|
1054
|
-
value = self.credentials.get(param)
|
|
1055
|
-
if value
|
|
1179
|
+
value = self.credentials.get(param)
|
|
1180
|
+
if _absent(value):
|
|
1181
|
+
value = extra.get(param)
|
|
1182
|
+
if _absent(value):
|
|
1056
1183
|
raise MissingSqlParamError(field=param)
|
|
1057
|
-
param_values[param] = value
|
|
1184
|
+
param_values[param] = _url_component(param, value, template_fields)
|
|
1058
1185
|
|
|
1059
1186
|
# Fill in base template
|
|
1060
1187
|
conn_str = self.DB_CONFIG.template.format(**param_values)
|
|
@@ -15,7 +15,10 @@ from typing import Any, TypeAlias
|
|
|
15
15
|
import orjson
|
|
16
16
|
|
|
17
17
|
from application_sdk._logging import get_logger
|
|
18
|
-
from application_sdk.common.sql_filters_errors import
|
|
18
|
+
from application_sdk.common.sql_filters_errors import (
|
|
19
|
+
InvalidSqlFilterError,
|
|
20
|
+
InvalidSqlFilterValueError,
|
|
21
|
+
)
|
|
19
22
|
from application_sdk.errors import AppError
|
|
20
23
|
|
|
21
24
|
logger = get_logger(__name__)
|
|
@@ -96,6 +99,10 @@ def strip_sql_block_comments(fragment: str) -> str:
|
|
|
96
99
|
# * ``--`` — SQL line comment (eats the rest of the line)
|
|
97
100
|
# * ``/*`` / ``*/`` — block comment
|
|
98
101
|
# * ``\x00`` — null byte; some drivers truncate on it
|
|
102
|
+
# * a trailing odd run of ``\`` — escapes the template's closing quote
|
|
103
|
+
# in dialects that treat ``\`` as an escape inside literals (MySQL by
|
|
104
|
+
# default), leaving the literal unclosed (FND-5216). An even run is a
|
|
105
|
+
# literal backslash and stays allowed.
|
|
99
106
|
#
|
|
100
107
|
# Regex meta-characters that legitimately appear in filter values
|
|
101
108
|
# (``^``, ``$``, ``.``, ``*``, ``+``, ``?``, ``|``, ``()``, ``[]``, ``\``,
|
|
@@ -178,6 +185,10 @@ def validate_filter_no_sql_injection(v: Any) -> Any:
|
|
|
178
185
|
raise ValueError(
|
|
179
186
|
f"SQL-unsafe sequence {seq!r} not allowed in filter {label}"
|
|
180
187
|
)
|
|
188
|
+
trailing_backslashes = len(value) - len(value.rstrip("\\"))
|
|
189
|
+
if trailing_backslashes % 2:
|
|
190
|
+
# conformance: ignore[E012] Pydantic @field_validator requires ValueError to collect validation errors; any other type bypasses Pydantic's error collection and propagates raw, breaking model instantiation for all callers
|
|
191
|
+
raise ValueError(f"SQL-unsafe trailing backslash in filter {label}")
|
|
181
192
|
|
|
182
193
|
def _check_value(label: str, value: Any, depth: int = 0) -> None:
|
|
183
194
|
if depth > _MAX_FILTER_NESTING_DEPTH:
|
|
@@ -514,6 +525,21 @@ def transform_posix_regex(regex_pattern: str) -> str:
|
|
|
514
525
|
return "|".join(transformed_patterns)
|
|
515
526
|
|
|
516
527
|
|
|
528
|
+
def _reject_unsafe_raw_filter(value: object) -> None:
|
|
529
|
+
"""Run the deny-list and the regex-structure check for a raw-dict caller.
|
|
530
|
+
|
|
531
|
+
The typed contracts run both validators inside Pydantic; the raw helpers
|
|
532
|
+
below run the same pair here. A rejection is re-raised as
|
|
533
|
+
:class:`InvalidSqlFilterValueError` so it carries the ``USER`` audience
|
|
534
|
+
instead of reaching the activity as an unclassified ``ValueError``.
|
|
535
|
+
"""
|
|
536
|
+
try:
|
|
537
|
+
validate_filter_no_sql_injection(value)
|
|
538
|
+
validate_filter_regex_syntax(value)
|
|
539
|
+
except ValueError as e:
|
|
540
|
+
raise InvalidSqlFilterValueError(message=str(e), cause=e) from e
|
|
541
|
+
|
|
542
|
+
|
|
517
543
|
def prepare_query(
|
|
518
544
|
query: str | None,
|
|
519
545
|
workflow_args: dict[str, Any],
|
|
@@ -556,14 +582,25 @@ def prepare_query(
|
|
|
556
582
|
or metadata.get("exclude-table-regex")
|
|
557
583
|
or metadata.get("exclude_table_regex")
|
|
558
584
|
)
|
|
559
|
-
|
|
585
|
+
# Only a value that will be rendered is validated: with no fragment
|
|
586
|
+
# to render into, the value never reaches the SQL, and a caller that
|
|
587
|
+
# checks it elsewhere (with its own error) keeps that verdict.
|
|
588
|
+
if temp_table_regex and temp_table_regex_sql:
|
|
589
|
+
if not isinstance(temp_table_regex, str):
|
|
590
|
+
# A non-string would skip the string checks below and still
|
|
591
|
+
# be stringified into the quoted literal by ``.format``.
|
|
592
|
+
raise InvalidSqlFilterValueError(
|
|
593
|
+
message="temp-table regex must be a string, got "
|
|
594
|
+
f"{type(temp_table_regex).__name__}"
|
|
595
|
+
)
|
|
560
596
|
# Translate legacy quoted-CSV shape to a v3 alternation regex
|
|
561
597
|
# before applying the deny-list. Without this, raw-dict
|
|
562
598
|
# callers (which bypass the typed ``ExtractionInput``
|
|
563
599
|
# validators) still trip on migrated workflow specs.
|
|
564
600
|
temp_table_regex = normalize_legacy_filter_value(temp_table_regex)
|
|
565
|
-
|
|
566
|
-
|
|
601
|
+
# FND-5216: the deny-list plus the structural check the typed
|
|
602
|
+
# contracts run.
|
|
603
|
+
_reject_unsafe_raw_filter(temp_table_regex)
|
|
567
604
|
temp_table_regex_sql = strip_sql_block_comments(
|
|
568
605
|
temp_table_regex_sql
|
|
569
606
|
).format(exclude_table_regex=temp_table_regex)
|
|
@@ -616,6 +653,10 @@ def prepare_query(
|
|
|
616
653
|
exclude_empty_tables=exclude_empty_tables,
|
|
617
654
|
exclude_views=exclude_views,
|
|
618
655
|
)
|
|
656
|
+
except InvalidSqlFilterValueError:
|
|
657
|
+
# The customer's filter was refused: surface it with its USER
|
|
658
|
+
# audience rather than collapse it into the ``None`` return below.
|
|
659
|
+
raise
|
|
619
660
|
except AppError as e:
|
|
620
661
|
error_message = str(e).split(": ", 1)[-1] if ": " in str(e) else str(e)
|
|
621
662
|
logger.warning(
|
|
@@ -650,7 +691,7 @@ async def get_database_names(
|
|
|
650
691
|
if isinstance(raw_include, str):
|
|
651
692
|
raw_include = normalize_legacy_filter_value(raw_include)
|
|
652
693
|
if isinstance(raw_include, (str, dict)):
|
|
653
|
-
|
|
694
|
+
_reject_unsafe_raw_filter(raw_include)
|
|
654
695
|
database_names = parse_filter_input(raw_include)
|
|
655
696
|
|
|
656
697
|
database_names = [
|
|
@@ -717,20 +758,22 @@ def prepare_filters(
|
|
|
717
758
|
# as a JSONDecodeError instead of the SQL-unsafe ValueError).
|
|
718
759
|
# HYP-1560: normalise legacy quoted-CSV strings first so migrated
|
|
719
760
|
# workflow specs surviving the v3.13 SDK bump still validate.
|
|
761
|
+
# FND-5216: each deny-list call is paired with the regex-structure check
|
|
762
|
+
# the typed contracts run, so both paths refuse the same input.
|
|
720
763
|
if isinstance(include_filter_str, str):
|
|
721
764
|
include_filter_str = normalize_legacy_filter_value(include_filter_str)
|
|
722
|
-
|
|
765
|
+
_reject_unsafe_raw_filter(include_filter_str)
|
|
723
766
|
if isinstance(exclude_filter_str, str):
|
|
724
767
|
exclude_filter_str = normalize_legacy_filter_value(exclude_filter_str)
|
|
725
|
-
|
|
768
|
+
_reject_unsafe_raw_filter(exclude_filter_str)
|
|
726
769
|
|
|
727
770
|
include_filter = parse_filter_input(include_filter_str)
|
|
728
771
|
exclude_filter = parse_filter_input(exclude_filter_str)
|
|
729
772
|
|
|
730
773
|
# Re-validate the parsed shapes — defense in depth for callers that
|
|
731
774
|
# pass a dict directly without going through the string path.
|
|
732
|
-
|
|
733
|
-
|
|
775
|
+
_reject_unsafe_raw_filter(include_filter)
|
|
776
|
+
_reject_unsafe_raw_filter(exclude_filter)
|
|
734
777
|
|
|
735
778
|
normalized_include_filter_list = normalize_filters(include_filter, True)
|
|
736
779
|
normalized_exclude_filter_list = normalize_filters(exclude_filter, False)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Typed error leaves for the SQL filters module."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from typing import ClassVar
|
|
7
|
+
|
|
8
|
+
from application_sdk.errors.leaves import InvalidInputError, InvalidInputValueError
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass(kw_only=True)
|
|
12
|
+
class InvalidSqlFilterError(InvalidInputError):
|
|
13
|
+
"""Filter input could not be parsed as valid JSON."""
|
|
14
|
+
|
|
15
|
+
code: ClassVar[str] = "INVALID_INPUT_SQL_FILTER_JSON"
|
|
16
|
+
message: str = "Invalid filter JSON"
|
|
17
|
+
field: str | None = "filter"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(kw_only=True)
|
|
21
|
+
class InvalidSqlFilterValueError(InvalidInputValueError):
|
|
22
|
+
"""A filter value was refused before SQL substitution on a raw-dict path.
|
|
23
|
+
|
|
24
|
+
Raised by ``prepare_query``, ``prepare_filters`` and
|
|
25
|
+
``get_database_names`` when a filter fails the SQL deny-list or the
|
|
26
|
+
regex-structure check. The value is the customer's own configuration, so
|
|
27
|
+
the audience is ``USER``. Still a ``ValueError`` so callers that guarded
|
|
28
|
+
the earlier bare ``ValueError`` keep working. The message names the
|
|
29
|
+
problem, never the value.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
code: ClassVar[str] = "INVALID_INPUT_SQL_FILTER_VALUE"
|
|
33
|
+
message: str = "Filter value rejected"
|
|
34
|
+
field: str | None = "filter"
|
{atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/constants.py
RENAMED
|
@@ -252,7 +252,8 @@ CLEANUP_BASE_PATHS = [
|
|
|
252
252
|
if path.strip()
|
|
253
253
|
]
|
|
254
254
|
|
|
255
|
-
# Key used to store tracked FileReference objects in
|
|
255
|
+
# Key used to store tracked FileReference objects in a run's _app_state slot
|
|
256
|
+
# (keyed by (workflow_id, run_id)) on the worker that ran the task
|
|
256
257
|
TRACKED_FILE_REFS_KEY = "_tracked_file_refs"
|
|
257
258
|
|
|
258
259
|
# Object-store prefixes that must never be deleted by cleanup_storage.
|
|
@@ -40,12 +40,24 @@ from typing import TYPE_CHECKING, Annotated, Any, Protocol, cast
|
|
|
40
40
|
from uuid import uuid4
|
|
41
41
|
|
|
42
42
|
import orjson
|
|
43
|
-
from fastapi import
|
|
43
|
+
from fastapi import (
|
|
44
|
+
FastAPI,
|
|
45
|
+
File,
|
|
46
|
+
Form,
|
|
47
|
+
HTTPException,
|
|
48
|
+
Query,
|
|
49
|
+
Request,
|
|
50
|
+
UploadFile,
|
|
51
|
+
params,
|
|
52
|
+
)
|
|
44
53
|
from fastapi import Path as PathParam
|
|
45
54
|
from fastapi.responses import JSONResponse
|
|
55
|
+
from fastapi.routing import APIRoute
|
|
56
|
+
from starlette.middleware import Middleware
|
|
57
|
+
from starlette.types import ASGIApp, Message, Receive, Scope, Send
|
|
46
58
|
from typing_extensions import deprecated
|
|
47
59
|
|
|
48
|
-
from application_sdk import _obstore_config
|
|
60
|
+
from application_sdk import _env, _obstore_config
|
|
49
61
|
from application_sdk._logging import get_logger
|
|
50
62
|
from application_sdk._runtime.offload import run_in_thread
|
|
51
63
|
from application_sdk.handler.contracts import FileUploadResponse
|
|
@@ -85,6 +97,17 @@ def valid_upload_prefix(prefix: str) -> bool:
|
|
|
85
97
|
)
|
|
86
98
|
|
|
87
99
|
|
|
100
|
+
#: First segments a worker refuses in an upload prefix: the object-store trees
|
|
101
|
+
#: the SDK itself writes, in the bucket every app on the tenant shares. Apps'
|
|
102
|
+
#: configs and state live under ``persistent-artifacts/apps/<app>/``, run
|
|
103
|
+
#: outputs under ``artifacts/apps/<app>/``, and connector caches under
|
|
104
|
+
#: ``connection-cache/``, each listed and read back by its owner. The host needs
|
|
105
|
+
#: no such list: it puts every upload under the app's own namespace.
|
|
106
|
+
_RESERVED_UPLOAD_ROOTS = frozenset(
|
|
107
|
+
{"persistent-artifacts", "artifacts", "connection-cache"}
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
|
|
88
111
|
# Strips any character that is not a simple alphanumeric from file extensions
|
|
89
112
|
# before they become part of an object-store key.
|
|
90
113
|
SAFE_EXT_RE = re.compile(r"[^a-zA-Z0-9]")
|
|
@@ -135,7 +158,16 @@ class ObjectRoutesSource:
|
|
|
135
158
|
consolidated host sets the app's own
|
|
136
159
|
``persistent-artifacts/apps/<app>/uploads``: one identity writes to
|
|
137
160
|
the shared bucket for every hosted app, so a request routed to one
|
|
138
|
-
app must not be able to write under another's prefix.
|
|
161
|
+
app must not be able to write under another's prefix. When unset
|
|
162
|
+
(the worker), the prefix is kept as given but may not start with
|
|
163
|
+
one of :data:`_RESERVED_UPLOAD_ROOTS`. Either way an unsafe prefix
|
|
164
|
+
(see :func:`valid_upload_prefix`) answers 400.
|
|
165
|
+
stored_key: ``key`` → the key ``upload_file`` actually writes. The
|
|
166
|
+
worker's store normalises keys (``storage.ops.normalize_key``
|
|
167
|
+
strips the local staging root, so ``local/tmp/artifacts/x`` is
|
|
168
|
+
stored at ``artifacts/x``). An upload whose key the store would
|
|
169
|
+
rewrite answers 400, so the key the route checks and returns is
|
|
170
|
+
the key stored. Defaults to the key unchanged.
|
|
139
171
|
"""
|
|
140
172
|
|
|
141
173
|
configured: Callable[[], bool]
|
|
@@ -143,10 +175,246 @@ class ObjectRoutesSource:
|
|
|
143
175
|
save_config: Callable[[str, dict[str, Any], str], Awaitable[bool]]
|
|
144
176
|
upload_file: Callable[[str, str], Awaitable[None]]
|
|
145
177
|
upload_namespace: str = ""
|
|
178
|
+
stored_key: Callable[[str], str] = lambda key: key
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
#: Path of the SDK's setup-form file upload route.
|
|
182
|
+
UPLOAD_ROUTE = "/workflows/v1/file"
|
|
183
|
+
|
|
184
|
+
#: Default cap on a request body a route reads whole (4 MiB): every route but a
|
|
185
|
+
#: form route. FastAPI reads such a body into memory before it parses it, so
|
|
186
|
+
#: this bounds what one request can make the process hold. The largest setup
|
|
187
|
+
#: form we ship decodes to ~5 KB.
|
|
188
|
+
DEFAULT_MAX_BODY_BYTES = 4 * 1024 * 1024
|
|
189
|
+
#: Default cap on a body sent to a form route (512 MiB): a route that declares a
|
|
190
|
+
#: ``File`` or ``Form`` parameter, such as :data:`UPLOAD_ROUTE` or an app's own
|
|
191
|
+
#: upload route. Starlette spools a multipart file to local disk while parsing
|
|
192
|
+
#: it, before the route runs, so this bounds the ephemeral storage one upload
|
|
193
|
+
#: can take.
|
|
194
|
+
DEFAULT_MAX_UPLOAD_BYTES = 512 * 1024 * 1024
|
|
195
|
+
|
|
196
|
+
MAX_BODY_BYTES_ENV = "ATLAN_HANDLER_MAX_BODY_BYTES"
|
|
197
|
+
MAX_UPLOAD_BYTES_ENV = "ATLAN_HANDLER_MAX_UPLOAD_BYTES"
|
|
198
|
+
|
|
199
|
+
_TOO_LARGE_DETAIL = "Request body too large"
|
|
200
|
+
_TOO_LARGE_BODY = orjson.dumps({"detail": _TOO_LARGE_DETAIL})
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def _too_large() -> HTTPException:
|
|
204
|
+
"""The signal ``receive`` raises once a body passes its cap.
|
|
205
|
+
|
|
206
|
+
An ``HTTPException`` because every layer between the read and the response
|
|
207
|
+
already passes one through untouched and unlogged: the routes' error
|
|
208
|
+
boundaries re-raise it, FastAPI's form parsing re-raises it, and
|
|
209
|
+
``ExceptionMiddleware`` renders it as the 413. It is not a ``ValueError``,
|
|
210
|
+
so :func:`~application_sdk.handler.request_contract.read_json_object` does
|
|
211
|
+
not answer 422 for it.
|
|
212
|
+
"""
|
|
213
|
+
return HTTPException(status_code=413, detail=_TOO_LARGE_DETAIL)
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def _report_env(message: str) -> None:
|
|
217
|
+
logger.warning("Ignoring env var: %s", message)
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
class RequestBodyLimitMiddleware:
|
|
221
|
+
"""Answer 413 to a request whose body is larger than its cap.
|
|
222
|
+
|
|
223
|
+
Pure ASGI, so it counts bytes as they arrive and never buffers a body. A
|
|
224
|
+
``Content-Length`` over the cap is refused before anything is read. A body
|
|
225
|
+
without one, or with one that understates it, is refused when the running
|
|
226
|
+
count passes the cap: ``receive`` raises a 413 ``HTTPException``, which
|
|
227
|
+
stops a multipart parser before it spools more to disk (Starlette closes the
|
|
228
|
+
spooled files when the read fails). Should an inner layer answer something
|
|
229
|
+
else, the response is still replaced by the 413, unless the app had already
|
|
230
|
+
started its response.
|
|
231
|
+
|
|
232
|
+
The cap depends on the route that reads the body. Routing runs before any
|
|
233
|
+
read and records the route in ``scope["route"]``, so the cap is chosen at
|
|
234
|
+
the first ``receive``, before a byte is counted. A form route (one that
|
|
235
|
+
declares a ``File`` or ``Form`` parameter) streams its body to disk and gets
|
|
236
|
+
``max_upload_bytes``. Every other route, a mount included, may read its body
|
|
237
|
+
whole into memory and gets ``max_body_bytes``. The route decides, not the
|
|
238
|
+
request's ``Content-Type``: FastAPI reads a non-form body whole before it
|
|
239
|
+
looks at the content type, so a large body labelled multipart must still
|
|
240
|
+
meet the smaller cap on a JSON route. An app's own upload route gets the
|
|
241
|
+
upload cap by declaring its file parameter, with nothing to configure. A
|
|
242
|
+
route that calls ``request.form()`` by hand gets the smaller cap.
|
|
243
|
+
|
|
244
|
+
A declared ``Content-Length`` over both caps is refused before routing; one
|
|
245
|
+
over the route's cap is refused at the first ``receive``, with nothing read.
|
|
246
|
+
|
|
247
|
+
:func:`install_body_limit` puts it inside every other user middleware, so
|
|
248
|
+
the raise never crosses a ``BaseHTTPMiddleware`` (the worker's
|
|
249
|
+
``LogMiddleware``): that would wrap it in an ``ExceptionGroup`` no handler
|
|
250
|
+
matches and log an expected rejection as a failed request.
|
|
251
|
+
"""
|
|
252
|
+
|
|
253
|
+
def __init__(
|
|
254
|
+
self,
|
|
255
|
+
app: ASGIApp,
|
|
256
|
+
*,
|
|
257
|
+
max_body_bytes: int,
|
|
258
|
+
max_upload_bytes: int,
|
|
259
|
+
) -> None:
|
|
260
|
+
self.app = app
|
|
261
|
+
self.max_body_bytes = max_body_bytes
|
|
262
|
+
self.max_upload_bytes = max_upload_bytes
|
|
263
|
+
|
|
264
|
+
def _limit_for(self, scope: Scope) -> int:
|
|
265
|
+
"""The cap of the route routing chose (``max_body_bytes`` when none)."""
|
|
266
|
+
if _is_form_route(scope.get("route")):
|
|
267
|
+
return self.max_upload_bytes
|
|
268
|
+
return self.max_body_bytes
|
|
269
|
+
|
|
270
|
+
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
|
|
271
|
+
if scope["type"] != "http":
|
|
272
|
+
await self.app(scope, receive, send)
|
|
273
|
+
return
|
|
274
|
+
|
|
275
|
+
declared = _content_length(scope)
|
|
276
|
+
largest = max(self.max_body_bytes, self.max_upload_bytes)
|
|
277
|
+
if declared is not None and declared > largest:
|
|
278
|
+
# No route takes a body this size: refuse it before routing.
|
|
279
|
+
self._log_rejection(scope, largest)
|
|
280
|
+
await _send_413(send)
|
|
281
|
+
return
|
|
282
|
+
|
|
283
|
+
limit: int | None = None
|
|
284
|
+
received = 0
|
|
285
|
+
exceeded = False
|
|
286
|
+
response_started = False
|
|
287
|
+
replaced = False
|
|
288
|
+
|
|
289
|
+
async def limited_receive() -> Message:
|
|
290
|
+
nonlocal limit, received, exceeded
|
|
291
|
+
if exceeded:
|
|
292
|
+
raise _too_large()
|
|
293
|
+
if limit is None:
|
|
294
|
+
limit = self._limit_for(scope)
|
|
295
|
+
if declared is not None and declared > limit:
|
|
296
|
+
exceeded = True
|
|
297
|
+
raise _too_large()
|
|
298
|
+
message = await receive()
|
|
299
|
+
if message["type"] == "http.request":
|
|
300
|
+
received += len(message.get("body", b""))
|
|
301
|
+
if received > limit:
|
|
302
|
+
exceeded = True
|
|
303
|
+
raise _too_large()
|
|
304
|
+
return message
|
|
305
|
+
|
|
306
|
+
async def guarded_send(message: Message) -> None:
|
|
307
|
+
nonlocal response_started, replaced
|
|
308
|
+
if replaced:
|
|
309
|
+
# The inner app's answer to the oversize body is discarded.
|
|
310
|
+
return
|
|
311
|
+
if message["type"] == "http.response.start":
|
|
312
|
+
if exceeded:
|
|
313
|
+
replaced = True
|
|
314
|
+
await _send_413(send)
|
|
315
|
+
return
|
|
316
|
+
response_started = True
|
|
317
|
+
await send(message)
|
|
318
|
+
|
|
319
|
+
try:
|
|
320
|
+
await self.app(scope, limited_receive, guarded_send)
|
|
321
|
+
except Exception:
|
|
322
|
+
# Once the cap has tripped, whatever escaped is its consequence:
|
|
323
|
+
# the 413 itself, or an inner layer's wrapping of it.
|
|
324
|
+
if not exceeded or response_started:
|
|
325
|
+
raise
|
|
326
|
+
if exceeded:
|
|
327
|
+
if not replaced and not response_started:
|
|
328
|
+
await _send_413(send)
|
|
329
|
+
self._log_rejection(scope, limit or self.max_body_bytes)
|
|
330
|
+
|
|
331
|
+
@staticmethod
|
|
332
|
+
def _log_rejection(scope: Scope, limit: int) -> None:
|
|
333
|
+
logger.warning(
|
|
334
|
+
"Request body over the %d-byte limit on %s %s; answered 413",
|
|
335
|
+
limit,
|
|
336
|
+
scope.get("method", ""),
|
|
337
|
+
scope.get("path", ""),
|
|
338
|
+
)
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
def _is_form_route(route: object) -> bool:
|
|
342
|
+
"""Whether *route* parses its body as a form (a ``File`` or ``Form`` parameter).
|
|
343
|
+
|
|
344
|
+
FastAPI parses such a body with ``request.form()``, which spools files to
|
|
345
|
+
disk, and reads any other body whole. ``File`` subclasses ``Form``.
|
|
346
|
+
"""
|
|
347
|
+
if not isinstance(route, APIRoute) or route.body_field is None:
|
|
348
|
+
return False
|
|
349
|
+
return isinstance(route.body_field.field_info, params.Form)
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
def _content_length(scope: Scope) -> int | None:
|
|
353
|
+
for name, value in scope.get("headers", ()):
|
|
354
|
+
if name == b"content-length":
|
|
355
|
+
try:
|
|
356
|
+
return int(value)
|
|
357
|
+
except ValueError:
|
|
358
|
+
return None
|
|
359
|
+
return None
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
async def _send_413(send: Send) -> None:
|
|
363
|
+
await send(
|
|
364
|
+
{
|
|
365
|
+
"type": "http.response.start",
|
|
366
|
+
"status": 413,
|
|
367
|
+
"headers": [
|
|
368
|
+
(b"content-type", b"application/json"),
|
|
369
|
+
(b"content-length", str(len(_TOO_LARGE_BODY)).encode()),
|
|
370
|
+
(b"connection", b"close"),
|
|
371
|
+
],
|
|
372
|
+
}
|
|
373
|
+
)
|
|
374
|
+
await send({"type": "http.response.body", "body": _TOO_LARGE_BODY})
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
def install_body_limit(app: FastAPI) -> None:
|
|
378
|
+
"""Cap request bodies on *app*, reading the caps from the environment.
|
|
379
|
+
|
|
380
|
+
:envvar:`ATLAN_HANDLER_MAX_UPLOAD_BYTES` caps a body sent to a form route
|
|
381
|
+
(``/workflows/v1/file``, or an app's own route with a ``File`` parameter),
|
|
382
|
+
:envvar:`ATLAN_HANDLER_MAX_BODY_BYTES` every other body. Called
|
|
383
|
+
by :func:`register_object_routes`, which the worker and the consolidated host
|
|
384
|
+
both call, so neither app can be built without the cap. Idempotent.
|
|
385
|
+
|
|
386
|
+
Appended, not added with ``add_middleware`` (which makes a middleware the
|
|
387
|
+
outermost): the cap must run inside every other user middleware, whenever
|
|
388
|
+
that was added. See :class:`RequestBodyLimitMiddleware`.
|
|
389
|
+
"""
|
|
390
|
+
if getattr(app.state, "body_limit_installed", False):
|
|
391
|
+
return
|
|
392
|
+
if app.middleware_stack is not None:
|
|
393
|
+
raise RuntimeError("Cannot add middleware after an application has started")
|
|
394
|
+
limit = Middleware(
|
|
395
|
+
RequestBodyLimitMiddleware,
|
|
396
|
+
max_body_bytes=_env.env_int(
|
|
397
|
+
MAX_BODY_BYTES_ENV, DEFAULT_MAX_BODY_BYTES, minimum=1, report=_report_env
|
|
398
|
+
),
|
|
399
|
+
max_upload_bytes=_env.env_int(
|
|
400
|
+
MAX_UPLOAD_BYTES_ENV,
|
|
401
|
+
DEFAULT_MAX_UPLOAD_BYTES,
|
|
402
|
+
minimum=1,
|
|
403
|
+
report=_report_env,
|
|
404
|
+
),
|
|
405
|
+
)
|
|
406
|
+
app.user_middleware.append(limit)
|
|
407
|
+
app.state.body_limit_installed = True
|
|
146
408
|
|
|
147
409
|
|
|
148
410
|
def register_object_routes(app: FastAPI, source: ObjectRoutesSource) -> None:
|
|
149
|
-
"""Register the config and file-upload routes on *app*.
|
|
411
|
+
"""Register the config and file-upload routes on *app*.
|
|
412
|
+
|
|
413
|
+
Also installs the request-body cap for the whole app
|
|
414
|
+
(:func:`install_body_limit`): every route's body is bounded, and an upload is
|
|
415
|
+
refused with 413 before it fills the pod's disk.
|
|
416
|
+
"""
|
|
417
|
+
install_body_limit(app)
|
|
150
418
|
|
|
151
419
|
@app.get("/workflows/v1/config/{config_id}")
|
|
152
420
|
async def get_workflow_config(
|
|
@@ -218,7 +486,7 @@ def register_object_routes(app: FastAPI, source: ObjectRoutesSource) -> None:
|
|
|
218
486
|
)
|
|
219
487
|
)
|
|
220
488
|
|
|
221
|
-
@app.post(
|
|
489
|
+
@app.post(UPLOAD_ROUTE)
|
|
222
490
|
async def upload_file(
|
|
223
491
|
file: UploadFile = File(...),
|
|
224
492
|
filename: str | None = Form(None),
|
|
@@ -240,20 +508,34 @@ def register_object_routes(app: FastAPI, source: ObjectRoutesSource) -> None:
|
|
|
240
508
|
|
|
241
509
|
file_id = str(uuid4())
|
|
242
510
|
effective_prefix = prefix or "workflow_file_upload"
|
|
511
|
+
if not valid_upload_prefix(effective_prefix):
|
|
512
|
+
raise HTTPException(
|
|
513
|
+
status_code=400,
|
|
514
|
+
detail="prefix must be relative path segments of letters, "
|
|
515
|
+
"digits, '_', '-' or '.', with no '.' or '..' segment",
|
|
516
|
+
)
|
|
243
517
|
if source.upload_namespace:
|
|
244
518
|
# The consolidated host: one AWS identity and one bucket serve every
|
|
245
|
-
# hosted app, so
|
|
246
|
-
# outside that app's namespace. A worker serves only its own app and
|
|
247
|
-
# keeps accepting the prefix as given, as it always has.
|
|
248
|
-
if not valid_upload_prefix(effective_prefix):
|
|
249
|
-
raise HTTPException(
|
|
250
|
-
status_code=400,
|
|
251
|
-
detail="prefix must be relative path segments of letters, "
|
|
252
|
-
"digits, '_', '-' or '.', with no '.' or '..' segment",
|
|
253
|
-
)
|
|
519
|
+
# hosted app, so every upload goes under the app's own namespace.
|
|
254
520
|
effective_prefix = f"{source.upload_namespace}/{effective_prefix}"
|
|
521
|
+
elif effective_prefix.split("/", 1)[0] in _RESERVED_UPLOAD_ROOTS:
|
|
522
|
+
# A worker keeps the prefix as given, so its keys stay where its
|
|
523
|
+
# readers expect them (``workflow_file_upload/...``), but the bucket
|
|
524
|
+
# is shared by every app on the tenant: a prefix must not plant an
|
|
525
|
+
# object in a tree the SDK writes and other apps or runs list.
|
|
526
|
+
raise HTTPException(
|
|
527
|
+
status_code=400,
|
|
528
|
+
detail="prefix must not start with a reserved object-store root",
|
|
529
|
+
)
|
|
255
530
|
stored_name = f"{file_id}.{extension}" if extension else file_id
|
|
256
531
|
key = f"{effective_prefix}/{stored_name}"
|
|
532
|
+
if source.stored_key(key) != key:
|
|
533
|
+
# The store would write somewhere else (a staging-path alias such
|
|
534
|
+
# as ``local/tmp/artifacts/...``), past the checks above.
|
|
535
|
+
raise HTTPException(
|
|
536
|
+
status_code=400,
|
|
537
|
+
detail="prefix must not be a local staging path",
|
|
538
|
+
)
|
|
257
539
|
|
|
258
540
|
# Stream the upload: drain the spooled temp file to a named temp file,
|
|
259
541
|
# then stream-upload to the object store (avoids materialising in memory).
|
|
@@ -108,9 +108,9 @@ async def read_json_object(request: Request) -> dict[str, Any]:
|
|
|
108
108
|
body = await request.json()
|
|
109
109
|
except ValueError as exc:
|
|
110
110
|
# ValueError, not Exception: json.JSONDecodeError is a ValueError, while
|
|
111
|
-
# the body-size cap signals
|
|
112
|
-
#
|
|
113
|
-
#
|
|
111
|
+
# the body-size cap (object_routes.RequestBodyLimitMiddleware) signals
|
|
112
|
+
# with a 413 HTTPException from inside the ASGI receive. It must
|
|
113
|
+
# propagate: FastAPI renders it as the 413.
|
|
114
114
|
raise RequestContractError(message="Request body is not valid JSON.") from exc
|
|
115
115
|
if not isinstance(body, dict):
|
|
116
116
|
raise RequestContractError(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "atlan-application-sdk-api"
|
|
3
|
-
version = "3.
|
|
3
|
+
version = "3.59.0"
|
|
4
4
|
description = "Experimental: the handler surface of the Atlan Application SDK, for the consolidated API host"
|
|
5
5
|
license = "Apache-2.0"
|
|
6
6
|
authors = [
|
|
@@ -61,7 +61,7 @@ obstore = ["obstore>=0.12.0,<0.13.0"]
|
|
|
61
61
|
# only inside ConnectionRef's Atlas conversion helpers, which the host never
|
|
62
62
|
# calls. Declared so those function-level imports are an extra's, as on the worker.
|
|
63
63
|
pyatlan = [
|
|
64
|
-
"pyatlan>=11.
|
|
64
|
+
"pyatlan>=11.8.0,<12",
|
|
65
65
|
# pyatlan 11.5.0 already requires authlib~=1.9.1 on Python >=3.10. Published
|
|
66
66
|
# here too so a resolver that ignores requires-python cannot pick pyatlan's
|
|
67
67
|
# py3.9 authlib branch for this wheel.
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"""Typed error leaves for the SQL filters module."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
from dataclasses import dataclass
|
|
6
|
-
from typing import ClassVar
|
|
7
|
-
|
|
8
|
-
from application_sdk.errors.leaves import InvalidInputError
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
@dataclass(kw_only=True)
|
|
12
|
-
class InvalidSqlFilterError(InvalidInputError):
|
|
13
|
-
"""Filter input could not be parsed as valid JSON."""
|
|
14
|
-
|
|
15
|
-
code: ClassVar[str] = "INVALID_INPUT_SQL_FILTER_JSON"
|
|
16
|
-
message: str = "Invalid filter JSON"
|
|
17
|
-
field: str | None = "filter"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/__init__.py
RENAMED
|
File without changes
|
{atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/_build_info.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/_env.py
RENAMED
|
File without changes
|
{atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/_install.py
RENAMED
|
File without changes
|
{atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/_logging.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/errors/base.py
RENAMED
|
File without changes
|
|
File without changes
|
{atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/errors/http.py
RENAMED
|
File without changes
|
|
File without changes
|
{atlan_application_sdk_api-3.58.1 → atlan_application_sdk_api-3.59.0}/application_sdk/errors/wire.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|