tinet-data-foundry-cli 0.1.1__tar.gz → 0.1.3__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.3}/PKG-INFO +30 -3
  2. {tinet_data_foundry_cli-0.1.1 → tinet_data_foundry_cli-0.1.3}/README.md +29 -2
  3. {tinet_data_foundry_cli-0.1.1 → tinet_data_foundry_cli-0.1.3}/pyproject.toml +1 -1
  4. tinet_data_foundry_cli-0.1.3/src/tinet_data_foundry_cli/__init__.py +1 -0
  5. {tinet_data_foundry_cli-0.1.1 → tinet_data_foundry_cli-0.1.3}/src/tinet_data_foundry_cli/cli.py +31 -2
  6. {tinet_data_foundry_cli-0.1.1 → tinet_data_foundry_cli-0.1.3}/src/tinet_data_foundry_cli/client.py +6 -0
  7. {tinet_data_foundry_cli-0.1.1 → tinet_data_foundry_cli-0.1.3}/src/tinet_data_foundry_cli.egg-info/PKG-INFO +30 -3
  8. {tinet_data_foundry_cli-0.1.1 → tinet_data_foundry_cli-0.1.3}/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.3}/setup.cfg +0 -0
  11. {tinet_data_foundry_cli-0.1.1 → tinet_data_foundry_cli-0.1.3}/src/tinet_data_foundry_cli/__main__.py +0 -0
  12. {tinet_data_foundry_cli-0.1.1 → tinet_data_foundry_cli-0.1.3}/src/tinet_data_foundry_cli/auth.py +0 -0
  13. {tinet_data_foundry_cli-0.1.1 → tinet_data_foundry_cli-0.1.3}/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.3}/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.3}/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.3}/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.3}/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.3
4
4
  Summary: Tinet Data Foundry 取数 CLI(catalog / query / schema)
5
5
  Author: Tinet
6
6
  License: MIT
@@ -19,7 +19,11 @@ Description-Content-Type: text/markdown
19
19
 
20
20
  Tinet Data Foundry 取数 CLI。包名 `tinet-data-foundry-cli`,命令 **`tdf`**(避开系统磁盘命令 `df`)。
21
21
 
22
- 鉴权只用环境变量,**不要**把 AccessKey / SecretKey 写入本地文件。
22
+ 鉴权只用环境变量,**不要**把 AccessKey / SecretKey 写入本地文件。需要 Python **≥ 3.10**。
23
+
24
+ macOS / Linux 用 Terminal(bash / zsh)。Windows 用 **cmd.exe** 跑下面示例(不要用 PowerShell 传 JSON:`export` 不可用,引号也会被剥掉)。
25
+
26
+ ## macOS / Linux
23
27
 
24
28
  ```bash
25
29
  pip install -U tinet-data-foundry-cli
@@ -39,7 +43,30 @@ tdf query \
39
43
  --page-size 10
40
44
  ```
41
45
 
42
- 需要 Python **≥ 3.10**。若 pip 提示 scripts 目录不在 PATH,把该目录加入 PATH,或用 `python3 -m tinet_data_foundry_cli`。
46
+ 若 pip 提示 scripts 目录不在 PATH,把该目录加入 PATH,或用 `python3 -m tinet_data_foundry_cli`。
47
+
48
+ ## Windows(cmd.exe)
49
+
50
+ ```bat
51
+ pip install -U tinet-data-foundry-cli
52
+
53
+ set DF_ENDPOINT=https://data-foundry-data-api.tinetcloud.com
54
+ set DF_AK=你的_AccessKey
55
+ set DF_SK=你的_SecretKey
56
+
57
+ tdf catalog
58
+ tdf schema --dataset "DATASET_ID"
59
+ tdf query --dataset "DATASET_ID" --fields "id" --filter "{\"op\":\"eq\",\"field\":\"id\",\"value\":\"sample\"}" --sort "[{\"field\":\"id\",\"direction\":\"DESC\"}]" --page-no 1 --page-size 10
60
+ ```
61
+
62
+ 环境变量只对当前 cmd 窗口有效。JSON 参数用 `\"` 转义,整条命令写在一行。
63
+
64
+ 公司代理 / 自签证书导致 `CERTIFICATE_VERIFY_FAILED` 时:
65
+
66
+ ```bash
67
+ tdf --insecure catalog
68
+ tdf catalog --insecure
69
+ ```
43
70
 
44
71
  | 命令 | 接口 |
45
72
  | --- | --- |
@@ -2,7 +2,11 @@
2
2
 
3
3
  Tinet Data Foundry 取数 CLI。包名 `tinet-data-foundry-cli`,命令 **`tdf`**(避开系统磁盘命令 `df`)。
4
4
 
