tinet-data-foundry-cli 0.1.1__tar.gz → 0.1.2__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 (17) hide show
  1. {tinet_data_foundry_cli-0.1.1 → tinet_data_foundry_cli-0.1.2}/PKG-INFO +8 -1
  2. {tinet_data_foundry_cli-0.1.1 → tinet_data_foundry_cli-0.1.2}/README.md +7 -0
  3. {tinet_data_foundry_cli-0.1.1 → tinet_data_foundry_cli-0.1.2}/pyproject.toml +1 -1
  4. tinet_data_foundry_cli-0.1.2/src/tinet_data_foundry_cli/__init__.py +1 -0
  5. {tinet_data_foundry_cli-0.1.1 → tinet_data_foundry_cli-0.1.2}/src/tinet_data_foundry_cli/cli.py +31 -2
  6. {tinet_data_foundry_cli-0.1.1 → tinet_data_foundry_cli-0.1.2}/src/tinet_data_foundry_cli/client.py +6 -0
  7. {tinet_data_foundry_cli-0.1.1 → tinet_data_foundry_cli-0.1.2}/src/tinet_data_foundry_cli.egg-info/PKG-INFO +8 -1
  8. {tinet_data_foundry_cli-0.1.1 → tinet_data_foundry_cli-0.1.2}/tests/test_cli.py +4 -2
  9. tinet_data_foundry_cli-0.1.1/src/tinet_data_foundry_cli/__init__.py +0 -1
  10. {tinet_data_foundry_cli-0.1.1 → tinet_data_foundry_cli-0.1.2}/setup.cfg +0 -0
  11. {tinet_data_foundry_cli-0.1.1 → tinet_data_foundry_cli-0.1.2}/src/tinet_data_foundry_cli/__main__.py +0 -0
  12. {tinet_data_foundry_cli-0.1.1 → tinet_data_foundry_cli-0.1.2}/src/tinet_data_foundry_cli/auth.py +0 -0
  13. {tinet_data_foundry_cli-0.1.1 → tinet_data_foundry_cli-0.1.2}/src/tinet_data_foundry_cli.egg-info/SOURCES.txt +0 -0
  14. {tinet_data_foundry_cli-0.1.1 → tinet_data_foundry_cli-0.1.2}/src/tinet_data_foundry_cli.egg-info/dependency_links.txt +0 -0
  15. {tinet_data_foundry_cli-0.1.1 → tinet_data_foundry_cli-0.1.2}/src/tinet_data_foundry_cli.egg-info/entry_points.txt +0 -0
  16. {tinet_data_foundry_cli-0.1.1 → tinet_data_foundry_cli-0.1.2}/src/tinet_data_foundry_cli.egg-info/top_level.txt +0 -0
  17. {tinet_data_foundry_cli-0.1.1 → tinet_data_foundry_cli-0.1.2}/tests/test_sign.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tinet-data-foundry-cli
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: Tinet Data Foundry 取数 CLI(catalog / query / schema)
5
5
  Author: Tinet
6
6
  License: MIT
@@ -41,6 +41,13 @@ tdf query \
41
41
 
42
42
  需要 Python **≥ 3.10**。若 pip 提示 scripts 目录不在 PATH,把该目录加入 PATH,或用 `python3 -m tinet_data_foundry_cli`。
43
43
 
44
+ 公司代理 / 自签证书导致 `CERTIFICATE_VERIFY_FAILED` 时:
45
+
46
+ ```bash
47
+ tdf --insecure catalog
48
+ tdf catalog --insecure
49
+ ```
50
+
44
51
  | 命令 | 接口 |
45
52
  | --- | --- |
46
53
  | `tdf catalog` | `GET /data-api/v1/catalog` |
@@ -24,6 +24,13 @@ tdf query \
24
24
 
25
25
  需要 Python **≥ 3.10**。若 pip 提示 scripts 目录不在 PATH,把该目录加入 PATH,或用 `python3 -m tinet_data_foundry_cli`。
26
26
 
27
+ 公司代理 / 自签证书导致 `CERTIFICATE_VERIFY_FAILED` 时:
28
+
29
+ ```bash
30
+ tdf --insecure catalog
31
+ tdf catalog --insecure
32
+ ```
33
+
27
34
  | 命令 | 接口 |
