[TD-6285]<feature>: added directive for db name in restful interface
This commit is contained in:
parent
77a920d278
commit
a33afdf351
|
@ -194,6 +194,9 @@ keepColumnName 1
|
||||||
# maximum number of rows returned by the restful interface
|
# maximum number of rows returned by the restful interface
|
||||||
# restfulRowLimit 10240
|
# restfulRowLimit 10240
|
||||||
|
|
||||||
|
# database name must be specified in restful interface if the following parameter is set, off by default
|
||||||
|
# httpDbNameMandatory 1
|
||||||
|
|
||||||
# The following parameter is used to limit the maximum number of lines in log files.
|
# The following parameter is used to limit the maximum number of lines in log files.
|
||||||
# max number of lines per log filters
|
# max number of lines per log filters
|
||||||
# numOfLogLines 10000000
|
# numOfLogLines 10000000
|
||||||
|
|
|
@ -130,6 +130,7 @@ extern int32_t tsHttpMaxThreads;
|
||||||
extern int8_t tsHttpEnableCompress;
|
extern int8_t tsHttpEnableCompress;
|
||||||
extern int8_t tsHttpEnableRecordSql;
|
extern int8_t tsHttpEnableRecordSql;
|
||||||
extern int8_t tsTelegrafUseFieldNum;
|
extern int8_t tsTelegrafUseFieldNum;
|
||||||
|
extern int8_t tsHttpDbNameMandatory;
|
||||||
|
|
||||||
// mqtt
|
// mqtt
|
||||||
extern int8_t tsEnableMqttModule;
|
extern int8_t tsEnableMqttModule;
|
||||||
|
|
|
@ -175,6 +175,7 @@ int32_t tsHttpMaxThreads = 2;
|
||||||
int8_t tsHttpEnableCompress = 1;
|
int8_t tsHttpEnableCompress = 1;
|
||||||
int8_t tsHttpEnableRecordSql = 0;
|
int8_t tsHttpEnableRecordSql = 0;
|
||||||
int8_t tsTelegrafUseFieldNum = 0;
|
int8_t tsTelegrafUseFieldNum = 0;
|
||||||
|
int8_t tsHttpDbNameMandatory = 0;
|
||||||
|
|
||||||
// mqtt
|
// mqtt
|
||||||
int8_t tsEnableMqttModule = 0; // not finished yet, not started it by default
|
int8_t tsEnableMqttModule = 0; // not finished yet, not started it by default
|
||||||
|
@ -1287,6 +1288,16 @@ static void doInitGlobalConfig(void) {
|
||||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||||
taosInitConfigOption(cfg);
|
taosInitConfigOption(cfg);
|
||||||
|
|
||||||
|
cfg.option = "httpDbNameMandatory";
|
||||||
|
cfg.ptr = &tsHttpDbNameMandatory;
|
||||||
|
cfg.valType = TAOS_CFG_VTYPE_INT8;
|
||||||
|
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
|
||||||
|
cfg.minValue = 0;
|
||||||
|
cfg.maxValue = 1;
|
||||||
|
cfg.ptrLength = 0;
|
||||||
|
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||||
|
taosInitConfigOption(cfg);
|
||||||
|
|
||||||
// debug flag
|
// debug flag
|
||||||
cfg.option = "numOfLogLines";
|
cfg.option = "numOfLogLines";
|
||||||
cfg.ptr = &tsNumOfLogLines;
|
cfg.ptr = &tsNumOfLogLines;
|
||||||
|
|
|
@ -6,6 +6,7 @@ INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/cJson/inc)
|
||||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/lz4/inc)
|
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/lz4/inc)
|
||||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc)
|
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc)
|
||||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc)
|
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc)
|
||||||
|
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc)
|
||||||
INCLUDE_DIRECTORIES(inc)
|
INCLUDE_DIRECTORIES(inc)
|
||||||
AUX_SOURCE_DIRECTORY(src SRC)
|
AUX_SOURCE_DIRECTORY(src SRC)
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "httpLog.h"
|
#include "httpLog.h"
|
||||||
#include "httpRestHandle.h"
|
#include "httpRestHandle.h"
|
||||||
#include "httpRestJson.h"
|
#include "httpRestJson.h"
|
||||||
|
#include "tglobal.h"
|
||||||
|
|
||||||
static HttpDecodeMethod restDecodeMethod = {"rest", restProcessRequest};
|
static HttpDecodeMethod restDecodeMethod = {"rest", restProcessRequest};
|
||||||
static HttpDecodeMethod restDecodeMethod2 = {"restful", restProcessRequest};
|
static HttpDecodeMethod restDecodeMethod2 = {"restful", restProcessRequest};
|
||||||
|
@ -111,6 +112,14 @@ bool restProcessSqlRequest(HttpContext* pContext, int32_t timestampFmt) {
|
||||||
pContext->db[0] = '\0';
|
pContext->db[0] = '\0';
|
||||||
|
|
||||||
HttpString *path = &pContext->parser->path[REST_USER_USEDB_URL_POS];
|
HttpString *path = &pContext->parser->path[REST_USER_USEDB_URL_POS];
|
||||||
|
if (tsHttpDbNameMandatory) {
|
||||||
|
if (path->pos == 0) {
|
||||||
|
httpError("context:%p, fd:%d, user:%s, database name is mandatory", pContext, pContext->fd, pContext->user);
|
||||||
|
httpSendErrorResp(pContext, TSDB_CODE_HTTP_INVALID_URL);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (path->pos > 0 && !(strlen(sql) > 4 && (sql[0] == 'u' || sql[0] == 'U') &&
|
if (path->pos > 0 && !(strlen(sql) > 4 && (sql[0] == 'u' || sql[0] == 'U') &&
|
||||||
(sql[1] == 's' || sql[1] == 'S') && (sql[2] == 'e' || sql[2] == 'E') && sql[3] == ' '))
|
(sql[1] == 's' || sql[1] == 'S') && (sql[2] == 'e' || sql[2] == 'E') && sql[3] == ' '))
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,124 @@
|
||||||
|
system sh/stop_dnodes.sh
|
||||||
|
sleep 2000
|
||||||
|
system sh/deploy.sh -n dnode1 -i 1
|
||||||
|
system sh/cfg.sh -n dnode1 -c walLevel -v 1
|
||||||
|
system sh/cfg.sh -n dnode1 -c http -v 1
|
||||||
|
system sh/cfg.sh -n dnode1 -c httpDbNameMandatory -v 1
|
||||||
|
system sh/exec.sh -n dnode1 -s start
|
||||||
|
|
||||||
|
sleep 2000
|
||||||
|
sql connect
|
||||||
|
sql drop database if exists db
|
||||||
|
|
||||||
|
print ============================ dnode1 start
|
||||||
|
|
||||||
|
print =============== step1 - login
|
||||||
|
|
||||||
|
system_content curl 127.0.0.1:7111/rest/login/root/taosdata
|
||||||
|
print curl 127.0.0.1:7111/rest/login/root/taosdata -----> $system_content
|
||||||
|
|
||||||
|
if $system_content != @{"status":"succ","code":0,"desc":"/KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04"}@ then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print =============== step2 - execute sql without db_name
|
||||||
|
|
||||||
|
print curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'show databases' 127.0.0.1:7111/rest/sql
|
||||||
|
|
||||||
|
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'show databases' 127.0.0.1:7111/rest/sql
|
||||||
|
|
||||||
|
if $system_content != @{"status":"error","code":4354,"desc":"invalid url format"}@ then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'create database if not exists db' 127.0.0.1:7111/rest/sql
|
||||||
|
|
||||||
|
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'create database if not exists db' 127.0.0.1:7111/rest/sql
|
||||||
|
|
||||||
|
if $system_content != @{"status":"error","code":4354,"desc":"invalid url format"}@ then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'create table table_rest (ts timestamp, i int)' 127.0.0.1:7111/rest/sql
|
||||||
|
|
||||||
|
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'create table table_rest (ts timestamp, i int)' 127.0.0.1:7111/rest/sql
|
||||||
|
|
||||||
|
if $system_content != @{"status":"error","code":4354,"desc":"invalid url format"}@ then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'insert into table_rest (now, 1)' 127.0.0.1:7111/rest/sql
|
||||||
|
|
||||||
|
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'insert into table_rest values (now, 1)' 127.0.0.1:7111/rest/sql
|
||||||
|
|
||||||
|
if $system_content != @{"status":"error","code":4354,"desc":"invalid url format"}@ then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'select * from table_rest' 127.0.0.1:7111/rest/sql
|
||||||
|
|
||||||
|
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'select * from table_rest' 127.0.0.1:7111/rest/sql
|
||||||
|
|
||||||
|
if $system_content != @{"status":"error","code":4354,"desc":"invalid url format"}@ then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'drop database if exists db' 127.0.0.1:7111/rest/sql
|
||||||
|
|
||||||
|
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'drop database if exists db' 127.0.0.1:7111/rest/sql
|
||||||
|
|
||||||
|
if $system_content != @{"status":"error","code":4354,"desc":"invalid url format"}@ then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print =============== step3 - execute sql with db_name
|
||||||
|
|
||||||
|
print curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'show databases' 127.0.0.1:7111/rest/sql/databases
|
||||||
|
|
||||||
|
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'show databases' 127.0.0.1:7111/rest/sql/databases
|
||||||
|
|
||||||
|
if $system_content != @{"status":"succ","head":["name","created_time","ntables","vgroups","replica","quorum","days","keep","cache(MB)","blocks","minrows","maxrows","wallevel","fsync","comp","cachelast","precision","update","status"],"column_meta":[["name",8,32],["created_time",9,8],["ntables",4,4],["vgroups",4,4],["replica",3,2],["quorum",3,2],["days",3,2],["keep",8,24],["cache(MB)",4,4],["blocks",4,4],["minrows",4,4],["maxrows",4,4],["wallevel",2,1],["fsync",4,4],["comp",2,1],["cachelast",2,1],["precision",8,3],["update",2,1],["status",8,10]],"data":[],"rows":0}@ then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'create database if not exists db' 127.0.0.1:7111/rest/sql/db
|
||||||
|
|
||||||
|
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'create database if not exists db' 127.0.0.1:7111/rest/sql/db
|
||||||
|
|
||||||
|
if $system_content != @{"status":"succ","head":["affected_rows"],"column_meta":[["affected_rows",4,4]],"data":[[0]],"rows":1}@ then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'create table table_rest (ts timestamp, i int)' 127.0.0.1:7111/rest/sql/db
|
||||||
|
|
||||||
|
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'create table table_rest (ts timestamp, i int)' 127.0.0.1:7111/rest/sql/db
|
||||||
|
|
||||||
|
if $system_content != @{"status":"succ","head":["affected_rows"],"column_meta":[["affected_rows",4,4]],"data":[[0]],"rows":1}@ then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'insert into table_rest (now, 1)' 127.0.0.1:7111/rest/sql/db
|
||||||
|
|
||||||
|
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'insert into table_rest values (1629904789233, 1)' 127.0.0.1:7111/rest/sql/db
|
||||||
|
|
||||||
|
if $system_content != @{"status":"succ","head":["affected_rows"],"column_meta":[["affected_rows",4,4]],"data":[[1]],"rows":1}@ then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'select * from table_rest' 127.0.0.1:7111/rest/sql/db
|
||||||
|
|
||||||
|
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'select * from table_rest' 127.0.0.1:7111/rest/sql/db
|
||||||
|
|
||||||
|
if $system_content != @{"status":"succ","head":["ts","i"],"column_meta":[["ts",9,8],["i",4,4]],"data":[["2021-08-25 23:19:49.233",1]],"rows":1}@ then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'drop database if exists db' 127.0.0.1:7111/rest/sql/db
|
||||||
|
|
||||||
|
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'drop database if exists db' 127.0.0.1:7111/rest/sql/db
|
||||||
|
|
||||||
|
if $system_content != @{"status":"succ","head":["affected_rows"],"column_meta":[["affected_rows",4,4]],"data":[[0]],"rows":1}@ then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
Loading…
Reference in New Issue