foundry-dev-tools 2.1.24__tar.gz → 2.1.26__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.
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/PKG-INFO +1 -1
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/pyproject.toml +1 -1
- foundry_dev_tools-2.1.26/src/foundry_dev_tools/__about__.py +1 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/__init__.py +6 -1
- foundry_dev_tools-2.1.26/src/foundry_dev_tools/_optional/snowflake.py +15 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/cli/config.py +43 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/cli/info.py +86 -22
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/clients/api_client.py +35 -2
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/clients/multipass.py +25 -4
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/config/config.py +127 -22
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/config/context.py +1 -1
- foundry_dev_tools-2.1.26/src/foundry_dev_tools/config/palantir_mcp.py +226 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/config/token_provider.py +106 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/errors/meta.py +9 -0
- foundry_dev_tools-2.1.26/src/foundry_dev_tools/helpers/fast_snowflake_ingestion/__init__.py +21 -0
- foundry_dev_tools-2.1.26/src/foundry_dev_tools/helpers/fast_snowflake_ingestion/_impl.py +658 -0
- foundry_dev_tools-2.1.26/src/foundry_dev_tools/helpers/fast_snowflake_ingestion/utils.py +308 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/utils/compat.py +20 -2
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/utils/config.py +5 -0
- foundry_dev_tools-2.1.26/src/foundry_dev_tools/utils/scope.py +166 -0
- foundry_dev_tools-2.1.24/src/foundry_dev_tools/__about__.py +0 -1
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/README.md +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/_optional/__init__.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/_optional/foundry_platform_sdk.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/_optional/pandas.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/_optional/polars.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/_optional/pyarrow.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/_optional/pyspark.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/cached_foundry_client.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/cli/__init__.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/cli/build.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/cli/git.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/cli/git_credential_foundry.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/cli/main.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/cli/s3.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/cli/stubs.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/clients/__init__.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/clients/build2.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/clients/catalog.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/clients/compass.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/clients/context_client.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/clients/data_health.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/clients/data_proxy.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/clients/foundry_sql_server.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/clients/foundry_stats.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/clients/jemma.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/clients/magritte_coordinator.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/clients/metadata.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/clients/public_ontologies_client.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/clients/s3_client.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/clients/scheduler.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/clients/schema_inference.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/clients/tables.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/config/__init__.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/config/config_types.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/errors/__init__.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/errors/compass.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/errors/config.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/errors/dataset.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/errors/handling.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/errors/multipass.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/errors/sql.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/foundry_api_client.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/helpers/__init__.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/helpers/multipass/__init__.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/helpers/multipass/group.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/helpers/multipass/principal.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/helpers/multipass/user.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/public_sdk/__init__.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/public_sdk/auth.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/py.typed +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/resources/__init__.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/resources/dataset.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/resources/folder.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/resources/resource.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/utils/__init__.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/utils/api_types.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/utils/async_s3.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/utils/caches/__init__.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/utils/caches/metadata_store.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/utils/caches/spark_caches.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/utils/cli.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/utils/clients.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/utils/converter/__init__.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/utils/converter/foundry_spark.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/utils/misc.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/utils/public_api_types.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/utils/repo.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/utils/s3.py +0 -0
- {foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/utils/spark.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: foundry-dev-tools
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.26
|
|
4
4
|
Summary: Seamlessly run your Palantir Foundry Repository transforms code on your local machine.
|
|
5
5
|
Author-Email: Nicolas Renkamp <nicolas.renkamp@merckgroup.com>, Jonas Wunderlich <jonas.wunderlich@merckgroup.com>
|
|
6
6
|
License: Apache-2.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = '2.1.26'
|
|
@@ -5,7 +5,11 @@ from foundry_dev_tools.cached_foundry_client import CachedFoundryClient
|
|
|
5
5
|
from foundry_dev_tools.config.config import Config
|
|
6
6
|
from foundry_dev_tools.config.config_types import Host
|
|
7
7
|
from foundry_dev_tools.config.context import FoundryContext
|
|
8
|
-
from foundry_dev_tools.config.token_provider import
|
|
8
|
+
from foundry_dev_tools.config.token_provider import (
|
|
9
|
+
JWTTokenProvider,
|
|
10
|
+
OAuthTokenProvider,
|
|
11
|
+
PalantirMCPTokenProvider,
|
|
12
|
+
)
|
|
9
13
|
from foundry_dev_tools.foundry_api_client import FoundryRestClient
|
|
10
14
|
|
|
11
15
|
__all__ = [
|
|
@@ -15,6 +19,7 @@ __all__ = [
|
|
|
15
19
|
"JWTTokenProvider",
|
|
16
20
|
"FoundryContext",
|
|
17
21
|
"OAuthTokenProvider",
|
|
22
|
+
"PalantirMCPTokenProvider",
|
|
18
23
|
"FoundryRestClient",
|
|
19
24
|
"CachedFoundryClient",
|
|
20
25
|
]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
try:
|
|
4
|
+
import snowflake.connector.errors as snowflake_errors
|
|
5
|
+
import snowflake.snowpark.exceptions as snowpark_exceptions
|
|
6
|
+
|
|
7
|
+
snowflake_errors.__fake__ = False
|
|
8
|
+
snowpark_exceptions.__fake__ = False
|
|
9
|
+
except ImportError:
|
|
10
|
+
from foundry_dev_tools._optional import FakeModule
|
|
11
|
+
|
|
12
|
+
snowflake_errors = FakeModule("snowflake-snowpark-python")
|
|
13
|
+
snowpark_exceptions = FakeModule("snowflake-snowpark-python")
|
|
14
|
+
|
|
15
|
+
__all__ = ["snowflake_errors", "snowpark_exceptions"]
|
|
@@ -24,11 +24,16 @@ from rich.markdown import Markdown
|
|
|
24
24
|
from rich.prompt import IntPrompt
|
|
25
25
|
|
|
26
26
|
from foundry_dev_tools.cli.info import _config_section
|
|
27
|
+
from foundry_dev_tools.config import palantir_mcp
|
|
28
|
+
from foundry_dev_tools.config.config_types import DEFAULT_SCHEME
|
|
29
|
+
from foundry_dev_tools.errors.config import FoundryConfigError
|
|
27
30
|
from foundry_dev_tools.utils.compat import v1_to_v2_config_dict
|
|
28
31
|
from foundry_dev_tools.utils.config import (
|
|
29
32
|
PROJECT_CFG_FILE_NAME,
|
|
33
|
+
cfg_files,
|
|
30
34
|
find_project_config_file,
|
|
31
35
|
site_cfg_file,
|
|
36
|
+
user_cfg_file,
|
|
32
37
|
user_cfg_files,
|
|
33
38
|
)
|
|
34
39
|
from foundry_dev_tools.utils.repo import git_toplevel_dir
|
|
@@ -105,6 +110,44 @@ def config_cli(ctx: click.Context, profile: str | None):
|
|
|
105
110
|
console.print(_config_section(profile=profile))
|
|
106
111
|
|
|
107
112
|
|
|
113
|
+
@config_cli.command("init")
|
|
114
|
+
def init():
|
|
115
|
+
"""Create a minimal configuration for the Palantir MCP token Foundry DevTools uses."""
|
|
116
|
+
console = Console(markup=True)
|
|
117
|
+
existing = [path for path in cfg_files() if path.exists() and path.read_text().strip()]
|
|
118
|
+
if existing:
|
|
119
|
+
console.print(
|
|
120
|
+
f"A configuration already exists at {existing[0]!s}. Run `fdt config edit` to change it.",
|
|
121
|
+
)
|
|
122
|
+
sys.exit(1)
|
|
123
|
+
|
|
124
|
+
try:
|
|
125
|
+
credential = palantir_mcp.discover_palantir_mcp_credential()
|
|
126
|
+
except FoundryConfigError as e:
|
|
127
|
+
console.print(f"Can't create a configuration: {e}")
|
|
128
|
+
sys.exit(1)
|
|
129
|
+
if credential is None:
|
|
130
|
+
console.print(
|
|
131
|
+
f"No Palantir MCP token found in {palantir_mcp.palantir_mcp_config_path()}. "
|
|
132
|
+
"Authorize a Foundry host in Palantir MCP first, or configure credentials manually"
|
|
133
|
+
" with `fdt config edit`.",
|
|
134
|
+
)
|
|
135
|
+
sys.exit(1)
|
|
136
|
+
|
|
137
|
+
credentials: dict[str, object] = {"domain": credential.host.domain}
|
|
138
|
+
if credential.host.scheme != DEFAULT_SCHEME:
|
|
139
|
+
credentials["scheme"] = credential.host.scheme
|
|
140
|
+
credentials["palantir_mcp"] = {}
|
|
141
|
+
|
|
142
|
+
target = user_cfg_file()
|
|
143
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
144
|
+
target.write_text(tomli_w.dumps({"credentials": credentials}))
|
|
145
|
+
console.print(
|
|
146
|
+
f"Created {target!s} with the credentials of the Palantir MCP token for {credential.host.url}. "
|
|
147
|
+
"The auto-pickup notice will no longer be printed.",
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
|
|
108
151
|
@config_cli.command("edit")
|
|
109
152
|
def edit():
|
|
110
153
|
"""Let's you edit your Foundry DevTools configuration file more easily."""
|
|
@@ -8,7 +8,10 @@ import os
|
|
|
8
8
|
import platform
|
|
9
9
|
import subprocess
|
|
10
10
|
import sys
|
|
11
|
+
import time
|
|
12
|
+
from datetime import datetime, timezone
|
|
11
13
|
from pathlib import Path
|
|
14
|
+
from typing import TYPE_CHECKING
|
|
12
15
|
|
|
13
16
|
import click
|
|
14
17
|
from packaging.markers import _evaluate_markers, default_environment
|
|
@@ -21,6 +24,8 @@ from rich.tree import Tree
|
|
|
21
24
|
|
|
22
25
|
from foundry_dev_tools.__about__ import __version__
|
|
23
26
|
from foundry_dev_tools.config.config import (
|
|
27
|
+
Config,
|
|
28
|
+
TokenProvider,
|
|
24
29
|
_pure_config_dict,
|
|
25
30
|
get_config_dict,
|
|
26
31
|
parse_credentials_config,
|
|
@@ -30,6 +35,9 @@ from foundry_dev_tools.config.context import FoundryContext
|
|
|
30
35
|
from foundry_dev_tools.utils.cli import _bool_color, _bool_icon
|
|
31
36
|
from foundry_dev_tools.utils.config import cfg_files
|
|
32
37
|
|
|
38
|
+
if TYPE_CHECKING:
|
|
39
|
+
from rich.console import RenderableType
|
|
40
|
+
|
|
33
41
|
HIGHLIGHT_BEGIN = "[bold color(5)]"
|
|
34
42
|
HIGHLIGHT_END = "[/bold color(5)]"
|
|
35
43
|
|
|
@@ -207,23 +215,36 @@ def _dependency_section() -> Tree: # noqa: C901,PLR0912
|
|
|
207
215
|
return dependency_node
|
|
208
216
|
|
|
209
217
|
|
|
210
|
-
def
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
218
|
+
def _format_duration(seconds: float) -> str:
|
|
219
|
+
total = max(int(seconds), 0)
|
|
220
|
+
days, remainder = divmod(total, 86400)
|
|
221
|
+
hours, remainder = divmod(remainder, 3600)
|
|
222
|
+
minutes, seconds = divmod(remainder, 60)
|
|
223
|
+
parts = []
|
|
224
|
+
if days:
|
|
225
|
+
parts.append(f"{days}d")
|
|
226
|
+
if days or hours:
|
|
227
|
+
parts.append(f"{hours}h")
|
|
228
|
+
if days or hours or minutes:
|
|
229
|
+
parts.append(f"{minutes}m")
|
|
230
|
+
parts.append(f"{seconds}s")
|
|
231
|
+
return " ".join(parts)
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def _format_token_ttl(token_provider: TokenProvider) -> str | None:
|
|
235
|
+
"""Format the remaining lifetime of the provider's token, if the provider knows it."""
|
|
236
|
+
expires_at: float | None = None
|
|
237
|
+
with contextlib.suppress(Exception):
|
|
238
|
+
expires_at = token_provider.token_expires_at()
|
|
239
|
+
if expires_at is None:
|
|
240
|
+
return None
|
|
241
|
+
expires = datetime.fromtimestamp(expires_at, tz=timezone.utc).isoformat(timespec="seconds")
|
|
242
|
+
if expires_at <= time.time():
|
|
243
|
+
return f"expired at {expires}"
|
|
244
|
+
return f"expires in {_format_duration(expires_at - time.time())} (at {expires})"
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def _credentials_section(config: Config, config_dict: dict | None) -> list[RenderableType]:
|
|
227
248
|
try:
|
|
228
249
|
cred_config = parse_credentials_config(config_dict)
|
|
229
250
|
|
|
@@ -233,6 +254,10 @@ def _config_section(profile: str | None) -> Tree:
|
|
|
233
254
|
title=f"Using the {cred_config.__class__.__name__} implementation for authentication.",
|
|
234
255
|
)
|
|
235
256
|
for cred_config_entry, value in cred_config.__dict__.items():
|
|
257
|
+
# Provider internals (the cached credential and its refresh deadline)
|
|
258
|
+
# are state, not credential configuration.
|
|
259
|
+
if cred_config_entry in {"_credential", "_credential_stale_after"}:
|
|
260
|
+
continue
|
|
236
261
|
# This check needs to happend before the single underscore check
|
|
237
262
|
# Otherwise this check would be unecessary
|
|
238
263
|
if cred_config_entry.startswith("__"):
|
|
@@ -253,25 +278,64 @@ def _config_section(profile: str | None) -> Tree:
|
|
|
253
278
|
str(value),
|
|
254
279
|
)
|
|
255
280
|
|
|
281
|
+
if ttl := _format_token_ttl(cred_config):
|
|
282
|
+
cred_table.add_row("token_ttl", ttl)
|
|
283
|
+
|
|
256
284
|
ctx = FoundryContext(config=config, token_provider=cred_config)
|
|
257
|
-
config_node.add(cred_table)
|
|
258
285
|
username = None
|
|
259
286
|
with contextlib.suppress(Exception):
|
|
260
287
|
username = ctx.multipass.api_me().json()["username"]
|
|
261
|
-
|
|
288
|
+
return [
|
|
289
|
+
cred_table,
|
|
262
290
|
_bool_color(
|
|
263
291
|
bool(username),
|
|
264
292
|
(f"Successfully authenticated as '{username}'" if username else "Failed to authenticate"),
|
|
265
|
-
)
|
|
266
|
-
|
|
293
|
+
),
|
|
294
|
+
]
|
|
267
295
|
except Exception as e: # noqa: BLE001
|
|
268
|
-
|
|
296
|
+
return [
|
|
269
297
|
(
|
|
270
298
|
_bool_icon(False) + "Can't create a TokenProvider,"
|
|
271
299
|
" please refer to the documentation how to configure FoundryDevTools for authentication.\n"
|
|
272
300
|
f"Following Error was raised: {e}"
|
|
273
301
|
),
|
|
302
|
+
]
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def _config_section(profile: str | None) -> Tree:
|
|
306
|
+
config_node = Tree("Configuration")
|
|
307
|
+
config_table = Table("Config Name", "Value")
|
|
308
|
+
config_file_table = Table("Config File Path", "Exists")
|
|
309
|
+
|
|
310
|
+
config_dict = None
|
|
311
|
+
load_error: Exception | None = None
|
|
312
|
+
try:
|
|
313
|
+
if profile is None:
|
|
314
|
+
pure_config = _pure_config_dict()
|
|
315
|
+
if pure_config is not None:
|
|
316
|
+
profile = pure_config.get("profile")
|
|
317
|
+
config_dict = get_config_dict(profile=profile)
|
|
318
|
+
config = parse_general_config(config_dict)
|
|
319
|
+
except Exception as e: # noqa: BLE001
|
|
320
|
+
# `fdt info` is a diagnostic command: an invalid or ambiguous configuration
|
|
321
|
+
# must be reported here instead of aborting with a traceback.
|
|
322
|
+
load_error = e
|
|
323
|
+
|
|
324
|
+
config_node.label = "Configuration" + ((f"(Profile '{profile}')") if profile is not None else "")
|
|
325
|
+
if load_error is not None:
|
|
326
|
+
config_node.add(
|
|
327
|
+
_bool_icon(False) + "Could not load the Foundry DevTools configuration.\n"
|
|
328
|
+
f"Following Error was raised: {load_error}"
|
|
274
329
|
)
|
|
330
|
+
else:
|
|
331
|
+
for config_item, value in config.__dict__.items():
|
|
332
|
+
if isinstance(value, bool):
|
|
333
|
+
config_table.add_row(config_item, _bool_icon(value))
|
|
334
|
+
else:
|
|
335
|
+
config_table.add_row(config_item, str(value))
|
|
336
|
+
config_node.add(config_table)
|
|
337
|
+
for renderable in _credentials_section(config, config_dict):
|
|
338
|
+
config_node.add(renderable)
|
|
275
339
|
for cfg_file in cfg_files():
|
|
276
340
|
config_file_table.add_row(os.fspath(cfg_file), _bool_icon(cfg_file.is_file()))
|
|
277
341
|
config_node.add(config_file_table)
|
{foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/clients/api_client.py
RENAMED
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import contextlib
|
|
5
6
|
from typing import TYPE_CHECKING, ClassVar, Literal
|
|
6
7
|
|
|
7
8
|
from foundry_dev_tools.errors.handling import ErrorHandlingConfig, raise_foundry_api_error
|
|
9
|
+
from foundry_dev_tools.errors.meta import FoundryAPIError
|
|
8
10
|
from foundry_dev_tools.utils.clients import build_api_url, build_public_api_url
|
|
11
|
+
from foundry_dev_tools.utils.scope import build_auth_error_hint
|
|
9
12
|
|
|
10
13
|
if TYPE_CHECKING:
|
|
11
14
|
from requests import Response
|
|
@@ -26,6 +29,28 @@ if TYPE_CHECKING:
|
|
|
26
29
|
from foundry_dev_tools.config.context import FoundryContext
|
|
27
30
|
|
|
28
31
|
|
|
32
|
+
def _raise_foundry_api_error_with_hint(
|
|
33
|
+
context: FoundryContext,
|
|
34
|
+
response: Response,
|
|
35
|
+
error_handling: ErrorHandlingConfig | Literal[False] | None,
|
|
36
|
+
) -> None:
|
|
37
|
+
"""Raise the regular API error and append token diagnostics when available."""
|
|
38
|
+
try:
|
|
39
|
+
raise_foundry_api_error(response, error_handling)
|
|
40
|
+
except FoundryAPIError as exc:
|
|
41
|
+
try:
|
|
42
|
+
error_name = response.json().get("errorName")
|
|
43
|
+
except (AttributeError, ValueError):
|
|
44
|
+
error_name = None
|
|
45
|
+
hint = None
|
|
46
|
+
# Never mask the original API error.
|
|
47
|
+
with contextlib.suppress(Exception):
|
|
48
|
+
hint = build_auth_error_hint(context, response.status_code, error_name)
|
|
49
|
+
if hint:
|
|
50
|
+
exc.add_info(hint)
|
|
51
|
+
raise
|
|
52
|
+
|
|
53
|
+
|
|
29
54
|
class APIClient:
|
|
30
55
|
"""Base class for API clients."""
|
|
31
56
|
|
|
@@ -111,7 +136,11 @@ class APIClient:
|
|
|
111
136
|
cert=cert,
|
|
112
137
|
json=json,
|
|
113
138
|
)
|
|
114
|
-
|
|
139
|
+
if auth is None:
|
|
140
|
+
_raise_foundry_api_error_with_hint(self.context, response, error_handling)
|
|
141
|
+
else:
|
|
142
|
+
# A custom auth handler may use a different token than the context provider.
|
|
143
|
+
raise_foundry_api_error(response, error_handling)
|
|
115
144
|
return response
|
|
116
145
|
|
|
117
146
|
|
|
@@ -215,5 +244,9 @@ class PublicAPIClient:
|
|
|
215
244
|
cert=cert,
|
|
216
245
|
json=json,
|
|
217
246
|
)
|
|
218
|
-
|
|
247
|
+
if auth is None:
|
|
248
|
+
_raise_foundry_api_error_with_hint(self.context, response, error_handling)
|
|
249
|
+
else:
|
|
250
|
+
# A custom auth handler may use a different token than the context provider.
|
|
251
|
+
raise_foundry_api_error(response, error_handling)
|
|
219
252
|
return response
|
{foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/clients/multipass.py
RENAMED
|
@@ -143,7 +143,12 @@ class MultipassClient(APIClient):
|
|
|
143
143
|
)
|
|
144
144
|
|
|
145
145
|
def search(
|
|
146
|
-
self,
|
|
146
|
+
self,
|
|
147
|
+
query: str,
|
|
148
|
+
principal_types: set[api_types.PrincipalTypes] | None = None,
|
|
149
|
+
page_size: int = 1000,
|
|
150
|
+
max_results: int | None = None,
|
|
151
|
+
**kwargs,
|
|
147
152
|
) -> Iterator[dict]:
|
|
148
153
|
"""Searches for multipass principals based on a text.
|
|
149
154
|
|
|
@@ -151,21 +156,37 @@ class MultipassClient(APIClient):
|
|
|
151
156
|
query: the text string to search for
|
|
152
157
|
principal_types: set of principal types to search in, e.g. "GROUP"
|
|
153
158
|
Default is GROUP and USER
|
|
159
|
+
page_size: number of results per page, defaults to 1000
|
|
160
|
+
max_results: stop after yielding this many results, or None for all.
|
|
161
|
+
A search token that is a common substring (e.g. a middle initial
|
|
162
|
+
like "M") can match thousands of users, causing unbounded iteration.
|
|
154
163
|
**kwargs: gets passed to :py:meth:`APIClient.api_request`
|
|
155
164
|
"""
|
|
156
165
|
if principal_types is None:
|
|
157
166
|
principal_types = {"USER", "GROUP"}
|
|
158
167
|
|
|
159
|
-
json = {
|
|
168
|
+
json = {
|
|
169
|
+
"attributeFilters": {},
|
|
170
|
+
"principalTypes": list(principal_types),
|
|
171
|
+
"query": query,
|
|
172
|
+
"pageSize": page_size,
|
|
173
|
+
}
|
|
160
174
|
|
|
175
|
+
total = 0
|
|
161
176
|
next_start = None
|
|
162
177
|
while True:
|
|
163
178
|
if next_start:
|
|
164
179
|
json["pageStart"] = next_start
|
|
165
180
|
|
|
166
181
|
response_as_json = self.api_request("POST", "search/v2/search", json=json, **kwargs).json()
|
|
167
|
-
|
|
168
|
-
if
|
|
182
|
+
values = response_as_json["values"]
|
|
183
|
+
if max_results is not None:
|
|
184
|
+
values = values[: max_results - total]
|
|
185
|
+
yield from values
|
|
186
|
+
total += len(values)
|
|
187
|
+
if (next_start := response_as_json["nextPageToken"]) is None or (
|
|
188
|
+
max_results is not None and total >= max_results
|
|
189
|
+
):
|
|
169
190
|
break
|
|
170
191
|
|
|
171
192
|
def api_get_groups_of_user(self, **kwargs) -> requests.Response:
|
{foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/config/config.py
RENAMED
|
@@ -8,6 +8,12 @@ from pathlib import Path
|
|
|
8
8
|
from typing import TYPE_CHECKING
|
|
9
9
|
|
|
10
10
|
from foundry_dev_tools.config.config_types import Host
|
|
11
|
+
from foundry_dev_tools.config.palantir_mcp import (
|
|
12
|
+
REAUTHORIZE_HINT,
|
|
13
|
+
discover_palantir_mcp_credential,
|
|
14
|
+
palantir_mcp_config_path,
|
|
15
|
+
print_auto_pickup_notice,
|
|
16
|
+
)
|
|
11
17
|
from foundry_dev_tools.config.token_provider import (
|
|
12
18
|
TOKEN_PROVIDER_MAPPING,
|
|
13
19
|
AppServiceTokenProvider,
|
|
@@ -142,13 +148,101 @@ def _find_token_provider(credentials: dict) -> str | None:
|
|
|
142
148
|
return None
|
|
143
149
|
|
|
144
150
|
|
|
151
|
+
PALANTIR_MCP_PROVIDER = "palantir_mcp"
|
|
152
|
+
|
|
145
153
|
MISSING_TP_ERROR = TokenProviderConfigError(
|
|
146
154
|
"To authenticate with Foundry you need a TokenProvider. The token provider can be configured either via the"
|
|
147
155
|
" configuration file or the token_provider FoundryContext parameter."
|
|
148
156
|
)
|
|
149
157
|
|
|
150
158
|
|
|
151
|
-
def
|
|
159
|
+
def _auto_palantir_mcp_config(discovery_host: Host | None = None) -> dict | None:
|
|
160
|
+
"""Return a credentials config synthesized from the Palantir MCP cache, if available."""
|
|
161
|
+
if "APP_SERVICE_TS" in os.environ:
|
|
162
|
+
# App Service supplies its own token; do not override that environment.
|
|
163
|
+
return None
|
|
164
|
+
if discovery_host is None:
|
|
165
|
+
auto_credential = discover_palantir_mcp_credential()
|
|
166
|
+
else:
|
|
167
|
+
# A known host makes discovery optional: no matching cache entry just means
|
|
168
|
+
# that the caller's own credentials are used.
|
|
169
|
+
try:
|
|
170
|
+
auto_credential = discover_palantir_mcp_credential(host=discovery_host)
|
|
171
|
+
except TokenProviderConfigError:
|
|
172
|
+
return None
|
|
173
|
+
if auto_credential is None:
|
|
174
|
+
return None
|
|
175
|
+
print_auto_pickup_notice(auto_credential)
|
|
176
|
+
return {
|
|
177
|
+
"credentials": {
|
|
178
|
+
"domain": auto_credential.host.domain,
|
|
179
|
+
"scheme": auto_credential.host.scheme,
|
|
180
|
+
PALANTIR_MCP_PROVIDER: {},
|
|
181
|
+
},
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def _resolve_auto_credentials(
|
|
186
|
+
default_credentials: dict,
|
|
187
|
+
domain: str | None,
|
|
188
|
+
scheme: str | None,
|
|
189
|
+
token_provider_name: str | None,
|
|
190
|
+
discovery_host: Host | None = None,
|
|
191
|
+
) -> tuple[str | None, str | None, str | None]:
|
|
192
|
+
"""Fill missing host/provider values from the Palantir MCP token cache."""
|
|
193
|
+
if (domain and token_provider_name) or "APP_SERVICE_TS" in os.environ:
|
|
194
|
+
return domain, scheme, token_provider_name
|
|
195
|
+
|
|
196
|
+
# Only the Palantir MCP provider may be inferred. A provider that was selected
|
|
197
|
+
# explicitly keeps its existing configuration validation, so explicit
|
|
198
|
+
# credentials are never sent to a host discovered from the MCP cache.
|
|
199
|
+
if token_provider_name not in (None, PALANTIR_MCP_PROVIDER):
|
|
200
|
+
return domain, scheme, token_provider_name
|
|
201
|
+
|
|
202
|
+
# Use the origin the provider will use, including the configured scheme.
|
|
203
|
+
host = Host(domain, scheme) if domain else discovery_host
|
|
204
|
+
# When a host is known, discovery is optional: a missing cache entry must not
|
|
205
|
+
# block the regular missing-provider error.
|
|
206
|
+
optional_discovery = token_provider_name is None and host is not None
|
|
207
|
+
try:
|
|
208
|
+
auto_credential = discover_palantir_mcp_credential(host=host)
|
|
209
|
+
except TokenProviderConfigError:
|
|
210
|
+
if not optional_discovery:
|
|
211
|
+
raise
|
|
212
|
+
auto_credential = None
|
|
213
|
+
if auto_credential is None:
|
|
214
|
+
return domain, scheme, token_provider_name
|
|
215
|
+
|
|
216
|
+
if not domain:
|
|
217
|
+
domain = auto_credential.host.domain
|
|
218
|
+
if not scheme:
|
|
219
|
+
scheme = auto_credential.host.scheme
|
|
220
|
+
if not token_provider_name:
|
|
221
|
+
token_provider_name = PALANTIR_MCP_PROVIDER
|
|
222
|
+
default_credentials.setdefault(PALANTIR_MCP_PROVIDER, {})
|
|
223
|
+
print_auto_pickup_notice(auto_credential)
|
|
224
|
+
return domain, scheme, token_provider_name
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def _resolve_profile_config(config: dict, profile: str | None) -> tuple[dict, dict]:
|
|
228
|
+
"""Return the profile's credentials and config sections."""
|
|
229
|
+
if profile is None:
|
|
230
|
+
profile = config.get("profile")
|
|
231
|
+
if profile in ("config", "credentials"):
|
|
232
|
+
msg = f"Profile name can't be {profile}"
|
|
233
|
+
raise AttributeError(msg)
|
|
234
|
+
if profile and (profile_config := config.get(profile)) and isinstance(profile_config, dict):
|
|
235
|
+
return profile_config.get("credentials", {}), profile_config.get("config", {})
|
|
236
|
+
# use empty profile sections if no profile is specified
|
|
237
|
+
return {}, {}
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def get_config_dict(
|
|
241
|
+
profile: str | None = None,
|
|
242
|
+
env: bool = True,
|
|
243
|
+
auto_discover: bool = True,
|
|
244
|
+
discovery_host: Host | None = None,
|
|
245
|
+
) -> dict | None:
|
|
152
246
|
"""Loads config from the config files and environment variables.
|
|
153
247
|
|
|
154
248
|
Profiles make configs like this possible:
|
|
@@ -167,35 +261,45 @@ def get_config_dict(profile: str | None = None, env: bool = True) -> dict | None
|
|
|
167
261
|
Args:
|
|
168
262
|
profile: The profile to use, if None the default profile is used
|
|
169
263
|
env: Whether to load the environment variables
|
|
264
|
+
auto_discover: Whether to fall back to the Palantir MCP token cache when the
|
|
265
|
+
configuration does not define credentials. Set to False when credentials
|
|
266
|
+
are passed explicitly.
|
|
267
|
+
discovery_host: Host to use when the configuration does not define one, for
|
|
268
|
+
example an explicit URL supplied by a v1 caller.
|
|
170
269
|
"""
|
|
171
270
|
config = _pure_config_dict(env=env)
|
|
172
271
|
if not config:
|
|
173
|
-
return None
|
|
174
|
-
|
|
175
|
-
profile = config.get("profile")
|
|
176
|
-
if profile in ("config", "credentials"):
|
|
177
|
-
msg = f"Profile name can't be {profile}"
|
|
178
|
-
raise AttributeError(msg)
|
|
179
|
-
if profile and (profile_config := config.get(profile)) and isinstance(profile_config, dict):
|
|
180
|
-
profile_credentials = profile_config.get("credentials", {})
|
|
181
|
-
profile_config = profile_config.get("config", {})
|
|
182
|
-
else:
|
|
183
|
-
# use an empty profile config if no profile is specified
|
|
184
|
-
# this aims to reduce duplicate code
|
|
185
|
-
# but is going to do useless operations
|
|
186
|
-
profile_credentials = {}
|
|
187
|
-
profile_config = {}
|
|
272
|
+
return _auto_palantir_mcp_config(discovery_host) if auto_discover else None
|
|
273
|
+
profile_credentials, profile_general_config = _resolve_profile_config(config, profile)
|
|
188
274
|
|
|
189
275
|
default_credentials = config.get("credentials", {})
|
|
190
276
|
domain = profile_credentials.pop("domain", default_credentials.pop("domain", None))
|
|
191
|
-
# a domain must always be provided
|
|
192
|
-
if not domain:
|
|
193
|
-
raise MissingFoundryHostError
|
|
194
|
-
|
|
195
277
|
scheme = profile_credentials.pop("scheme", default_credentials.pop("scheme", None))
|
|
196
278
|
|
|
197
279
|
# decide which will be the token provider used
|
|
198
280
|
token_provider_name = _find_token_provider(profile_credentials) or _find_token_provider(default_credentials)
|
|
281
|
+
|
|
282
|
+
# If the Foundry DevTools configuration does not fully define credentials,
|
|
283
|
+
# fall back to the token Palantir MCP already cached. Explicit credentials
|
|
284
|
+
# always take precedence.
|
|
285
|
+
if auto_discover:
|
|
286
|
+
domain, scheme, token_provider_name = _resolve_auto_credentials(
|
|
287
|
+
default_credentials,
|
|
288
|
+
domain,
|
|
289
|
+
scheme,
|
|
290
|
+
token_provider_name,
|
|
291
|
+
discovery_host,
|
|
292
|
+
)
|
|
293
|
+
|
|
294
|
+
# a domain must always be provided
|
|
295
|
+
if not domain:
|
|
296
|
+
if auto_discover and token_provider_name == PALANTIR_MCP_PROVIDER:
|
|
297
|
+
# The provider was configured explicitly, so point at the missing token
|
|
298
|
+
# instead of complaining about the host it could not discover.
|
|
299
|
+
msg = f"No Palantir MCP token found in {palantir_mcp_config_path()}. {REAUTHORIZE_HINT}"
|
|
300
|
+
raise TokenProviderConfigError(msg)
|
|
301
|
+
raise MissingFoundryHostError
|
|
302
|
+
|
|
199
303
|
if not token_provider_name:
|
|
200
304
|
if "APP_SERVICE_TS" in os.environ:
|
|
201
305
|
token_provider_name = "app_service" # noqa: S105
|
|
@@ -203,7 +307,7 @@ def get_config_dict(profile: str | None = None, env: bool = True) -> dict | None
|
|
|
203
307
|
raise MISSING_TP_ERROR
|
|
204
308
|
# merge the profile config with the non-prefixed config
|
|
205
309
|
return_config = {}
|
|
206
|
-
merged_config = merge_dicts(config.get("config", {}),
|
|
310
|
+
merged_config = merge_dicts(config.get("config", {}), profile_general_config)
|
|
207
311
|
if merged_config:
|
|
208
312
|
return_config["config"] = merged_config
|
|
209
313
|
return_config["credentials"] = {
|
|
@@ -235,7 +339,8 @@ def parse_credentials_config(config_dict: dict | None) -> TokenProvider:
|
|
|
235
339
|
if tp_config is None or len(tp_config) == 0:
|
|
236
340
|
tp_config = {}
|
|
237
341
|
elif not isinstance(tp_config, dict):
|
|
238
|
-
|
|
342
|
+
# palantir_mcp has no required option, allow `palantir_mcp = ""`
|
|
343
|
+
tp_config = {} if tp_name == PALANTIR_MCP_PROVIDER else {tp_name: tp_config}
|
|
239
344
|
except KeyError:
|
|
240
345
|
tp_name, tp_config = None, None
|
|
241
346
|
|
{foundry_dev_tools-2.1.24 → foundry_dev_tools-2.1.26}/src/foundry_dev_tools/config/context.py
RENAMED
|
@@ -58,7 +58,7 @@ class FoundryContext:
|
|
|
58
58
|
profile: str | None = None,
|
|
59
59
|
) -> None:
|
|
60
60
|
if config is None or token_provider is None:
|
|
61
|
-
config_dict = get_config_dict(profile)
|
|
61
|
+
config_dict = get_config_dict(profile, auto_discover=token_provider is None)
|
|
62
62
|
self.config = config or parse_general_config(config_dict)
|
|
63
63
|
self.token_provider = token_provider or parse_credentials_config(config_dict)
|
|
64
64
|
else:
|