zt-apollo-cli 0.2.1__tar.gz → 0.2.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zt-apollo-cli
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: Apollo configuration management CLI
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -31,9 +31,8 @@ pip install -e .
31
31
  ### 打包发布
32
32
 
33
33
  ```bash
34
- python -m pip install --upgrade build twine
35
- python -m build
36
- twine upload dist/*
34
+ uv build
35
+ uv public --token <your_token>
37
36
  ```
38
37
 
39
38
  ## 快速开始
@@ -91,7 +90,16 @@ zt-apollo-cli app list-namespace -a your_app_id --env DEV --cluster default
91
90
  zt-apollo-cli app show-namespace-release -a your_app_id -n application --env DEV --cluster default
92
91
  ```
93
92
 
94
- ### 9) 修改应用配置
93
+ ### 9) 分配 Namespace 发布权限
94
+
95
+ ```bash
96
+ zt-apollo-cli app add-namespace-publisher -a your_app_id -n application -u zt19262
97
+ zt-apollo-cli app del-namespace-publisher -a your_app_id -n application -u zt19262
98
+ zt-apollo-cli app add-namespace-release-publisher -a your_app_id -n application -u zt19262
99
+ zt-apollo-cli app del-namespace-release-publisher -a your_app_id -n application -u zt19262
100
+ ```
101
+
102
+ ### 10) 修改应用配置
95
103
 
96
104
  ```bash
97
105
  zt-apollo-cli app update -a your_app_id --file ./app-update.json
@@ -18,9 +18,8 @@ pip install -e .
18
18
  ### 打包发布
19
19
 
20
20
  ```bash
21
- python -m pip install --upgrade build twine
22
- python -m build
23
- twine upload dist/*
21
+ uv build
22
+ uv public --token <your_token>
24
23
  ```
25
24
 
26
25
  ## 快速开始
@@ -78,7 +77,16 @@ zt-apollo-cli app list-namespace -a your_app_id --env DEV --cluster default
78
77
  zt-apollo-cli app show-namespace-release -a your_app_id -n application --env DEV --cluster default
79
78
  ```
80
79
 
81
- ### 9) 修改应用配置
80
+ ### 9) 分配 Namespace 发布权限
81
+
82
+ ```bash
83
+ zt-apollo-cli app add-namespace-publisher -a your_app_id -n application -u zt19262
84
+ zt-apollo-cli app del-namespace-publisher -a your_app_id -n application -u zt19262
85
+ zt-apollo-cli app add-namespace-release-publisher -a your_app_id -n application -u zt19262
86
+ zt-apollo-cli app del-namespace-release-publisher -a your_app_id -n application -u zt19262
87
+ ```
88
+
89
+ ### 10) 修改应用配置
82
90
 
83
91
  ```bash
84
92
  zt-apollo-cli app update -a your_app_id --file ./app-update.json
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "zt-apollo-cli"
7
- version = "0.2.1"
7
+ version = "0.2.3"
8
8
  description = "Apollo configuration management CLI"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -107,3 +107,37 @@ class ApolloApi:
107
107
  f"/apps/{app_id}/roles/{role}",
108
108
  params={"user": user_code},
109
109
  )
110
+
111
+ def add_namespace_modify_role(self, app_id: str, namespace: str, user_code: str):
112
+ """分配 Namespace 发布权限(ModifyNamespace)"""
113
+ return self._request(
114
+ "POST",
115
+ f"/apps/{app_id}/namespaces/{namespace}/roles/ModifyNamespace",
116
+ data=user_code,
117
+ headers={"Content-Type": "text/plain;charset=UTF-8"},
118
+ )
119
+
120
+ def remove_namespace_modify_role(self, app_id: str, namespace: str, user_code: str):
121
+ """移除 Namespace 发布权限(ModifyNamespace)"""
122
+ return self._request(
123
+ "DELETE",
124
+ f"/apps/{app_id}/namespaces/{namespace}/roles/ModifyNamespace",
125
+ params={"user": user_code},
126
+ )
127
+
128
+ def remove_namespace_release_role(self, app_id: str, namespace: str, user_code: str):
129
+ """移除 Namespace 发布权限(ReleaseNamespace)"""
130
+ return self._request(
131
+ "DELETE",
132
+ f"/apps/{app_id}/namespaces/{namespace}/roles/ReleaseNamespace",
133
+ params={"user": user_code},
134
+ )
135
+
136
+ def add_namespace_release_role(self, app_id: str, namespace: str, user_code: str):
137
+ """分配 Namespace 发布权限(ReleaseNamespace)"""
138
+ return self._request(
139
+ "POST",
140
+ f"/apps/{app_id}/namespaces/{namespace}/roles/ReleaseNamespace",
141
+ data=user_code,
142
+ headers={"Content-Type": "text/plain;charset=UTF-8"},
143
+ )
@@ -8,7 +8,6 @@ from .config import config
8
8
 
