zt-apollo-cli 0.2.1__py3-none-any.whl

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.
apollo_cli/__init__.py ADDED
File without changes
apollo_cli/api.py ADDED
@@ -0,0 +1,109 @@
1
+ """Apollo API 请求封装"""
2
+ import requests
3
+
4
+ from .auth import get_auth_cookies, get_auth_headers
5
+ from .config import config
6
+
7
+
8
+ class ApolloApi:
9
+ """Apollo API 客户端"""
10
+
11
+ def __init__(self):
12
+ self.base_url = config.base_url
13
+
14
+ def _request(self, method: str, path: str, **kwargs):
15
+ """发送 API 请求"""
16
+ cookies = get_auth_cookies()
17
+ headers = get_auth_headers(cookies)
18
+ extra_headers = kwargs.pop("headers", None)
19
+ if extra_headers:
20
+ headers.update(extra_headers)
21
+ url = f"{self.base_url}/{path.lstrip('/')}"
22
+
23
+ response = requests.request(
24
+ method=method,
25
+ url=url,
26
+ headers=headers,
27
+ cookies=cookies,
28
+ **kwargs
29
+ )
30
+
31
+ if response.status_code >= 400:
32
+ raise Exception(f"Apollo API 错误: {response.status_code} {response.text}")
33
+
34
+ try:
35
+ return response.json()
36
+ except ValueError:
37
+ return response.text
38
+
39
+ def list_organizations(self):
40
+ """列出部门"""
41
+ return self._request("GET", "/organizations")
42
+
43
+ def search_apps(self, query: str, page: int = 0, size: int = 20):
44
+ """按 appId 或名称搜索应用"""
45
+ return self._request(
46
+ "GET",
47
+ "/apps/search/by-appid-or-name",
48
+ params={
49
+ "query": query,
50
+ "page": page,
51
+ "size": size,
52
+ },
53
+ )
54
+
55
+ def get_app(self, app_id: str):
56
+ """获取应用基本信息"""
57
+ return self._request("GET", f"/apps/{app_id}")
58
+
59
+ def get_app_role_users(self, app_id: str):
60
+ """获取应用管理员"""
61
+ return self._request("GET", f"/apps/{app_id}/role_users")
62
+
63
+ def list_namespaces(self, app_id: str, env: str = "DEV", cluster: str = "default"):
64
+ """获取应用 Namespace 列表"""
65
+ return self._request(
66
+ "GET",
67
+ f"/apps/{app_id}/envs/{env}/clusters/{cluster}/namespaces",
68
+ )
69
+
70
+ def get_namespace_active_release(
71
+ self,
72
+ app_id: str,
73
+ namespace: str,
74
+ env: str = "DEV",
75
+ cluster: str = "default",
76
+ page: int = 0,
77
+ size: int = 1,
78
+ ):
79
+ """获取 Namespace 当前生效发布"""
80
+ return self._request(
81
+ "GET",
82
+ f"/apps/{app_id}/envs/{env}/clusters/{cluster}/namespaces/{namespace}/releases/active",
83
+ params={"page": page, "size": size},
84
+ )
85
+
86
+ def update_app(self, app_id: str, payload: dict):
87
+ """更新应用配置"""
88
+ return self._request(
89
+ "PUT",
90
+ f"/apps/{app_id}",
91
+ json=payload,
92
+ )
93
+
94
+ def add_app_admin(self, app_id: str, user_code: str, role: str = "Master"):
95
+ """添加应用管理员"""
96
+ return self._request(
97
+ "POST",
98
+ f"/apps/{app_id}/roles/{role}",
99
+ data=user_code,
100
+ headers={"Content-Type": "text/plain;charset=UTF-8"},
101
+ )
102
+
103
+ def remove_app_admin(self, app_id: str, user_code: str, role: str = "Master"):
104
+ """移除应用管理员"""
105
+ return self._request(
106
+ "DELETE",
107
+ f"/apps/{app_id}/roles/{role}",
108
+ params={"user": user_code},
109
+ )
apollo_cli/auth.py ADDED
@@ -0,0 +1,145 @@
1
+ """认证模块 - 通过 Playwright 获取浏览器 cookie"""
2
+ import json
3
+ import os
4
+
5
+ from playwright.sync_api import sync_playwright
6
+
7
+ from .config import config
8
+
9
+
10
+ APOLLO_DOMAIN = ".eminxing.com"
11
+ LOGIN_URL = "https://dev-apollo-admin.eminxing.com"
12
+ REQUIRED_COOKIES = ["SESSION"]
13
+
14
+ def save_cookies(cookies: dict):
15
+ """保存 cookie 到缓存文件"""
16
+ config.CONFIG_DIR.mkdir(parents=True, exist_ok=True)
17
+ with open(config.COOKIE_FILE, "w") as f:
18
+ json.dump(cookies, f)
19
+
20
+ def load_cookies() -> dict:
21
+ """从缓存文件加载 cookie"""
22
+ if config.COOKIE_FILE.exists():
23
+ with open(config.COOKIE_FILE) as f:
24
+ return json.load(f)
25
+ return {}
26
+
27
+ def get_auth_headers(cookies: dict) -> dict:
28
+ """从 cookie 构建认证请求头"""
29
+ session_cookie = "; ".join(f"{k}={v}" for k, v in cookies.items())
30
+ return {
31
+ "Accept": "application/json, text/plain, */*",
32
+ "Accept-Language": "zh-CN,zh;q=0.9",
33
+ "Connection": "keep-alive",
34
+ "Referer": "https://dev-apollo-admin.eminxing.com",
35
+ "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36",
36
+ "Cookie": session_cookie,
37
+ "X-Requested-With": "XMLHttpRequest",
38
+ }
39
+
40
+ def get_auth_cookies() -> dict:
41
+ """获取认证 cookie,优先使用缓存,失效则重新获取"""
42
+ cookies = load_cookies()
43
+ if all(cookies.get(k) for k in REQUIRED_COOKIES):
44
+ return cookies
45
+
46
+ # 缓存失效,重新获取
47
+ cookies = get_cookies_from_browser()
48
+ save_cookies(cookies)
49
+
50
+ print("已获取新的 Apollo Cookie")
51
+ return cookies
52
+
53
+ def open_login_page(page) -> bool:
54
+ """自动登录 - 尝试读取环境变量自动填写账号密码"""
55
+ username = os.environ.get("ZT_SSO_USERNAME")
56
+ password = os.environ.get("ZT_SSO_PASSWORD")
57
+
58
+ if not username or not password:
59
+ return False
60
+
61
+ print(f"检测到环境变量,自动登录中...")
62
+
63
+ try:
64
+ # 兼容常见账号密码输入框
65
+ user_selector = "#username, input[name='username'], input[type='text']"
66
+ pass_selector = "#password, #password2, input[name='password'], input[type='password']"
67
+ login_selector = ".login_in, button[type='submit'], .btn-login"
68
+
69
+ page.wait_for_selector(user_selector, timeout=15000)
70
+ page.fill(user_selector, username)
71
+ page.fill(pass_selector, password)
72
+ page.click(login_selector)
73
+ print("已尝试自动提交登录")
74
+
75
+ return True
76
+
77
+ except Exception as e:
78
+ print(f"自动登录失败: {e}")
79
+
80
+ return False
81
+
82
+ def get_cookies_from_browser(headless: bool = True) -> dict:
83
+ """通过 Playwright 从浏览器获取 cookie"""
84
+ if headless:
85
+ print("正在启动浏览器(无头模式),请登录...")
86
+ else:
87
+ print("正在打开浏览器,请登录...")
88
+
89
+ with sync_playwright() as p:
90
+ browser = p.chromium.launch(headless=headless)
91
+ context = browser.new_context()
92
+ page = context.new_page()
93
+
94
+ page.goto(LOGIN_URL)
95
+
96
+ # 尝试自动登录
97
+ if not open_login_page(page):
98
+ if headless:
99
+ raise RuntimeError(
100
+ "无头模式下无法完成交互式登录。请设置环境变量 ZT_APOLLO_USERNAME 与 ZT_APOLLO_PASSWORD,"
101
+ "或执行 zt-apollo-cli login --headed 使用有界面浏览器登录。"
102
+ )
103
+ print("自动登陆失败. 请在浏览器中完成登录,登录成功后会自动继续...")
104
+
105
+ print("登陆中. 检测关键 cookie 出现")
106
+ page.wait_for_function(
107
+ f"""() => {{
108
+ const cookies = document.cookie;
109
+ return cookies.includes('NG_TRANSLATE_LANG_KEY');
110
+ }}""",
111
+ timeout=300000 # 5分钟超时
112
+ )
113
+
114
+ print("登陆成功. 已获取关键 cookie")
115
+
116
+ cookies = context.cookies()
117
+
118
+ cookie_dict = {}
119
+ for cookie in cookies:
120
+ if cookie["domain"] == APOLLO_DOMAIN or APOLLO_DOMAIN in cookie["domain"]:
121
+ cookie_dict[cookie["name"]] = cookie["value"]
122
+
123
+
124
+ browser.close()
125
+
126
+ return cookie_dict
127
+
128
+ def login(headless: bool = True, force: bool = False) -> dict:
129
+ """登录并缓存 cookie;已有有效登录态时默认跳过"""
130
+ cached = load_cookies()
131
+ if not force and all(cached.get(k) for k in REQUIRED_COOKIES):
132
+ print("检测到已登录,跳过重新登录。如需刷新请使用 --force。")
133
+ return cached
134
+
135
+ if headless:
136
+ print("正在启动浏览器(无头模式),请重新登录...")
137
+ else:
138
+ print("正在打开浏览器,请重新登录...")
139
+ cookies = get_cookies_from_browser(headless=headless)
140
+ save_cookies(cookies)
141
+ print("登录成功,Apollo cookie 已缓存!")
142
+ return cookies
143
+
144
+ if __name__ == "__main__":
145
+ print(login())
apollo_cli/cli.py ADDED
@@ -0,0 +1,281 @@
1
+ """CLI 入口"""
2
+ import click
3
+ import json
4
+ import shutil
5
+ from .api import ApolloApi
6
+ from .auth import login
7
+
8
+ def _normalize_cell(value):
9
+ if value is None:
10
+ return "-"
11
+ return str(value)
12
+
13
+
14
+ def _truncate_text(text, width):
15
+ if width <= 0:
16
+ return ""
17
+ if len(text) <= width:
18
+ return text
19
+ if width <= 1:
20
+ return text[:width]
21
+ return text[: width - 1] + "…"
22
+
23
+
24
+ def render_table(headers, rows, max_width=120, no_truncate_headers=None):
25
+ if not rows:
26
+ click.echo("暂无数据")
27
+ return
28
+
29
+ terminal_width = shutil.get_terminal_size((max_width, 20)).columns
30
+ table_max_width = min(max_width, terminal_width)
31
+
32
+ no_truncate_headers = set(no_truncate_headers or [])
33
+
34
+ normalized_rows = []
35
+ for row in rows:
36
+ normalized = [_normalize_cell(cell) for cell in row[: len(headers)]]
37
+ if len(normalized) < len(headers):
38
+ normalized.extend(["-"] * (len(headers) - len(normalized)))
39
+ normalized_rows.append(normalized)
40
+
41
+ widths = [len(h) for h in headers]
42
+ for row in normalized_rows:
43
+ for idx, cell in enumerate(row):
44
+ widths[idx] = max(widths[idx], len(cell))
45
+
46
+ # 边框和分隔占用: 左右边框 + 每列两侧空格 + 列分隔符
47
+ overhead = 3 * len(headers) + 1
48
+ available = max(20, table_max_width - overhead)
49
+ min_col_width = 10
50
+ widths = [max(min_col_width, w) for w in widths]
51
+
52
+ total = sum(widths)
53
+ if total > available:
54
+ fixed_idx = {i for i, h in enumerate(headers) if h in no_truncate_headers}
55
+ shrinkable_idx = [i for i in range(len(headers)) if i not in fixed_idx]
56
+
57
+ if shrinkable_idx:
58
+ while sum(widths) > available:
59
+ idx = max(shrinkable_idx, key=lambda i: widths[i])
60
+ if widths[idx] > min_col_width:
61
+ widths[idx] -= 1
62
+ else:
63
+ if all(widths[i] <= min_col_width for i in shrinkable_idx):
64
+ break
65
+ # 若仍超出可用宽度,保留不截断列完整内容,允许终端自动换行/横向滚动查看
66
+
67
+ def format_row(cells):
68
+ parts = []
69
+ for i, cell in enumerate(cells):
70
+ text = cell if headers[i] in no_truncate_headers else _truncate_text(cell, widths[i])
71
+ parts.append(f" {text.ljust(widths[i])} ")
72
+ return "|" + "|".join(parts) + "|"
73
+
74
+ border = "+" + "+".join("-" * (w + 2) for w in widths) + "+"
75
+ click.echo(border)
76
+ click.echo(format_row(headers))
77
+ click.echo(border)
78
+ for row in normalized_rows:
79
+ click.echo(format_row(row))
80
+ click.echo(border)
81
+
82
+
83
+ @click.group()
84
+ @click.option(
85
+ "--output",
86
+ "-o",
87
+ "output_format",
88
+ type=click.Choice(["human", "json"], case_sensitive=False),
89
+ default="json",
90
+ show_default=True,
91
+ help="输出格式: human(表格) / json",
92
+ )
93
+ @click.pass_context
94
+ def cli(ctx, output_format):
95
+ """Apollo 配置管理命令行工具"""
96
+ ctx.ensure_object(dict)
97
+ ctx.obj["output_format"] = output_format.lower()
98
+
99
+ @cli.command("login")
100
+ @click.option(
101
+ "--headed",
102
+ is_flag=True,
103
+ help="显示浏览器窗口,用于无环境变量时的手动登录",
104
+ )
105
+ @click.option(
106
+ "--force",
107
+ is_flag=True,
108
+ help="强制重新登录并刷新本地 cookie",
109
+ )
110
+ def cmd_login(headed, force):
111
+ """登录 - 已登录则跳过,传 --force 可强制重新登录"""
112
+ login(headless=not headed, force=force)
113
+
114
+
115
+ @cli.group()
116
+ def sys():
117
+ """Apollo 系统管理组"""
118
+ pass
119
+
120
+ @cli.group()
121
+ def app():
122
+ """Apollo 配置管理命令组"""
123
+ pass
124
+
125
+ def _extract_rows(result):
126
+ if isinstance(result, list):
127
+ return result
128
+ if isinstance(result, dict):
129
+ for key in ("content", "items", "data", "rows", "result", "results"):
130
+ value = result.get(key)
131
+ if isinstance(value, list):
132
+ return value
133
+ return []
134
+
135
+ def _print_result(ctx, result, preferred_headers=None):
136
+ output_format = ctx.obj["output_format"]
137
+ if output_format == "json":
138
+ click.echo(json.dumps(result, ensure_ascii=False, indent=2))
139
+ return
140
+
141
+ rows = _extract_rows(result)
142
+ if not rows:
143
+ click.echo(json.dumps(result, ensure_ascii=False, indent=2))
144
+ return
145
+
146
+ if isinstance(rows[0], dict):
147
+ headers = preferred_headers or list(rows[0].keys())
148
+ table_rows = [[item.get(h) for h in headers] for item in rows]
149
+ render_table(headers, table_rows, no_truncate_headers=headers[:1])
150
+ return
151
+
152
+ if isinstance(rows[0], list):
153
+ headers = preferred_headers or [f"col_{idx + 1}" for idx in range(len(rows[0]))]
154
+ render_table(headers, rows)
155
+ return
156
+
157
+ render_table(["value"], [[row] for row in rows])
158
+
159
+ @sys.command("list-org")
160
+ @click.pass_context
161
+ def list_organizations(ctx):
162
+ """列出部门"""
163
+ api = ApolloApi()
164
+ result = api.list_organizations()
165
+ _print_result(ctx, result, preferred_headers=["orgId", "name"])
166
+
167
+ @app.command("search")
168
+ @click.option("--query", "-q", required=True, help="应用 appId 或名称关键词")
169
+ @click.option("--page", default=0, show_default=True, type=int, help="分页页码,从 0 开始")
170
+ @click.option("--size", default=20, show_default=True, type=int, help="分页大小")
171
+ @click.pass_context
172
+ def list_app(ctx, query, page, size):
173
+ """应用列表"""
174
+ api = ApolloApi()
175
+ result = api.search_apps(query=query, page=page, size=size)
176
+ _print_result(ctx, result, preferred_headers=["appId", "name", "orgName", "ownerName"])
177
+
178
+ @app.command("show")
179
+ @click.option("--app-id", "-a", required=True, help="应用 appId")
180
+ @click.pass_context
181
+ def show_app_base_info(ctx, app_id):
182
+ """获取应用基本信息"""
183
+ api = ApolloApi()
184
+ result = api.get_app(app_id=app_id)
185
+ if ctx.obj["output_format"] == "json":
186
+ click.echo(json.dumps(result, ensure_ascii=False, indent=2))
187
+ return
188
+ headers = ["appId", "name", "orgName", "ownerName", "ownerEmail"]
189
+ render_table(headers, [[result.get(h) for h in headers]])
190
+
191
+ @app.command("list-admin")
192
+ @click.option("--app-id", "-a", required=True, help="应用 appId")
193
+ @click.pass_context
194
+ def list_app_admin(ctx, app_id):
195
+ """获取应用管理员"""
196
+ api = ApolloApi()
197
+ result = api.get_app_role_users(app_id=app_id)
198
+ _print_result(ctx, result, preferred_headers=["userId", "userIdDisplayName", "roleName"])
199
+
200
+ @app.command("add-admin")
201
+ @click.option("--app-id", "-a", required=True, help="应用 appId")
202
+ @click.option("--user-code", "-u", required=True, help="管理员工号/账号(如 zt07905)")
203
+ @click.option("--role", default="Master", show_default=True, help="角色名称")
204
+ @click.pass_context
205
+ def add_app_admin(ctx, app_id, user_code, role):
206
+ """添加应用管理员"""
207
+ api = ApolloApi()
208
+ result = api.add_app_admin(app_id=app_id, user_code=user_code, role=role)
209
+ if ctx.obj["output_format"] == "json":
210
+ click.echo(json.dumps(result, ensure_ascii=False, indent=2))
211
+ else:
212
+ click.echo(f"已添加管理员: {user_code} (role={role})")
213
+
214
+ @app.command("del-admin")
215
+ @click.option("--app-id", "-a", required=True, help="应用 appId")
216
+ @click.option("--user-code", "-u", required=True, help="待移除管理员工号/账号(如 zt07905)")
217
+ @click.option("--role", default="Master", show_default=True, help="角色名称")
218
+ @click.pass_context
219
+ def remove_app_admin(ctx, app_id, user_code, role):
220
+ """移除应用管理员"""
221
+ api = ApolloApi()
222
+ result = api.remove_app_admin(app_id=app_id, user_code=user_code, role=role)
223
+ if ctx.obj["output_format"] == "json":
224
+ click.echo(json.dumps(result, ensure_ascii=False, indent=2))
225
+ else:
226
+ click.echo(f"已移除管理员: {user_code} (role={role})")
227
+
228
+ @app.command("list-namespace")
229
+ @click.option("--app-id", "-a", required=True, help="应用 appId")
230
+ @click.option("--env", default="DEV", show_default=True, help="环境")
231
+ @click.option("--cluster", default="default", show_default=True, help="集群")
232
+ @click.pass_context
233
+ def list_namespaces(ctx, app_id, env, cluster):
234
+ """获取应用 Namespace"""
235
+ api = ApolloApi()
236
+ result = api.list_namespaces(app_id=app_id, env=env, cluster=cluster)
237
+ _print_result(ctx, result, preferred_headers=["name", "appId", "clusterName", "dataChangeLastModifiedTime"])
238
+
239
+ @app.command("show-namespace-release")
240
+ @click.option("--app-id", "-a", required=True, help="应用 appId")
241
+ @click.option("--namespace", "-n", required=True, help="Namespace 名称")
242
+ @click.option("--env", default="DEV", show_default=True, help="环境")
243
+ @click.option("--cluster", default="default", show_default=True, help="集群")
244
+ @click.option("--page", default=0, show_default=True, type=int, help="分页页码,从 0 开始")
245
+ @click.option("--size", default=1, show_default=True, type=int, help="分页大小")
246
+ @click.pass_context
247
+ def show_namespace_release(ctx, app_id, namespace, env, cluster, page, size):
248
+ """获取应用 Namespace 生效配置发布"""
249
+ api = ApolloApi()
250
+ result = api.get_namespace_active_release(
251
+ app_id=app_id,
252
+ namespace=namespace,
253
+ env=env,
254
+ cluster=cluster,
255
+ page=page,
256
+ size=size,
257
+ )
258
+ _print_result(ctx, result)
259
+
260
+ @app.command("update")
261
+ @click.option("--app-id", "-a", required=True, help="应用 appId")
262
+ @click.option("--file", "payload_file", type=click.Path(exists=True, dir_okay=False), required=True, help="更新 payload 的 JSON 文件")
263
+ @click.pass_context
264
+ def update_app(ctx, app_id, payload_file):
265
+ """修改应用配置"""
266
+ with open(payload_file) as f:
267
+ payload = json.load(f)
268
+
269
+ api = ApolloApi()
270
+ result = api.update_app(app_id=app_id, payload=payload)
271
+
272
+ if ctx.obj["output_format"] == "json":
273
+ click.echo(json.dumps(result, ensure_ascii=False, indent=2))
274
+ else:
275
+ click.echo("应用配置更新成功")
276
+
277
+ def main():
278
+ cli()
279
+
280
+ if __name__ == "__main__":
281
+ main()
apollo_cli/config.py ADDED
@@ -0,0 +1,36 @@
1
+ """配置管理模块"""
2
+ from pathlib import Path
3
+
4
+ import yaml
5
+
6
+
7
+ class Config:
8
+ """配置类"""
9
+
10
+ CONFIG_DIR = Path.home() / ".zt-apollo-cli"
11
+ COOKIE_FILE = CONFIG_DIR / "cookies.json"
12
+ CONFIG_FILE = CONFIG_DIR / "config.yaml"
13
+
14
+ # Apollo API 默认地址
15
+ BASE_URL = "https://dev-apollo-admin.eminxing.com"
16
+
17
+ def __init__(self):
18
+ self._config = self._load_config()
19
+
20
+ def _load_config(self) -> dict:
21
+ """加载配置文件"""
22
+ if self.CONFIG_FILE.exists():
23
+ with open(self.CONFIG_FILE) as f:
24
+ return yaml.safe_load(f) or {}
25
+ return {}
26
+
27
+ @property
28
+ def browser_channel(self) -> str:
29
+ return self._config.get("browser_channel", "chromium")
30
+
31
+ @property
32
+ def base_url(self) -> str:
33
+ return self._config.get("base_url", self.BASE_URL).rstrip("/")
34
+
35
+
36
+ config = Config()
@@ -0,0 +1,131 @@
1
+ Metadata-Version: 2.4
2
+ Name: zt-apollo-cli
3
+ Version: 0.2.1
4
+ Summary: Apollo configuration management CLI
5
+ Requires-Python: >=3.10
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: playwright>=1.40.0
8
+ Requires-Dist: requests>=2.31.0
9
+ Requires-Dist: click>=8.1.0
10
+ Requires-Dist: pyyaml>=6.0
11
+ Requires-Dist: build>=1.4.4
12
+ Requires-Dist: twine>=6.2.0
13
+
14
+ # zt-apollo-cli
15
+
16
+ Apollo 配置管理命令行工具
17
+
18
+ ## 环境要求
19
+
20
+ - Python `>=3.10`
21
+ - 可用浏览器(首次登录会自动打开)
22
+
23
+ ## 安装
24
+
25
+ ### 开发安装(源码)
26
+
27
+ ```bash
28
+ pip install -e .
29
+ ```
30
+
31
+ ### 打包发布
32
+
33
+ ```bash
34
+ python -m pip install --upgrade build twine
35
+ python -m build
36
+ twine upload dist/*
37
+ ```
38
+
39
+ ## 快速开始
40
+
41
+ ### 1) 登录并缓存 Cookie(已登录可跳过)
42
+
43
+ 首次运行会打开浏览器,请完成登录。成功后会缓存 Cookie 到本地。
44
+ 再次执行 `login` 时,如果检测到本地已有有效登录态会自动跳过;如需强制刷新可加 `--force`。
45
+
46
+ ```bash
47
+ zt-apollo-cli login
48
+ zt-apollo-cli login --force
49
+ ```
50
+
51
+ ### 2) 查看部门列表
52
+
53
+ ```bash
54
+ zt-apollo-cli sys list-org
55
+ ```
56
+
57
+ ### 3) 搜索应用
58
+
59
+ ```bash
60
+ zt-apollo-cli app search -q bsc
61
+ ```
62
+
63
+ ### 4) 查看应用基本信息
64
+
65
+ ```bash
66
+ zt-apollo-cli app show -a your_app_id
67
+ ```
68
+
69
+ ### 5) 查看应用管理员列表
70
+
71
+ ```bash
72
+ zt-apollo-cli app list-admin -a your_app_id
73
+ ```
74
+
75
+ ### 6) 添加/移除应用管理员
76
+
77
+ ```bash
78
+ zt-apollo-cli app add-admin -a your_app_id -u xxx
79
+ zt-apollo-cli app del-admin -a your_app_id -u xxx
80
+ ```
81
+
82
+ ### 7) 查询应用 Namespace
83
+
84
+ ```bash
85
+ zt-apollo-cli app list-namespace -a your_app_id --env DEV --cluster default
86
+ ```
87
+
88
+ ### 8) 获取 Namespace 当前生效发布
89
+
90
+ ```bash
91
+ zt-apollo-cli app show-namespace-release -a your_app_id -n application --env DEV --cluster default
92
+ ```
93
+
94
+ ### 9) 修改应用配置
95
+
96
+ ```bash
97
+ zt-apollo-cli app update -a your_app_id --file ./app-update.json
98
+ ```
99
+
100
+ ## 全局参数
101
+ - `-o, --output`:输出格式,支持:
102
+ - `json`(默认)
103
+ - `human`(表格)
104
+
105
+ 示例:
106
+
107
+ ```bash
108
+ zt-apollo-cli -o human sys list-org
109
+ ```
110
+
111
+ ## 配置说明
112
+
113
+ 默认配置目录:`~/.zt-apollo-cli`
114
+
115
+ - Cookie 缓存:`~/.zt-apollo-cli/cookies.json`
116
+ - 配置文件:`~/.zt-apollo-cli/config.yaml`
117
+
118
+ 可选配置项示例:
119
+
120
+ ```yaml
121
+ browser_channel: chromium
122
+ ```
123
+
124
+ ## 环境变量(可选)
125
+
126
+ 支持通过环境变量自动填充登录页账号密码(如 SSO 页面字段可用):
127
+
128
+ - `ZT_SSO_USERNAME`
129
+ - `ZT_SSO_PASSWORD`
130
+
131
+ 未设置时可在浏览器中手动完成登录。
@@ -0,0 +1,10 @@
1
+ apollo_cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ apollo_cli/api.py,sha256=8vGJNYG8GSsXApoCuRj4l9DjhtDAhYsSC_i9Agf7VvQ,3273
3
+ apollo_cli/auth.py,sha256=L0lRuZqFCZ1_O0EPHRY44YXzHfMVF4yo-VvPgQqvVMc,4927
4
+ apollo_cli/cli.py,sha256=2QVVPPAs98Lvzl0vS9O-duAsZ5LQmJSSxKkF2nrxBIY,9883
5
+ apollo_cli/config.py,sha256=fk74Ku3Ed0Q5-pdEDf9UxZ2Gec-KB-wtqzwTUrWoWUo,865
6
+ zt_apollo_cli-0.2.1.dist-info/METADATA,sha256=ddrzGph6LYrvhJtqWWtBtS8WJdGIlsHb5Qj65Bl7-nc,2464
7
+ zt_apollo_cli-0.2.1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
8
+ zt_apollo_cli-0.2.1.dist-info/entry_points.txt,sha256=t3vlWRJf_ShI7HEpVr1O-vwyKIxfwJ8hVVYJugpDpIM,54
9
+ zt_apollo_cli-0.2.1.dist-info/top_level.txt,sha256=_g_iA8jYTBg-79NnfI_POr0cXTcR4z1XVpcsDJdDZWE,11
10
+ zt_apollo_cli-0.2.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ zt-apollo-cli = apollo_cli.cli:main
@@ -0,0 +1 @@
1
+ apollo_cli