28
35
  | --- | --- |
29
36
  | `tdf catalog` | `GET /data-api/v1/catalog` |
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "tinet-data-foundry-cli"
7
- version = "0.1.1"
7
+ version = "0.1.2"
8
8
  description = "Tinet Data Foundry 取数 CLI(catalog / query / schema)"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -0,0 +1 @@
1
+ __version__ = "0.1.2"
@@ -7,7 +7,7 @@ from typing import Any, List, Mapping, Optional
7
7
 
8
8
  from tinet_data_foundry_cli import __version__
9
9
  from tinet_data_foundry_cli.auth import credentials
10
- from tinet_data_foundry_cli.client import ApiError, request
10
+ from tinet_data_foundry_cli.client import ApiError, TransportError, request
11
11
 
12
12
 
13
13
  def _parse_json(raw: Optional[str], flag: str) -> Any:
@@ -52,6 +52,16 @@ def _print_catalog_table(rows: List[Mapping[str, Any]]) -> None:
52
52
  print(" ".join(_cell(row.get(key), w) for key, _, w in cols))
53
53
 
54
54
 
55
+ def _exit_transport(err: TransportError) -> None:
56
+ raise SystemExit(
57
+ "无法连接取数网关:"
58
+ f"{err}\n"
59
+ "若错误含 CERTIFICATE_VERIFY_FAILED / self-signed certificate,多半是公司代理或自签证书。"
60
+ "请加 --insecure(写在子命令前或后均可),例如:\n"
61
+ " tdf --insecure catalog"
62
+ ) from err
63
+
64
+
55
65
  def _exit_api(err: ApiError) -> None:
56
66
  payload = err.payload if isinstance(err.payload, dict) else {"message": str(err.payload)}
57
67
  _print_json(payload)
@@ -93,6 +103,8 @@ def cmd_catalog(args: argparse.Namespace) -> int:
93
103
  )
94
104
  except ApiError as ex:
95
105
  _exit_api(ex)
106
+ except TransportError as ex:
107
+ _exit_transport(ex)
96
108
  if args.dry_run or args.format == "json":
97
109
  _print_json(parsed)
98
110
  return 0
@@ -135,6 +147,8 @@ def cmd_query(args: argparse.Namespace) -> int:
135
147
  )
136
148
  except ApiError as ex:
137
149
  _exit_api(ex)
150
+ except TransportError as ex:
151
+ _exit_transport(ex)
138
152
  _print_json(parsed)
139
153
  if isinstance(parsed, dict) and parsed.get("code") not in (None, 0, "0") and not args.dry_run:
140
154
  return 1
@@ -157,12 +171,24 @@ def cmd_schema(args: argparse.Namespace) -> int:
157
171
  )
158
172
  except ApiError as ex:
159
173
  _exit_api(ex)
174
+ except TransportError as ex:
175
+ _exit_transport(ex)
160
176
  _print_json(parsed)
161
177
  if isinstance(parsed, dict) and parsed.get("code") not in (None, 0, "0") and not args.dry_run:
162
178
  return 1
163
179
  return 0
164
180
 
165
181
 
182
+ def _add_insecure(parser: argparse.ArgumentParser, *, overlay: bool = False) -> None:
183
+ kwargs: dict[str, Any] = {
184
+ "action": "store_true",
185
+ "help": "跳过 TLS 校验(公司代理 / 自签证书,仅联调)",
186
+ }
187
+ if overlay:
188
+ kwargs["default"] = argparse.SUPPRESS
189
+ parser.add_argument("-k", "--insecure", **kwargs)
190
+
191
+
166
192
  def build_parser() -> argparse.ArgumentParser:
