MCPcopy Index your code
hub / github.com/dataease/SQLBot / get_es_data_by_http

Function get_es_data_by_http

backend/apps/db/es_engine.py:106–132  ·  view source on GitHub ↗
(conf: DatasourceConf, sql: str)

Source from the content-addressed store, hash-verified

104
105
106def get_es_data_by_http(conf: DatasourceConf, sql: str):
107 url = conf.host
108 while url.endswith('/'):
109 url = url[:-1]
110
111 host = f'{url}/_sql?format=json'
112
113 # Security improvement: Enable SSL certificate verification
114 # Note: In production, always set verify=True or provide path to CA bundle
115 # If using self-signed certificates, provide the cert path: verify='/path/to/cert.pem'
116 # verify_ssl = True if not url.startswith('https://localhost') else False
117
118 response = requests.post(
119 host,
120 data=json.dumps({"query": sql}),
121 headers=get_es_auth(conf),
122 verify=False,
123 timeout=30 # Add timeout to prevent hanging
124 )
125
126 # print(response.json())
127 res = response.json()
128 if res.get('error'):
129 raise SingleMessageError(json.dumps(res))
130 fields = res.get('columns')
131 result = res.get('rows')
132 return result, fields

Callers 1

exec_sqlFunction · 0.90

Calls 4

SingleMessageErrorClass · 0.90
get_es_authFunction · 0.85
postMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected