atlan-application-sdk-api 3.55.3__tar.gz → 3.57.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.
Files changed (89) hide show
  1. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/PKG-INFO +6 -3
  2. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/README.md +2 -1
  3. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/api-files.txt +3 -0
  4. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/_build_info.py +1 -1
  5. atlan_application_sdk_api-3.57.0/application_sdk/_env.py +181 -0
  6. atlan_application_sdk_api-3.57.0/application_sdk/_obstore_config.py +413 -0
  7. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/_runtime/__init__.py +1 -1
  8. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/_runtime/cgroup.py +4 -3
  9. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/_runtime/offload.py +49 -41
  10. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/clients/__init__.py +3 -0
  11. atlan_application_sdk_api-3.57.0/application_sdk/clients/ssl_utils.py +38 -0
  12. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/common/backoff.py +1 -1
  13. {atlan_application_sdk_api-3.55.3/application_sdk/clients → atlan_application_sdk_api-3.57.0/application_sdk/common}/ssl_utils.py +15 -2
  14. atlan_application_sdk_api-3.57.0/application_sdk/common/utils.py +147 -0
  15. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/constants.py +411 -230
  16. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/contracts/events.py +18 -10
  17. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/credentials/ref.py +36 -27
  18. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/errors/base.py +4 -3
  19. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/handler/asgi.py +7 -5
  20. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/handler/object_routes.py +227 -9
  21. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/server/fastapi/models.py +95 -3
  22. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/version.py +1 -1
  23. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/pyproject.toml +13 -3
  24. atlan_application_sdk_api-3.55.3/application_sdk/common/utils.py +0 -87
  25. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/.gitignore +0 -0
  26. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/__init__.py +0 -0
  27. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/_context_errors.py +0 -0
  28. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/_install.py +0 -0
  29. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/_logging.py +0 -0
  30. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/_runtime/progress.py +0 -0
  31. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/clients/_interface.py +0 -0
  32. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/clients/_sql_failure_classifier.py +0 -0
  33. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/clients/base.py +0 -0
  34. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/clients/http_errors.py +0 -0
  35. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/clients/models.py +0 -0
  36. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/clients/sql.py +0 -0
  37. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/clients/sql_errors.py +0 -0
  38. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/clients/sql_typecasters.py +0 -0
  39. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/common/__init__.py +0 -0
  40. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/common/_generated_tree.py +0 -0
  41. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/common/_listing.py +0 -0
  42. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/common/aws_utils.py +0 -0
  43. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/common/aws_utils_errors.py +0 -0
  44. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/common/build_identity.py +0 -0
  45. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/common/concurrency.py +0 -0
  46. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/common/errors.py +0 -0
  47. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/common/filter_matching.py +0 -0
  48. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/common/logger.py +0 -0
  49. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/common/models.py +0 -0
  50. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/common/sql_filters.py +0 -0
  51. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/common/sql_filters_errors.py +0 -0
  52. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/common/task_queue.py +0 -0
  53. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/common/types.py +0 -0
  54. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/contracts/__init__.py +0 -0
  55. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/contracts/base.py +0 -0
  56. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/contracts/types.py +0 -0
  57. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/contracts/types_errors.py +0 -0
  58. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/credentials/__init__.py +0 -0
  59. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/credentials/errors.py +0 -0
  60. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/credentials/extra.py +0 -0
  61. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/credentials/ingress.py +0 -0
  62. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/credentials/requirements.py +0 -0
  63. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/credentials/spec.py +0 -0
  64. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/credentials/types.py +0 -0
  65. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/credentials/utils.py +0 -0
  66. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/errors/__init__.py +0 -0
  67. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/errors/categories.py +0 -0
  68. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/errors/http.py +0 -0
  69. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/errors/leaves.py +0 -0
  70. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/errors/wire.py +0 -0
  71. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/handler/__init__.py +0 -0
  72. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/handler/_dispatch.py +0 -0
  73. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/handler/_warmup.py +0 -0
  74. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/handler/base.py +0 -0
  75. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/handler/context.py +0 -0
  76. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/handler/contracts.py +0 -0
  77. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/handler/manifest.py +0 -0
  78. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/handler/metadata_routes.py +0 -0
  79. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/handler/request_contract.py +0 -0
  80. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/handler/routes.py +0 -0
  81. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/handler/service_errors.py +0 -0
  82. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/server/__init__.py +0 -0
  83. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/templates/__init__.py +0 -0
  84. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/templates/contracts/__init__.py +0 -0
  85. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/templates/contracts/base_metadata_extraction.py +0 -0
  86. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/templates/contracts/incremental_sql.py +0 -0
  87. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/templates/contracts/sql_metadata.py +0 -0
  88. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.0}/application_sdk/templates/contracts/sql_query.py +0 -0
  89. {atlan_application_sdk_api-3.55.3 → atlan_application_sdk_api-3.57.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.55.3
3
+ Version: 3.57.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
@@ -29,10 +29,12 @@ Provides-Extra: aws
29
29
  Requires-Dist: boto3<2.0.0,>=1.38.6; extra == 'aws'
30
30
  Requires-Dist: httpx<0.29.0,>=0.27.0; extra == 'aws'
31
31
  Requires-Dist: python-dotenv<2.0.0,>=1.2.2; extra == 'aws'
32
+ Provides-Extra: obstore
33
+ Requires-Dist: obstore<0.13.0,>=0.12.0; extra == 'obstore'
32
34
  Provides-Extra: pandas
33
35
  Requires-Dist: pandas<4.0.0,>=2.2.3; extra == 'pandas'
34
36
  Provides-Extra: pyatlan
35
- Requires-Dist: authlib<2,>=1.9.4; extra == 'pyatlan'
37
+ Requires-Dist: authlib<2,>=1.9.5; extra == 'pyatlan'
36
38
  Requires-Dist: pyatlan<12,>=11.7.0; extra == 'pyatlan'
37
39
  Provides-Extra: sql
38
40
  Requires-Dist: httpx<0.29.0,>=0.27.0; extra == 'sql'
@@ -164,7 +166,7 @@ an app answers identically from either one:
164
166
  | `POST /workflows/v1/metadata` | `Handler.fetch_metadata` |
165
167
  | `POST /workflows/v1/warmup` | `Handler.warmup` (optional) |
166
168
  | `GET /workflows/v1/configmap/{id}`, `/configmaps`, `/input-contract`, `GET`/`POST /workflows/v1/manifest` | The app's `generated/` folder, if the app package ships one |
167
- | `GET`/`POST /workflows/v1/config/{id}`, `POST /workflows/v1/file` | An S3 bucket named by `ATLAN_S3_BUCKET` (and `ATLAN_S3_REGION`), or on GCP by `ATLAN_GCP_BUCKET` (and `ATLAN_GCP_REGION`) through GCS's S3-compatible API with the `ATLAN_GCP_HMAC_ACCESS_KEY` / `ATLAN_GCP_HMAC_SECRET` keys; needs the `aws` extra. These routes return 503 when neither is set |
169
+ | `GET`/`POST /workflows/v1/config/{id}`, `POST /workflows/v1/file` | The tenant object store through obstore; needs the `obstore` extra. An S3 bucket named by `ATLAN_S3_BUCKET` (and `ATLAN_S3_REGION`); on GCP, `ATLAN_GCP_BUCKET` (and `ATLAN_GCP_REGION`) through GCS's S3-compatible API with the `ATLAN_GCP_HMAC_ACCESS_KEY` / `ATLAN_GCP_HMAC_SECRET` keys; on Azure Blob, the container named by `ATLAN_AZURE_STORAGE_ACCOUNT` and `ATLAN_AZURE_STORAGE_CONTAINER`, with `ATLAN_AZURE_STORAGE_ACCESS_KEY` or the pod's own identity. A bucket wins over an Azure account. These routes return 503 when none is set |
168
170
  | Your own routes | FastAPI routers returned from `Handler.routers()`, served after the SDK's |
169
171
 
170
172
  `build_asgi_app` takes a few keyword options:
@@ -190,6 +192,7 @@ apps in one process don't block each other.
190
192
  | `application_sdk.common.logger` | `get_logger` |
191
193
  | `application_sdk.clients.sql` (`sql` extra) | The SQL client base |
192
194
  | `application_sdk.common.aws_utils` (`aws` extra) | AWS helpers |
195
+ | `application_sdk._obstore_config` (`obstore` extra) | The object-store constructors the config and file routes use |
193
196
 
194
197
  The complete file list is in
195
198
  [`api-files.txt`](https://github.com/atlanhq/application-sdk/blob/main/packages/api/api-files.txt).
@@ -122,7 +122,7 @@ an app answers identically from either one:
122
122
  | `POST /workflows/v1/metadata` | `Handler.fetch_metadata` |
123
123
  | `POST /workflows/v1/warmup` | `Handler.warmup` (optional) |
124
124
  | `GET /workflows/v1/configmap/{id}`, `/configmaps`, `/input-contract`, `GET`/`POST /workflows/v1/manifest` | The app's `generated/` folder, if the app package ships one |
125
- | `GET`/`POST /workflows/v1/config/{id}`, `POST /workflows/v1/file` | An S3 bucket named by `ATLAN_S3_BUCKET` (and `ATLAN_S3_REGION`), or on GCP by `ATLAN_GCP_BUCKET` (and `ATLAN_GCP_REGION`) through GCS's S3-compatible API with the `ATLAN_GCP_HMAC_ACCESS_KEY` / `ATLAN_GCP_HMAC_SECRET` keys; needs the `aws` extra. These routes return 503 when neither is set |
125
+ | `GET`/`POST /workflows/v1/config/{id}`, `POST /workflows/v1/file` | The tenant object store through obstore; needs the `obstore` extra. An S3 bucket named by `ATLAN_S3_BUCKET` (and `ATLAN_S3_REGION`); on GCP, `ATLAN_GCP_BUCKET` (and `ATLAN_GCP_REGION`) through GCS's S3-compatible API with the `ATLAN_GCP_HMAC_ACCESS_KEY` / `ATLAN_GCP_HMAC_SECRET` keys; on Azure Blob, the container named by `ATLAN_AZURE_STORAGE_ACCOUNT` and `ATLAN_AZURE_STORAGE_CONTAINER`, with `ATLAN_AZURE_STORAGE_ACCESS_KEY` or the pod's own identity. A bucket wins over an Azure account. These routes return 503 when none is set |
126
126
  | Your own routes | FastAPI routers returned from `Handler.routers()`, served after the SDK's |
127
127
 
128
128
  `build_asgi_app` takes a few keyword options:
@@ -148,6 +148,7 @@ apps in one process don't block each other.
148
148
  | `application_sdk.common.logger` | `get_logger` |
149
149
  | `application_sdk.clients.sql` (`sql` extra) | The SQL client base |
150
150
  | `application_sdk.common.aws_utils` (`aws` extra) | AWS helpers |
151
+ | `application_sdk._obstore_config` (`obstore` extra) | The object-store constructors the config and file routes use |
151
152
 
152
153
  The complete file list is in
153
154
  [`api-files.txt`](https://github.com/atlanhq/application-sdk/blob/main/packages/api/api-files.txt).
@@ -4,8 +4,10 @@
4
4
  application_sdk/__init__.py
5
5
  application_sdk/_build_info.py
6
6
  application_sdk/_context_errors.py
7
+ application_sdk/_env.py
7
8
  application_sdk/_install.py
8
9
  application_sdk/_logging.py
10
+ application_sdk/_obstore_config.py
9
11
  application_sdk/_runtime/__init__.py
10
12
  application_sdk/_runtime/cgroup.py
11
13
  application_sdk/_runtime/offload.py
@@ -34,6 +36,7 @@ application_sdk/common/logger.py
34
36
  application_sdk/common/models.py
35
37
  application_sdk/common/sql_filters.py
36
38
  application_sdk/common/sql_filters_errors.py
39
+ application_sdk/common/ssl_utils.py
37
40
  application_sdk/common/task_queue.py
38
41
  application_sdk/common/types.py
39
42
  application_sdk/common/utils.py
@@ -27,7 +27,7 @@ def load_build_info(path: str | None = None) -> dict[str, str]:
27
27
  Missing or malformed file → ``{}``; callers fall back to the env vars.
28
28
  ``ATLAN_BUILD_INFO_PATH`` overrides the lookup for non-template layouts.
29
29
 
30
- Public because :mod:`application_sdk.app.build_identity` reads the same file
30
+ Public because :mod:`application_sdk.common.build_identity` reads the same file
31
31
  through it. A second parser there would be a second place for the key names
32
32
  to drift from what CI writes.
33
33
  """
@@ -0,0 +1,181 @@
1
+ """Tolerant env-var parsing: the one reader for every typed SDK env var.
2
+
3
+ Every SDK setting read from the environment goes through one of these four
4
+ functions, so they all share one set of rules:
5
+
6
+ * **Unset or empty is the default.** An unset Helm value renders as ``""``, so
7
+ an empty string means "not configured", never "zero" or "false".
8
+ * **A malformed value is the default, with a warning.** A typo must not stop
9
+ every process at import, before logging is configured. The value falls back
10
+ to the default and a message names the variable, the rejected value and
11
+ the default used instead.
12
+ * **One boolean vocabulary.** ``true`` / ``1`` / ``yes`` / ``on`` enable and
13
+ ``false`` / ``0`` / ``no`` / ``off`` disable, case-insensitive with surrounding
14
+ whitespace ignored. Any other word warns and keeps the default.
15
+
16
+ Standard library only, and deliberately outside ``application_sdk.common``:
17
+ ``application_sdk.constants`` and ``application_sdk._runtime`` read through it
18
+ at import time. Importing anything under ``common`` would run that package's
19
+ ``__init__``, which imports ``constants``, which is a cycle. For the same reason
20
+ the message goes to :mod:`warnings` as a ``RuntimeWarning`` by default rather
21
+ than to the SDK logger: the logger imports ``constants``, and at import time
22
+ logging is not configured yet. A caller that runs after logging is up passes
23
+ ``report`` to route the message to its logger instead;
24
+ :mod:`application_sdk.common._env` does that for SDK modules that can import the
25
+ logger.
26
+ """
27
+
28
+ from __future__ import annotations
29
+
30
+ import math
31
+ import os
32
+ import warnings
33
+ from collections.abc import Callable, Collection
34
+
35
+ #: Receives the message for a rejected value. ``None`` means ``warnings.warn``.
36
+ Reporter = Callable[[str], None]
37
+
38
+ #: Words that switch a boolean env var on.
39
+ TRUE_VALUES: frozenset[str] = frozenset({"true", "1", "yes", "on"})
40
+ #: Words that switch a boolean env var off.
41
+ FALSE_VALUES: frozenset[str] = frozenset({"false", "0", "no", "off"})
42
+
43
+
44
+ def _raw(key: str) -> str | None:
45
+ """The stripped value of *key*, or ``None`` when unset or empty."""
46
+ value = os.environ.get(key)
47
+ if value is None:
48
+ return None
49
+ stripped = value.strip()
50
+ return stripped or None
51
+
52
+
53
+ def _reject(message: str, report: Reporter | None) -> None:
54
+ if report is not None:
55
+ report(message)
56
+ return
57
+ # stacklevel 3: point at the line that called env_int/env_float/..., not
58
+ # at this helper or the env_* function itself.
59
+ warnings.warn(message, RuntimeWarning, stacklevel=3)
60
+
61
+
62
+ def env_int(
63
+ key: str,
64
+ default: int = 0,
65
+ *,
66
+ minimum: int | None = None,
67
+ report: Reporter | None = None,
68
+ ) -> int:
69
+ """Read an integer env var.
70
+
71
+ Returns *default* when the variable is unset or empty. A value that is not
72
+ an integer, or is below *minimum*, warns and returns *default*.
73
+ """
74
+ raw = _raw(key)
75
+ if raw is None:
76
+ return default
77
+ try:
78
+ value = int(raw)
79
+ except ValueError:
80
+ _reject(f"{key}={raw!r} is not an integer; using the default {default}", report)
81
+ return default
82
+ if minimum is not None and value < minimum:
83
+ _reject(
84
+ f"{key}={value} is below {minimum}; using the default {default}", report
85
+ )
86
+ return default
87
+ return value
88
+
89
+
90
+ def env_float(
91
+ key: str,
92
+ default: float,
93
+ *,
94
+ minimum: float | None = None,
95
+ report: Reporter | None = None,
96
+ ) -> float:
97
+ """Read a finite float env var.
98
+
99
+ Returns *default* when the variable is unset or empty. A value that is not a
100
+ number, is not finite (``inf`` / ``nan``), or is below *minimum*, warns and
101
+ returns *default*. Non-finite values are rejected because an ``inf`` bound
102
+ never trips and every ``nan`` comparison is False, so either one silently
103
+ disables whatever the value bounds.
104
+ """
105
+ raw = _raw(key)
106
+ if raw is None:
107
+ return default
108
+ try:
109
+ value = float(raw)
110
+ except ValueError:
111
+ _reject(f"{key}={raw!r} is not a number; using the default {default:g}", report)
112
+ return default
113
+ if not math.isfinite(value):
114
+ _reject(f"{key}={raw!r} is not finite; using the default {default:g}", report)
115
+ return default
116
+ if minimum is not None and value < minimum:
117
+ _reject(
118
+ f"{key}={value:g} is below {minimum:g}; using the default {default:g}",
119
+ report,
120
+ )
121
+ return default
122
+ return value
123
+
124
+
125
+ def env_bool(
126
+ key: str, default: bool = False, *, report: Reporter | None = None
127
+ ) -> bool:
128
+ """Read a boolean env var using :data:`TRUE_VALUES` / :data:`FALSE_VALUES`.
129
+
130
+ Returns *default* when the variable is unset or empty. Any other word warns
131
+ and returns *default*.
132
+ """
133
+ raw = _raw(key)
134
+ if raw is None:
135
+ return default
136
+ word = raw.lower()
137
+ if word in TRUE_VALUES:
138
+ return True
139
+ if word in FALSE_VALUES:
140
+ return False
141
+ _reject(
142
+ f"{key}={raw!r} is not one of {sorted(TRUE_VALUES | FALSE_VALUES)}; "
143
+ f"using the default {str(default).lower()}",
144
+ report,
145
+ )
146
+ return default
147
+
148
+
149
+ def env_choice(
150
+ key: str,
151
+ allowed: Collection[str],
152
+ default: str,
153
+ *,
154
+ report: Reporter | None = None,
155
+ ) -> str:
156
+ """Read an env var whose value must be one of *allowed* (lowercase words).
157
+
158
+ The value is lowercased and stripped. Returns *default* when the variable
159
+ is unset or empty. A word outside *allowed* warns and returns *default*,
160
+ so a typo can never reach the code that branches on it and select whichever
161
+ branch happens to be the ``else``.
162
+ """
163
+ raw = _raw(key)
164
+ if raw is None:
165
+ return default
166
+ word = raw.lower()
167
+ if word in allowed:
168
+ return word
169
+ _reject(f"{key}={raw!r} is not one of {sorted(allowed)}; using {default!r}", report)
170
+ return default
171
+
172
+
173
+ __all__ = [
174
+ "FALSE_VALUES",
175
+ "Reporter",
176
+ "TRUE_VALUES",
177
+ "env_bool",
178
+ "env_choice",
179
+ "env_float",
180
+ "env_int",
181
+ ]
@@ -0,0 +1,413 @@
1
+ """obstore client + retry configuration plumbed from environment variables.
2
+
3
+ obstore-rs (the Rust layer behind ``S3Store``/``GCSStore``/``AzureStore``)
4
+ already does best-in-class retry with exponential backoff and jitter. What
5
+ we *cannot* tune from the SDK without these helpers is its **client-level
6
+ timeouts and connection pool**, which are sized for small objects by default
7
+ and cause GB-class downloads to fail with timeout-stalled streams.
8
+
9
+ A production RCA and the in-tree fivetran-app workaround
10
+ (``binding_cfg.config["client_options"] = {"timeout": "30m"}``) both point to
11
+ the same gap: ``client_options`` and ``retry_config`` are never plumbed
12
+ through ``application_sdk/storage/binding.py`` or
13
+ ``application_sdk/storage/cloud.py``.
14
+
15
+ This module is the single, env-var-driven source of truth for those values.
16
+
17
+ Environment variables
18
+ ---------------------
19
+
20
+ Client options (passed via ``S3Store(client_options=…)``):
21
+
22
+ * ``ATLAN_OBSTORE_READ_TIMEOUT`` — **progress-based** read timeout (default
23
+ ``"90s"``). This is the primary liveness bound for large transfers: obstore
24
+ resets it after every successful read, so a slow-but-*progressing* GB-class
25
+ download stays alive indefinitely and only fails when no bytes arrive for
26
+ the window. This is what keeps large downloads alive instead of relying on a
27
+ bigger overall cap (BLDX-1513).
28
+ * ``ATLAN_OBSTORE_TIMEOUT`` — **overall-request** timeout (default ``"30m"``).
29
+ This is the total wall-clock cap from connect to last byte, so it scales with
30
+ file size, not throughput. It is now a generous *backstop* — ``read_timeout``
31
+ above does the real stall detection. A prior default of ``"90s"`` killed
32
+ ~250 MB connection-cache downloads on a slow-egress tenant even while bytes
33
+ were still flowing (~1 MiB/s); bump this env for multi-GB single objects.
34
+ * ``ATLAN_OBSTORE_CONNECT_TIMEOUT`` — connect-phase timeout (default ``"30s"``).
35
+ * ``ATLAN_OBSTORE_POOL_IDLE_TIMEOUT`` — pool idle timeout (default ``"90s"``).
36
+ * ``ATLAN_OBSTORE_POOL_MAX_IDLE_PER_HOST`` — pool size per host (unset by
37
+ default — leaves the obstore default).
38
+ * ``ATLAN_OBSTORE_HTTP2_KEEP_ALIVE_TIMEOUT`` — H2 keep-alive ack timeout
39
+ (default ``"30s"``).
40
+ * ``ATLAN_OBSTORE_USER_AGENT`` — custom UA string. Defaults to
41
+ ``"atlan-application-sdk/{version}"`` so tenant operators can identify
42
+ SDK traffic in S3 access logs.
43
+
44
+ Proxy / TLS (obstore reads none of these itself, so we plumb them explicitly):
45
+
46
+ * ``HTTPS_PROXY`` / ``HTTP_PROXY`` — obstore's ``proxy_url``.
47
+ * ``NO_PROXY`` — obstore's ``proxy_excludes`` (only when a proxy is set).
48
+ * ``SSL_CERT_DIR`` — custom CA certs for private-CA stores (e.g. self-hosted
49
+ MinIO), loaded into obstore's ``root_certificate``. Same env var the SDK's httpx
50
+ clients and Temporal honor via ``common/ssl_utils.py``.
51
+
52
+ Retry config (passed via ``S3Store(retry_config=…)``):
53
+
54
+ * ``ATLAN_OBSTORE_RETRY_MAX_RETRIES`` — overrides obstore's default of 10.
55
+ * ``ATLAN_OBSTORE_RETRY_TIMEOUT_SECONDS`` — overrides obstore's default of 3 min
56
+ (integer seconds).
57
+
58
+ We deliberately do **not** add a Python-level retry loop on top — the Rust
59
+ layer already retries with backoff and we'd just multiply the failure time
60
+ without changing the outcome (see BLDX-1155 review thread). The one exception
61
+ is ``ops.upload_file``'s retry of the blobstorage gateway's transient
62
+ ``404 "no Route matched"``: the Rust layer never retries a 404, so that loop
63
+ adds a retry where there was none rather than multiplying one.
64
+ """
65
+
66
+ from __future__ import annotations
67
+
68
+ import contextlib
69
+ import os
70
+ import threading
71
+ import urllib.request
72
+ from typing import TYPE_CHECKING
73
+ from urllib.parse import urlsplit, urlunsplit
74
+
75
+ if TYPE_CHECKING:
76
+ # obstore TypedDicts — not importable at runtime.
77
+ from obstore.store import ClientConfig, ObjectStore, RetryConfig
78
+
79
+ from application_sdk._logging import get_logger
80
+
81
+ logger = get_logger(__name__)
82
+
83
+ # Overall-request cap: from connect to last byte, so it scales with file size,
84
+ # not throughput. Kept generous — ``read_timeout`` below is the real liveness
85
+ # bound. See BLDX-1513: a 90s value here killed slow-but-progressing GB-class
86
+ # downloads even while bytes were flowing.
87
+ _DEFAULT_TIMEOUT = "30m"
88
+ # Progress-based read timeout: resets after every successful read, so it detects
89
+ # a genuinely *stalled* connection (no bytes for the window) without penalising a
90
+ # transfer that is merely slow. This is what keeps large downloads alive.
91
+ _DEFAULT_READ_TIMEOUT = "90s"
92
+ _DEFAULT_CONNECT_TIMEOUT = "30s"
93
+ _DEFAULT_POOL_IDLE_TIMEOUT = "90s"
94
+ _DEFAULT_HTTP2_KEEP_ALIVE_TIMEOUT = "30s"
95
+
96
+
97
+ def _default_user_agent() -> str:
98
+ """Return the default ``user_agent`` string.
99
+
100
+ Imported lazily so that ``application_sdk.version`` doesn't pull this
101
+ module into circular-import paths during package init.
102
+ """
103
+ try:
104
+ from application_sdk.version import ( # type: ignore[import] # noqa: PLC0415
105
+ __version__,
106
+ )
107
+
108
+ return f"atlan-application-sdk/{__version__}"
109
+ except Exception: # pragma: no cover — defensive
110
+ logger.warning(
111
+ "Failed to derive User-Agent from version; using fallback", exc_info=True
112
+ )
113
+ return "atlan-application-sdk"
114
+
115
+
116
+ def _obstore_proxy_url() -> str | None:
117
+ """Return the proxy URL from HTTPS_PROXY/HTTP_PROXY, or None.
118
+
119
+ obstore doesn't read proxy env vars itself, so we pass it explicitly.
120
+ """
121
+ proxies = urllib.request.getproxies()
122
+ return proxies.get("https") or proxies.get("http") or None
123
+
124
+
125
+ def _obstore_proxy_excludes() -> str | None:
126
+ """Return NO_PROXY (obstore's ``proxy_excludes``), or None.
127
+
128
+ Unlike Temporal — which knows its single target host and resolves the bypass
129
+ itself via ``proxy_bypass_environment`` — obstore matches NO_PROXY per-host
130
+ at request time, so we just hand it the raw list.
131
+ """
132
+ return urllib.request.getproxies_environment().get("no") or None
133
+
134
+
135
+ def obstore_client_options() -> ClientConfig:
136
+ """Build an obstore ``ClientConfig`` from environment variables.
137
+
138
+ Returns:
139
+ A ``ClientConfig`` (obstore TypedDict) suitable for passing as
140
+ ``client_options=`` to S3Store / GCSStore / AzureStore constructors.
141
+ Always contains at least the SDK defaults — the dict is never empty.
142
+ """
143
+ opts: ClientConfig = {
144
+ "timeout": os.getenv("ATLAN_OBSTORE_TIMEOUT", _DEFAULT_TIMEOUT),
145
+ "read_timeout": os.getenv("ATLAN_OBSTORE_READ_TIMEOUT", _DEFAULT_READ_TIMEOUT),
146
+ "connect_timeout": os.getenv(
147
+ "ATLAN_OBSTORE_CONNECT_TIMEOUT", _DEFAULT_CONNECT_TIMEOUT
148
+ ),
149
+ "pool_idle_timeout": os.getenv(
150
+ "ATLAN_OBSTORE_POOL_IDLE_TIMEOUT", _DEFAULT_POOL_IDLE_TIMEOUT
151
+ ),
152
+ "http2_keep_alive_timeout": os.getenv(
153
+ "ATLAN_OBSTORE_HTTP2_KEEP_ALIVE_TIMEOUT",
154
+ _DEFAULT_HTTP2_KEEP_ALIVE_TIMEOUT,
155
+ ),
156
+ "user_agent": os.getenv("ATLAN_OBSTORE_USER_AGENT", _default_user_agent()),
157
+ }
158
+ pool_max = os.getenv("ATLAN_OBSTORE_POOL_MAX_IDLE_PER_HOST")
159
+ if pool_max:
160
+ opts["pool_max_idle_per_host"] = pool_max
161
+ proxy_url = _obstore_proxy_url()
162
+ if proxy_url:
163
+ opts["proxy_url"] = proxy_url
164
+ proxy_excludes = _obstore_proxy_excludes()
165
+ if proxy_excludes:
166
+ opts["proxy_excludes"] = proxy_excludes
167
+
168
+ from application_sdk.common.ssl_utils import ( # noqa: PLC0415
169
+ get_custom_ca_cert_bytes,
170
+ )
171
+
172
+ root_certificate = get_custom_ca_cert_bytes()
173
+ if root_certificate:
174
+ opts["root_certificate"] = root_certificate
175
+ return opts
176
+
177
+
178
+ def obstore_retry_config() -> RetryConfig | None:
179
+ """Build an obstore ``RetryConfig``, or ``None`` for upstream defaults.
180
+
181
+ Returns:
182
+ A ``RetryConfig`` (obstore TypedDict) suitable for passing as
183
+ ``retry_config=`` to S3Store / GCSStore / AzureStore constructors,
184
+ or ``None`` when no overrides have been set (so we don't fight the
185
+ upstream defaults).
186
+ """
187
+ from datetime import timedelta # noqa: PLC0415
188
+
189
+ cfg: RetryConfig = {}
190
+ raw_max = os.getenv("ATLAN_OBSTORE_RETRY_MAX_RETRIES")
191
+ if raw_max:
192
+ try:
193
+ cfg["max_retries"] = int(raw_max)
194
+ except ValueError:
195
+ logger.warning(
196
+ "Invalid ATLAN_OBSTORE_RETRY_MAX_RETRIES=%r — using obstore default",
197
+ raw_max,
198
+ exc_info=True,
199
+ )
200
+
201
+ raw_timeout = os.getenv("ATLAN_OBSTORE_RETRY_TIMEOUT_SECONDS")
202
+ if raw_timeout:
203
+ try:
204
+ cfg["retry_timeout"] = timedelta(seconds=int(raw_timeout))
205
+ except ValueError:
206
+ logger.warning(
207
+ "Invalid ATLAN_OBSTORE_RETRY_TIMEOUT_SECONDS=%r — using obstore default",
208
+ raw_timeout,
209
+ exc_info=True,
210
+ )
211
+
212
+ return cfg or None
213
+
214
+
215
+ def make_s3_store(
216
+ bucket: str,
217
+ config: dict[str, str] | None = None,
218
+ *,
219
+ label: str = "s3",
220
+ client_options: ClientConfig | None = None,
221
+ credential_provider: object = None,
222
+ ) -> ObjectStore:
223
+ """Create an S3Store with SDK-default client/retry config.
224
+
225
+ Both ``binding.py`` and ``cloud.py`` delegate store construction here so
226
+ timeouts, retry budgets, and log output stay consistent across all S3 paths.
227
+ Pass *client_options* to override the SDK defaults (e.g., for insecureSSL).
228
+ """
229
+ from obstore.store import S3Store # noqa: PLC0415
230
+
231
+ opts = client_options if client_options is not None else obstore_client_options()
232
+ retry = obstore_retry_config()
233
+ log_obstore_config(label, client_options=opts, retry_config=retry)
234
+ kw: dict[str, object] = dict(
235
+ bucket=bucket, config=config, client_options=opts, retry_config=retry
236
+ )
237
+ if credential_provider is not None:
238
+ kw["credential_provider"] = credential_provider
239
+ return S3Store(**kw) # type: ignore[arg-type]
240
+
241
+
242
+ # obstore-rs reads ``AZURE_*`` from the environment at AzureStore construction
243
+ # *unconditionally*, and its credential precedence (account key > SAS > client secret >
244
+ # workload identity) lets a value injected into the host environment outrank the
245
+ # credential the caller passed in ``config``. On an Azure-hosted node the pod carries
246
+ # its own identity in ``AZURE_STORAGE_ACCESS_KEY`` and in ``AZURE_FEDERATED_TOKEN_FILE``
247
+ # + ``AZURE_CLIENT_ID``; either silently overrides an explicit caller credential and
248
+ # signs requests as the wrong principal (403 AuthenticationFailed / 401 AADSTS70025).
249
+ # So when the caller supplies a standalone credential in ``config`` we construct the
250
+ # store with all ``AZURE_*`` stripped from the environment, leaving obstore to resolve
251
+ # from our ``config`` alone. Callers that pass no credential (managed / workload
252
+ # identity) are left untouched so the ambient identity still applies.
253
+ #
254
+ # TODO: retire this env-mutation workaround once obstore-rs honours explicit ``config``
255
+ # credentials with higher precedence than ambient ``AZURE_*`` env vars. File an issue
256
+ # at https://github.com/developmentseed/obstore/issues and replace the placeholder
257
+ # below with the specific issue URL — the workaround must not be deleted until that
258
+ # gate is closed.
259
+ # Upstream issue: <not yet filed>
260
+ _AZURE_CREDENTIAL_CONFIG_KEYS = (
261
+ "azure_storage_account_key",
262
+ "azure_storage_client_secret",
263
+ "azure_storage_sas_key",
264
+ "azure_storage_token",
265
+ )
266
+
267
+ # os.environ is process-global, so serialize make_azure_store callers: an isolated build
268
+ # (env temporarily stripped) must never overlap a concurrent build that relies on the
269
+ # ambient AZURE_* env. Note: this lock only protects callers of make_azure_store — other
270
+ # in-process readers (azure-identity, OpenTelemetry exporters, subprocesses spawned during
271
+ # the window, sidecar SDKs) can still observe the stripped env during the brief window.
272
+ _azure_store_build_lock = threading.Lock()
273
+
274
+
275
+ def _azure_config_has_explicit_credential(config: dict[str, str] | None) -> bool:
276
+ """True if *config* carries a standalone Azure credential (account key / client
277
+ secret / SAS / bearer token) — i.e. the caller wants that credential used, not the
278
+ host's ambient identity."""
279
+ return bool(config) and any(config.get(k) for k in _AZURE_CREDENTIAL_CONFIG_KEYS)
280
+
281
+
282
+ @contextlib.contextmanager
283
+ def _suppress_ambient_azure_env(active: bool):
284
+ """Temporarily drop all ambient ``AZURE_*`` env vars when *active*.
285
+
286
+ Scoped to the synchronous AzureStore constructor (where obstore reads the
287
+ environment). Serialized by ``_azure_store_build_lock`` so an isolated build can't
288
+ strip the environment out from under a concurrent non-isolated build.
289
+ """
290
+ with _azure_store_build_lock:
291
+ if not active:
292
+ yield
293
+ return
294
+ saved = {
295
+ k: os.environ.pop(k) for k in list(os.environ) if k.startswith("AZURE_")
296
+ }
297
+ if saved:
298
+ logger.debug(
299
+ "make_azure_store: suppressed %d ambient AZURE_* env var(s)", len(saved)
300
+ )
301
+ try:
302
+ yield
303
+ finally:
304
+ os.environ.update(saved)
305
+
306
+
307
+ def make_azure_store(
308
+ container: str,
309
+ config: dict[str, str] | None = None,
310
+ *,
311
+ label: str = "azure",
312
+ client_options: ClientConfig | None = None,
313
+ credential_provider: object = None,
314
+ ) -> ObjectStore:
315
+ """Create an AzureStore with SDK-default client/retry config.
316
+
317
+ See :func:`make_s3_store` for rationale. When *config* carries an explicit
318
+ credential *or* a ``credential_provider`` is supplied, the ambient ``AZURE_*``
319
+ environment is suppressed for the construction so the host's own identity can't
320
+ override it (see ``_suppress_ambient_azure_env``). The cert-auth path in
321
+ ``binding.py`` uses ``credential_provider`` instead of placing a key in ``config``,
322
+ so both cases must activate env stripping.
323
+ """
324
+ from obstore.store import AzureStore # noqa: PLC0415
325
+
326
+ opts = client_options if client_options is not None else obstore_client_options()
327
+ retry = obstore_retry_config()
328
+ log_obstore_config(label, client_options=opts, retry_config=retry)
329
+ kw: dict[str, object] = dict(
330
+ container_name=container, config=config, client_options=opts, retry_config=retry
331
+ )
332
+ if credential_provider is not None:
333
+ kw["credential_provider"] = credential_provider
334
+ isolate = (
335
+ _azure_config_has_explicit_credential(config) or credential_provider is not None
336
+ )
337
+ with _suppress_ambient_azure_env(isolate):
338
+ return AzureStore(**kw) # type: ignore[arg-type]
339
+
340
+
341
+ def make_gcs_store(
342
+ bucket: str,
343
+ config: dict[str, str] | None = None,
344
+ *,
345
+ label: str = "gcs",
346
+ client_options: ClientConfig | None = None,
347
+ credential_provider: object = None,
348
+ ) -> ObjectStore:
349
+ """Create a GCSStore with SDK-default client/retry config.
350
+
351
+ See :func:`make_s3_store` for rationale. On the ADC / Workload-Identity path
352
+ ``binding.py`` passes a ``credential_provider`` (obstore.auth.google, backed
353
+ by google-auth) instead of a key in ``config``: obstore's built-in GCS
354
+ credential-file decoder only understands ``service_account`` /
355
+ ``authorized_user`` files, NOT a Workload Identity Federation
356
+ ``external_account`` file — google-auth handles all of them.
357
+ """
358
+ from obstore.store import GCSStore # noqa: PLC0415
359
+
360
+ opts = client_options if client_options is not None else obstore_client_options()
361
+ retry = obstore_retry_config()
362
+ log_obstore_config(label, client_options=opts, retry_config=retry)
363
+ kw: dict[str, object] = dict(
364
+ bucket=bucket, config=config, client_options=opts, retry_config=retry
365
+ )
366
+ if credential_provider is not None:
367
+ kw["credential_provider"] = credential_provider
368
+ return GCSStore(**kw) # type: ignore[arg-type]
369
+
370
+
371
+ def log_obstore_config(
372
+ provider: str,
373
+ *,
374
+ client_options: ClientConfig | None,
375
+ retry_config: RetryConfig | None,
376
+ ) -> None:
377
+ """Log the configured client/retry options once at store creation time.
378
+
379
+ A prior RCA was wrong-footed by these values being invisible — we said
380
+ "single attempt" when ~5–6 attempts had actually happened in the Rust
381
+ layer at obstore's default 10×3 min retry budget. Surfacing what's
382
+ configured up front prevents that confusion next time.
383
+ """
384
+ logger.info(
385
+ "obstore configured for %s: client=%s retry=%s",
386
+ provider,
387
+ _redact_proxy_userinfo(client_options) if client_options else {},
388
+ dict(retry_config)
389
+ if retry_config
390
+ else "default(max_retries=10, retry_timeout=3m)",
391
+ )
392
+
393
+
394
+ def _redact_proxy_userinfo(client_options: ClientConfig) -> dict:
395
+ """Return a log-safe copy of *client_options* (the real config is untouched).
396
+
397
+ Masks ``proxy_url`` credentials and shrinks ``root_certificate`` to a byte
398
+ count, so logs never carry a proxy password or a full PEM bundle.
399
+ """
400
+ opts = dict(client_options)
401
+ proxy = opts.get("proxy_url")
402
+ if isinstance(proxy, str):
403
+ p = urlsplit(proxy)
404
+ if p.username or p.password:
405
+ host = p.hostname or ""
406
+ netloc = f"***@{host}:{p.port}" if p.port else f"***@{host}"
407
+ opts["proxy_url"] = urlunsplit(
408
+ (p.scheme, netloc, p.path, p.query, p.fragment)
409
+ )
410
+ root_cert = opts.get("root_certificate")
411
+ if isinstance(root_cert, (bytes, str)):
412
+ opts["root_certificate"] = f"<{len(root_cert)} bytes>"
413
+ return opts