167
193
  p = argparse.ArgumentParser(
168
194
  prog="tdf",
@@ -171,11 +197,12 @@ def build_parser() -> argparse.ArgumentParser:
171
197
  p.add_argument("--version", action="version", version=f"tinet-data-foundry-cli {__version__}")
172
198
  p.add_argument("--endpoint", help="覆盖 DF_ENDPOINT")
173
199
  p.add_argument("--timeout", type=float, default=30)
174
- p.add_argument("--insecure", action="store_true", help="跳过 TLS 校验(仅联调)")
200
+ _add_insecure(p)
175
201
  p.add_argument("--dry-run", action="store_true", help="只打印将发送的请求,不访问网关")
176
202
  sub = p.add_subparsers(dest="cmd", required=True)
177
203
 
178
204
  c = sub.add_parser("catalog", help="列出当前凭证有权访问的数据目录")
205
+ _add_insecure(c, overlay=True)
179
206
  c.add_argument("--keyword")
180
207
  c.add_argument("--layer", choices=["ods", "dwd"])
181
208
  c.add_argument("--domain", help="业务域 ID 或名称")
@@ -183,6 +210,7 @@ def build_parser() -> argparse.ArgumentParser:
183
210
  c.set_defaults(func=cmd_catalog)
184
211
 
185
212
  q = sub.add_parser("query", help="查询 Dataset")
213
+ _add_insecure(q, overlay=True)
186
214
  q.add_argument("--dataset", required=True)
187
215
  q.add_argument("--fields", help="逗号分隔列名")
188
216
  q.add_argument("--filter", help="filter AST JSON")
@@ -193,6 +221,7 @@ def build_parser() -> argparse.ArgumentParser:
193
221
  q.set_defaults(func=cmd_query)
194
222
 
195
223
  s = sub.add_parser("schema", help="拉取 Dataset Schema")
224
+ _add_insecure(s, overlay=True)
196
225
  s.add_argument("--dataset", required=True)
197
226
  s.set_defaults(func=cmd_schema)
198
227
  return p
@@ -17,6 +17,10 @@ class ApiError(Exception):
17
17
  super().__init__(f"HTTP {http_status}: {payload}")
18
18
 
19
19
 
20
+ class TransportError(Exception):
21
+ """网络或 TLS 失败(含公司代理自签证书)。"""
22
+
23
+
20
24
  def request(
21
25
  method: str,
22
26
  endpoint: str,
@@ -65,3 +69,5 @@ def request(
65
69
  except json.JSONDecodeError:
66
70
  parsed = {"message": raw.decode("utf-8", errors="replace")}
67
71
  raise ApiError(ex.code, parsed) from ex
72
+ except (urllib.error.URLError, ssl.SSLError, TimeoutError, OSError) as ex:
73
+ raise TransportError(str(ex)) from ex
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tinet-data-foundry-cli
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: Tinet Data Foundry 取数 CLI(catalog / query / schema)
5
5
  Author: Tinet
6
6
  License: MIT
@@ -41,6 +41,13 @@ tdf query \
41
41
 
42
42
  需要 Python **≥ 3.10**。若 pip 提示 scripts 目录不在 PATH,把该目录加入 PATH,或用 `python3 -m tinet_data_foundry_cli`。
43
43
 
44
+ 公司代理 / 自签证书导致 `CERTIFICATE_VERIFY_FAILED` 时:
45
+
46
+ ```bash
47
+ tdf --insecure catalog
48
+ tdf catalog --insecure
49
+ ```
50
+
44
51
  | 命令 | 接口 |
45
52
  | --- | --- |
46
53
  | `tdf catalog` | `GET /data-api/v1/catalog` |
@@ -11,8 +11,10 @@ class CliParserTest(unittest.TestCase):
11
11
  self.assertEqual(catalog.cmd, "catalog")
12
12
  query = parser.parse_args(["query", "--dataset", "ds_1", "--page-no", "1", "--page-size", "10"])
13
13
  self.assertEqual(query.cmd, "query")
14
- schema = parser.parse_args(["schema", "--dataset", "ds_1"])
15
- self.assertEqual(schema.cmd, "schema")
14
+ catalog_k = parser.parse_args(["catalog", "--insecure"])
15
+ self.assertTrue(catalog_k.insecure)
16
+ catalog_before = parser.parse_args(["--insecure", "catalog"])
17
+ self.assertTrue(catalog_before.insecure)
16
18
 
17
19
  def test_dry_run_catalog_does_not_need_network(self):
18
20
  with patch.dict("os.environ", {"DF_AK": "ak", "DF_SK": "sk" * 8}, clear=False):
@@ -1 +0,0 @@
1
- __version__ = "0.1.1"