From 88fcebd8d784d7b848a90e7daf4172cc2db62fab Mon Sep 17 00:00:00 2001 From: ifooth Date: Thu, 5 Dec 2024 15:03:05 +0800 Subject: [PATCH] feat: add pull_kvs method --- bk_bscp/client.py | 3 ++- examples/get_key.py | 10 ++++++++-- readme.md | 2 +- readme_en.md | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/bk_bscp/client.py b/bk_bscp/client.py index 7dde195..64adf8a 100644 --- a/bk_bscp/client.py +++ b/bk_bscp/client.py @@ -166,8 +166,9 @@ def pull_kvs(self, app: str, match: List[str], app_options: Optional[AppOptions] uid = self._fingerprint if app_options is not None: - uid = app_options.uid + uid = app_options.uid or self._fingerprint total_labels = {**self.labels, **(app_options.labels or {})} + match = [*match, *(app_options.match or [])] msg = feed_server_pb2.PullKvMetaReq( match=match, diff --git a/examples/get_key.py b/examples/get_key.py index 57ac360..9f641f2 100644 --- a/examples/get_key.py +++ b/examples/get_key.py @@ -15,7 +15,7 @@ # to the current version of the project delivered to anyone in the future. """Get a key.""" -from bk_bscp.client import BscpClient +from bk_bscp.client import AppOptions, BscpClient SERVER_ADDRS = ["example.com:9090"] TOKEN = "your_token" @@ -29,8 +29,14 @@ def get_key(): def get_all_keys(): + app = AppOptions( + match=[], + labels={}, + uid="", + ) + with BscpClient(SERVER_ADDRS, TOKEN, BIZ_ID) as client: - release = client.pull_kvs("app1", ["key1"]) + release = client.pull_kvs("app1", ["key1"], app) for kv in release.kvs: pair = client.get("app1", kv.key) print(pair) diff --git a/readme.md b/readme.md index eed58dd..1a48fa5 100644 --- a/readme.md +++ b/readme.md @@ -61,7 +61,7 @@ with BscpClient(server_addrs, token, biz_id) as client: 安装环境 ```bash -# 安装版本, 修改{version}为版本好, 如3.18, 如果已经有版本,步骤忽略 +# 安装版本, 修改{version}为版本号, 如3.18, 如果已经有版本,步骤忽略 uv python install {version} # 创建环境, 修改{path}为python真实路径 diff --git a/readme_en.md b/readme_en.md index e3dba42..f90ec96 100644 --- a/readme_en.md +++ b/readme_en.md @@ -61,7 +61,7 @@ For more sample code, please refer to the examples/ directory. Installation environment ```bash -# Install version, modify {version} to a good version, such as 3.18. If there is already a version, ignore this step +# Install version, modify {version} to real version, such as 3.18. If there is already a version, ignore this step uv python install {version} # Create environment, modify {path} to the real path of python