9
9
 
10
10
  APOLLO_DOMAIN = ".eminxing.com"
11
- LOGIN_URL = "https://dev-apollo-admin.eminxing.com"
12
11
  REQUIRED_COOKIES = ["SESSION"]
13
12
 
14
13
  def save_cookies(cookies: dict):
@@ -31,7 +30,7 @@ def get_auth_headers(cookies: dict) -> dict:
31
30
  "Accept": "application/json, text/plain, */*",
32
31
  "Accept-Language": "zh-CN,zh;q=0.9",
33
32
  "Connection": "keep-alive",
34
- "Referer": "https://dev-apollo-admin.eminxing.com",
33
+ "Referer": f"{config.base_url}/",
35
34
  "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
35
  "Cookie": session_cookie,
37
36
  "X-Requested-With": "XMLHttpRequest",
@@ -91,7 +90,7 @@ def get_cookies_from_browser(headless: bool = True) -> dict:
91
90
  context = browser.new_context()
92
91
  page = context.new_page()
93
92
 
94
- page.goto(LOGIN_URL)
93
+ page.goto(config.base_url)
95
94
 
96
95
  # 尝试自动登录
97
96
  if not open_login_page(page):
@@ -4,6 +4,7 @@ import json
4
4
  import shutil
5
5
  from .api import ApolloApi
6
6
  from .auth import login
7
+ from .config import config
7
8
 
8
9
  def _normalize_cell(value):
9
10
  if value is None:
@@ -90,11 +91,18 @@ def render_table(headers, rows, max_width=120, no_truncate_headers=None):
90
91
  show_default=True,
91
92
  help="输出格式: human(表格) / json",
92
93
  )
94
+ @click.option(
95
+ "--base-url",
96
+ default=None,
97
+ help=f"Apollo 地址,默认 {config.DEFAULT_BASE_URL}",
98
+ )
93
99
  @click.pass_context
94
- def cli(ctx, output_format):
100
+ def cli(ctx, output_format, base_url):
95
101
  """Apollo 配置管理命令行工具"""
96
102
  ctx.ensure_object(dict)
97
103
  ctx.obj["output_format"] = output_format.lower()
104
+ if base_url:
105
+ config.set_base_url(base_url)
98
106
 
99
107
  @cli.command("login")
