|
14 | 14 | # We undertake not to change the open source license (MIT license) applicable |
15 | 15 | # to the current version of the project delivered to anyone in the future. |
16 | 16 | """The client for bscp feed-server""" |
| 17 | + |
17 | 18 | import json |
18 | 19 | import logging |
19 | 20 | import random |
|
36 | 37 | ) |
37 | 38 | from bk_bscp.grpc_lib.core.base import base_pb2 |
38 | 39 | from bk_bscp.grpc_lib.feed_server import feed_server_pb2, feed_server_pb2_grpc |
39 | | -from bk_bscp.models import KeyValuePair, KeyValueUpdatedEvent, WatchAppInputParams |
| 40 | +from bk_bscp.models import AppOptions, KeyValuePair, KeyValueUpdatedEvent, Release, WatchAppInputParams |
40 | 41 | from bk_bscp.utils import get_fingerprint |
41 | 42 |
|
42 | 43 | logger = logging.getLogger("bk_bscp") |
@@ -153,6 +154,42 @@ def do_handshake(self): |
153 | 154 | raise BscpClientHandshakeError("Unable to handshake", e) from e |
154 | 155 | logger.debug("Handshake success, api_version: %s", response.api_version) |
155 | 156 |
|
| 157 | + def pull_kvs(self, app: str, match: List[str], app_options: Optional[AppOptions] = None) -> Release: |
| 158 | + """Pull key-value Release from the server. |
| 159 | + :param app: The app name. |
| 160 | + :param match: The key. |
| 161 | + :param app_options: the app option params. |
| 162 | + :return: A kv Release. |
| 163 | + :raises BscpClientGetError: If get failed. |
| 164 | + """ |
| 165 | + total_labels = {**self.labels} |
| 166 | + uid = self._fingerprint |
| 167 | + |
| 168 | + if app_options is not None: |
| 169 | + uid = app_options.uid or self._fingerprint |
| 170 | + total_labels = {**self.labels, **(app_options.labels or {})} |
| 171 | + match = [*match, *(app_options.match or [])] |
| 172 | + |
| 173 | + msg = feed_server_pb2.PullKvMetaReq( |
| 174 | + match=match, |
| 175 | + biz_id=self.biz_id, |
| 176 | + app_meta=feed_server_pb2.AppMeta( |
| 177 | + uid=uid, |
| 178 | + app=app, |
| 179 | + labels=total_labels, |
| 180 | + ), |
| 181 | + ) |
| 182 | + try: |
| 183 | + response = self.stub.PullKvMeta(msg, metadata=self._get_req_metadata()) |
| 184 | + except grpc.RpcError as e: |
| 185 | + raise BscpClientGetError(f'Unable to get "{app}" release, details: {e.details()}', e) from e |
| 186 | + |
| 187 | + r = Release( |
| 188 | + release_id=response.release_id, |
| 189 | + kvs=response.kv_metas, |
| 190 | + ) |
| 191 | + return r |
| 192 | + |
156 | 193 | def get(self, app: str, key: str, labels: Optional[dict] = None) -> KeyValuePair: |
157 | 194 | """Get a key-value pair from the server. |
158 | 195 |
|
|
0 commit comments