tg-show-config CLI command

This commit is contained in:
Cyber MacGeddon 2025-04-01 19:45:23 +01:00
parent 6828ca8fc6
commit 36f3cdc94c
3 changed files with 80 additions and 0 deletions

View file

@ -382,3 +382,33 @@ class Api:
if resp.status_code != 200:
raise ProtocolException(f"Status code {resp.status_code}")
def get_config(self):
# The input consists of system and prompt strings
input = {
"operation": "config"
}
url = f"{self.url}config"
# Invoke the API, input is passed as JSON
resp = requests.post(url, json=input)
# Should be a 200 status code
if resp.status_code != 200:
raise ProtocolException(f"Status code {resp.status_code}")
try:
# Parse the response as JSON
object = resp.json()
except:
raise ProtocolException(f"Expected JSON response")
self.check_error(resp)
try:
return object["config"], object["version"]
except:
raise ProtocolException(f"Response not formatted correctly")