(conf: DatasourceConf, sql: str)
| 104 | |
| 105 | |
| 106 | def 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 |
no test coverage detected