100
108
  @click.option(
@@ -225,6 +233,83 @@ def remove_app_admin(ctx, app_id, user_code, role):
225
233
  else:
226
234
  click.echo(f"已移除管理员: {user_code} (role={role})")
227
235
 
236
+
237
+ @app.command("add-namespace-publisher")
238
+ @click.option("--app-id", "-a", required=True, help="应用 appId")
239
+ @click.option("--namespace", "-n", required=True, help="Namespace 名称(如 application)")
240
+ @click.option("--user-code", "-u", required=True, help="授权员工号/账号(如 zt07905)")
241
+ @click.pass_context
242
+ def add_namespace_publisher(ctx, app_id, namespace, user_code):
243
+ """分配 Namespace 发布权限(ModifyNamespace)"""
244
+ api = ApolloApi()
245
+ result = api.add_namespace_modify_role(
246
+ app_id=app_id,
247
+ namespace=namespace,
248
+ user_code=user_code,
249
+ )
250
+ if ctx.obj["output_format"] == "json":
251
+ click.echo(json.dumps(result, ensure_ascii=False, indent=2))
252
+ else:
253
+ click.echo(f"已分配 Namespace 发布权限: {user_code} (namespace={namespace})")
254
+
255
+
256
+ @app.command("del-namespace-publisher")
257
+ @click.option("--app-id", "-a", required=True, help="应用 appId")
258
+ @click.option("--namespace", "-n", required=True, help="Namespace 名称(如 application)")
259
+ @click.option("--user-code", "-u", required=True, help="待移除员工号/账号(如 zt07905)")
260
+ @click.pass_context
261
+ def remove_namespace_publisher(ctx, app_id, namespace, user_code):
262
+ """移除 Namespace 发布权限(ModifyNamespace)"""
263
+ api = ApolloApi()
264
+ result = api.remove_namespace_modify_role(
265
+ app_id=app_id,
266
+ namespace=namespace,
267
+ user_code=user_code,
268
+ )
269
+ if ctx.obj["output_format"] == "json":
270
+ click.echo(json.dumps(result, ensure_ascii=False, indent=2))
271
+ else:
272
+ click.echo(f"已移除 Namespace 发布权限: {user_code} (namespace={namespace})")
273
+
274
+
275
+ @app.command("del-namespace-release-publisher")
276
+ @click.option("--app-id", "-a", required=True, help="应用 appId")
277
+ @click.option("--namespace", "-n", required=True, help="Namespace 名称(如 application)")
278
+ @click.option("--user-code", "-u", required=True, help="待移除员工号/账号(如 zt07905)")
279
+ @click.pass_context
280
+ def remove_namespace_release_publisher(ctx, app_id, namespace, user_code):
281
+ """移除 Namespace 发布权限(ReleaseNamespace)"""
282
+ api = ApolloApi()
283
+ result = api.remove_namespace_release_role(
284
+ app_id=app_id,
285
+ namespace=namespace,
286
+ user_code=user_code,
287
+ )
288
+ if ctx.obj["output_format"] == "json":
289
+ click.echo(json.dumps(result, ensure_ascii=False, indent=2))
290
+ else:
291
+ click.echo(f"已移除 Namespace 发布权限(ReleaseNamespace): {user_code} (namespace={namespace})")
292
+
293
+
294
+ @app.command("add-namespace-release-publisher")
295
+ @click.option("--app-id", "-a", required=True, help="应用 appId")
296
+ @click.option("--namespace", "-n", required=True, help="Namespace 名称(如 application)")
297
+ @click.option("--user-code", "-u", required=True, help="授权员工号/账号(如 zt07905)")
298
+ @click.pass_context
299
+ def add_namespace_release_publisher(ctx, app_id, namespace, user_code):
300
+ """分配 Namespace 发布权限(ReleaseNamespace)"""
301
+ api = ApolloApi()
302
+ result = api.add_namespace_release_role(
303
+ app_id=app_id,
304
+ namespace=namespace,
305
+ user_code=user_code,
306
+ )
307
+ if ctx.obj["output_format"] == "json":
308
+ click.echo(json.dumps(result, ensure_ascii=False, indent=2))
309
+ else:
310
+ click.echo(f"已分配 Namespace 发布权限(ReleaseNamespace): {user_code} (namespace={namespace})")
311
+
312
+
228
313
  @app.command("list-namespace")
229
314
  @click.option("--app-id", "-a", required=True, help="应用 appId")
230
315
  @click.option("--env", default="DEV", show_default=True, help="环境")
@@ -12,10 +12,11 @@ class Config:
12
12
  CONFIG_FILE = CONFIG_DIR / "config.yaml"
13
13
 
14
14
  # Apollo API 默认地址
15
- BASE_URL = "https://dev-apollo-admin.eminxing.com"
15
+ DEFAULT_BASE_URL = "https://dev-apollo-admin.eminxing.com"
16
16
 
17
17
  def __init__(self):
18
18
  self._config = self._load_config()
19
+ self._base_url_override = None
19
20
 
20
21
  def _load_config(self) -> dict:
21
22
  """加载配置文件"""
@@ -30,7 +31,13 @@ class Config:
30
31
 
31
32
  @property
32
33
  def base_url(self) -> str:
33
- return self._config.get("base_url", self.BASE_URL).rstrip("/")
34
+ if self._base_url_override:
35
+ return self._base_url_override.rstrip("/")
36
+ return self._config.get("base_url", self.DEFAULT_BASE_URL).rstrip("/")
37
+
38
+ def set_base_url(self, base_url: str):
39
+ """设置运行时 base_url(仅当前进程生效)"""
40
+ self._base_url_override = base_url.rstrip("/")
34
41
 
35
42
 
36
43
  config = Config()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zt-apollo-cli
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: Apollo configuration management CLI
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -31,9 +31,8 @@ pip install -e .
31
31
  ### 打包发布
32
32
 
33
33
  ```bash
34
- python -m pip install --upgrade build twine
35
- python -m build
36
- twine upload dist/*
34
+ uv build
35
+ uv public --token <your_token>
37
36
  ```
38
37
 
39
38
  ## 快速开始
@@ -91,7 +90,16 @@ zt-apollo-cli app list-namespace -a your_app_id --env DEV --cluster default
91
90
  zt-apollo-cli app show-namespace-release -a your_app_id -n application --env DEV --cluster default
92
91
  ```
93
92
 
94
- ### 9) 修改应用配置
93
+ ### 9) 分配 Namespace 发布权限
94
+
95
+ ```bash
96
+ zt-apollo-cli app add-namespace-publisher -a your_app_id -n application -u zt19262
97
+ zt-apollo-cli app del-namespace-publisher -a your_app_id -n application -u zt19262
98
+ zt-apollo-cli app add-namespace-release-publisher -a your_app_id -n application -u zt19262
99
+ zt-apollo-cli app del-namespace-release-publisher -a your_app_id -n application -u zt19262
100
+ ```
101
+
102
+ ### 10) 修改应用配置
95
103
 
96
104
  ```bash
97
105
  zt-apollo-cli app update -a your_app_id --file ./app-update.json
File without changes