未验证 提交 336e88a8 编写于 作者: C CloudWise-Lukemiao 提交者: GitHub

[IOTDB-2458] Grafana REST API: add login method (#4923)

上级 8af4682c
......@@ -141,7 +141,7 @@ export class DataSource extends DataSourceApi<IoTDBQuery, IoTDBOptions> {
const Authorization = 'Basic ' + Buffer.from(this.username + ':' + this.password).toString('base64');
myHeader.append('Authorization', Authorization);
const response = getBackendSrv().datasourceRequest({
url: this.url + '/ping',
url: this.url + '/grafana/v1/login',
method: 'GET',
headers: myHeader,
});
......
......@@ -95,6 +95,17 @@ paths:
schema:
$ref: '#/components/schemas/QueryDataSet'
/grafana/v1/login:
get:
responses:
"200":
description: ExecutionStatus
content:
application/json:
schema:
$ref: '#/components/schemas/ExecutionStatus'
operationId: login
/grafana/v1/query/expression:
post:
summary: expression
......
......@@ -174,4 +174,14 @@ public class GrafanaApiServiceImpl extends GrafanaApiService {
return Response.ok().entity(ExceptionHandler.tryCatchException(e)).build();
}
}
@Override
public Response login(SecurityContext securityContext) throws NotFoundException {
return Response.ok()
.entity(
new ExecutionStatus()
.code(TSStatusCode.SUCCESS_STATUS.getStatusCode())
.message(TSStatusCode.SUCCESS_STATUS.name()))
.build();
}
}
......@@ -25,6 +25,7 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
......@@ -70,6 +71,37 @@ public class GrafanaApiServiceIT {
return httpPost;
}
@Test
public void login() {
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
HttpGet httpGet = new HttpGet("http://127.0.0.1:18080/grafana/v1/login");
CloseableHttpResponse response = null;
try {
String authorization = getAuthorization("root", "root");
httpGet.setHeader("Authorization", authorization);
response = httpClient.execute(httpGet);
HttpEntity responseEntity = response.getEntity();
String message = EntityUtils.toString(responseEntity, "utf-8");
JsonObject result = JsonParser.parseString(message).getAsJsonObject();
assertEquals(200, Integer.parseInt(result.get("code").toString()));
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
} finally {
try {
if (httpClient != null) {
httpClient.close();
}
if (response != null) {
response.close();
}
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
}
}
}
public void rightInsertTablet(CloseableHttpClient httpClient) {
CloseableHttpResponse response = null;
try {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册