Skip to content

Commit c0328b3

Browse files
committed
feat(api/): Add key/value helpers to API helper
As we added key/value storage in API, we need also helper in core library. Signed-off-by: Denys Fedoryshchenko <[email protected]>
1 parent f150ce4 commit c0328b3

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

kernelci/api/helper.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,20 @@ def submit_results(self, results, root):
562562
except requests.exceptions.HTTPError as error:
563563
raise RuntimeError(json.loads(error.response.content)) from error
564564

565+
def set_kv(self, namespace, key, value):
566+
"""Set a key-value pair in the API"""
567+
try:
568+
return self.api.set_kv(namespace, key, value)
569+
except requests.exceptions.HTTPError as error:
570+
raise RuntimeError(json.loads(error.response.content)) from error
571+
572+
def get_kv(self, namespace, key):
573+
"""Get a key-value pair from the API"""
574+
try:
575+
return self.api.get_kv(namespace, key)
576+
except requests.exceptions.HTTPError as error:
577+
raise RuntimeError(json.loads(error.response.content)) from error
578+
565579
@classmethod
566580
def load_json(cls, json_path, encoding='utf-8'):
567581
"""Read content from JSON file"""

kernelci/api/latest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,18 @@ def create_group(self, name: str) -> dict:
180180
def delete_group(self, group_id: str):
181181
return self._delete(f'group/{group_id}')
182182

183+
def set_kv(self, namespace: str, key: str, value: str):
184+
"""
185+
Set a key-value pair in the database
186+
"""
187+
return self._post(f'kv/{namespace}/{key}', value).json()
188+
189+
def get_kv(self, namespace: str, key: str) -> str:
190+
"""
191+
Get a value from the database
192+
"""
193+
return self._get(f'kv/{namespace}/{key}').json()
194+
183195

184196
def get_api(config, token):
185197
"""Get an API object for the latest version"""

0 commit comments

Comments
 (0)