5
- 鉴权只用环境变量,**不要**把 AccessKey / SecretKey 写入本地文件。
5
+ 鉴权只用环境变量,**不要**把 AccessKey / SecretKey 写入本地文件。需要 Python **≥ 3.10**。
6
+
7
+ macOS / Linux 用 Terminal(bash / zsh)。Windows 用 **cmd.exe** 跑下面示例(不要用 PowerShell 传 JSON:`export` 不可用,引号也会被剥掉)。
8
+
9
+ ## macOS / Linux
6
10
 
7
11
  ```bash
8
12
  pip install -U tinet-data-foundry-cli
@@ -22,7 +26,30 @@ tdf query \
22
26
  --page-size 10
23
27
  ```
24
28
 
25
- 需要 Python **≥ 3.10**。若 pip 提示 scripts 目录不在 PATH,把该目录加入 PATH,或用 `python3 -m tinet_data_foundry_cli`。
29
+ 若 pip 提示 scripts 目录不在 PATH,把该目录加入 PATH,或用 `python3 -m tinet_data_foundry_cli`。
30
+
31
+ ## Windows(cmd.exe)
32
+
33
+ ```bat
34
+ pip install -U tinet-data-foundry-cli
35
+
36
+ set DF_ENDPOINT=https://data-foundry-data-api.tinetcloud.com
37
+ set DF_AK=你的_AccessKey
38
+ set DF_SK=你的_SecretKey
39
+
40
+ tdf catalog
41
+ tdf schema --dataset "DATASET_ID"
42
+ tdf query --dataset "DATASET_ID" --fields "id" --filter "{\"op\":\"eq\",\"field\":\"id\",\"value\":\"sample\"}" --sort "[{\"field\":\"id\",\"direction\":\"DESC\"}]" --page-no 1 --page-size 10
43
+ ```
44
+
45
+ 环境变量只对当前 cmd 窗口有效。JSON 参数用 `\"` 转义,整条命令写在一行。
46
+
47
+ 公司代理 / 自签证书导致 `CERTIFICATE_VERIFY_FAILED` 时:
48
+
49
+ ```bash
50
+ tdf --insecure catalog
51
+ tdf catalog --insecure
52
+ ```
26
53
 
27
54
  | 命令 | 接口 |
28
55
  | --- | --- |
@@ -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.3"
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.3"
@@ -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.3
4
4
  Summary: Tinet Data Foundry 取数 CLI(catalog / query / schema)
5
5
  Author: Tinet
6
6
  License: MIT
@@ -19,7 +19,11 @@ Description-Content-Type: text/markdown
19
19
 
20
20
  Tinet Data Foundry 取数 CLI。包名 `tinet-data-foundry-cli`,命令 **`tdf`**(避开系统磁盘命令 `df`)。
21
21
 
22
- 鉴权只用环境变量,**不要**把 AccessKey / SecretKey 写入本地文件。
22
+ 鉴权只用环境变量,**不要**把 AccessKey / SecretKey 写入本地文件。需要 Python **≥ 3.10**。
23
+
24
+ macOS / Linux 用 Terminal(bash / zsh)。Windows 用 **cmd.exe** 跑下面示例(不要用 PowerShell 传 JSON:`export` 不可用,引号也会被剥掉)。
25
+
26
+ ## macOS / Linux
23
27
 
24
28
  ```bash
25
29
  pip install -U tinet-data-foundry-cli
@@ -39,7 +43,30 @@ tdf query \
39
43
  --page-size 10
40
44
  ```
41
45
 
42
- 需要 Python **≥ 3.10**。若 pip 提示 scripts 目录不在 PATH,把该目录加入 PATH,或用 `python3 -m tinet_data_foundry_cli`。
46
+ 若 pip 提示 scripts 目录不在 PATH,把该目录加入 PATH,或用 `python3 -m tinet_data_foundry_cli`。
47
+
48
+ ## Windows(cmd.exe)
49
+
50
+ ```bat
51
+ pip install -U tinet-data-foundry-cli
52
+
53
+ set DF_ENDPOINT=https://data-foundry-data-api.tinetcloud.com
54
+ set DF_AK=你的_AccessKey
55
+ set DF_SK=你的_SecretKey
56
+
57
+ tdf catalog
58
+ tdf schema --dataset "DATASET_ID"
59
+ tdf query --dataset "DATASET_ID" --fields "id" --filter "{\"op\":\"eq\",\"field\":\"id\",\"value\":\"sample\"}" --sort "[{\"field\":\"id\",\"direction\":\"DESC\"}]" --page-no 1 --page-size 10
60
+ ```
61
+
62
+ 环境变量只对当前 cmd 窗口有效。JSON 参数用 `\"` 转义,整条命令写在一行。
63
+
64
+ 公司代理 / 自签证书导致 `CERTIFICATE_VERIFY_FAILED` 时:
65
+
66
+ ```bash
67
+ tdf --insecure catalog
68
+ tdf catalog --insecure
69
+ ```
43
70
 
44
71
  | 命令 | 接口 |
45
72
  | --- | --- |
@@ -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"