未验证 提交 3a84a4df 编写于 作者: Y Yang Zhao 提交者: GitHub

feat: taos-shell support restful interface and token for cloud services (#12701)

* feat(shell): support restful with -R

* fix(shell): restful show large data and format print

* check database before use

* change send use db

* feat: add token for shell restful connection

* fix: revert files

* fix: compatible with x86_64 machine

* fix: add websocket support taos shell restful

* feat: add token to ws url

* fix: change format back

* feat: add limit showed rows to 100

* fix: mac compile
上级 24ac38e0
......@@ -16,10 +16,10 @@
#ifndef __SHELL__
#define __SHELL__
#include <sys/socket.h>
#include "stdbool.h"
#include "taos.h"
#include "taosdef.h"
#include "stdbool.h"
#include "tsclient.h"
#define MAX_USERNAME_SIZE 64
......@@ -43,6 +43,11 @@ typedef struct SShellArguments {
char* auth;
char* database;
char* timezone;
bool restful;
char* token;
int socket;
struct sockaddr_in serv_addr;
TAOS* con;
bool is_raw_time;
bool is_use_passwd;
bool dump_config;
......@@ -59,9 +64,11 @@ typedef struct SShellArguments {
char* netTestRole;
} SShellArguments;
typedef enum WS_ACTION_TYPE_S { WS_CONN, WS_QUERY, WS_FETCH, WS_FETCH_BLOCK } WS_ACTION_TYPE;
/**************** Function declarations ****************/
extern void shellParseArgument(int argc, char* argv[], SShellArguments* arguments);
extern TAOS* shellInit(SShellArguments* args);
extern void shellInit(SShellArguments* args);
extern void* shellLoopQuery(void* arg);
extern void taos_error(TAOS_RES* tres, int64_t st);
extern int regex_match(const char* s, const char* reg, int cflags);
......@@ -76,10 +83,15 @@ void shellCheck(TAOS* con, SShellArguments* args);
void get_history_path(char* history);
void shellCheck(TAOS* con, SShellArguments* args);
void cleanup_handler(void* arg);
int convertHostToServAddr();
void encode_base_64(char* base64_buf, char* user, char* password);
void exitShell();
int shellDumpResult(TAOS_RES* con, char* fname, int* error_no, bool printMode);
void shellGetGrantInfo(void *con);
int isCommentLine(char *line);
void shellGetGrantInfo(void* con);
int isCommentLine(char* line);
int wsclient_handshake();
int wsclient_conn();
void wsclient_query(char* command);
/**************** Global variable declarations ****************/
extern char PROMPT_HEADER[];
......
此差异已折叠。
......@@ -52,6 +52,8 @@ static struct argp_option options[] = {
{"pktlen", 'l', "PKTLEN", 0, "Packet length used for net test, default is 1000 bytes."},
{"pktnum", 'N', "PKTNUM", 0, "Packet numbers used for net test, default is 100."},
{"pkttype", 'S', "PKTTYPE", 0, "Choose packet type used for net test, default is TCP. Only speed test could be either TCP or UDP."},
{"restful", 'R', 0, 0, "Connect and interact with TDengine use restful"},
{"token", 't', "TOKEN", 0, "The token to use when connecting TDengine's cloud services"},
{0}};
static error_t parse_opt(int key, char *arg, struct argp_state *state) {
......@@ -162,6 +164,12 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
case OPT_ABORT:
arguments->abort = 1;
break;
case 't':
arguments->token = arg;
break;
case 'R':
arguments->restful = true;
break;
default:
return ARGP_ERR_UNKNOWN;
}
......
......@@ -44,7 +44,6 @@ void *cancelHandler(void *arg) {
exit(0);
#endif
}
return NULL;
}
......@@ -69,14 +68,15 @@ int checkVersion() {
}
// Global configurations
SShellArguments args = {
.host = NULL,
SShellArguments args = {.host = NULL,
#ifndef TD_WINDOWS
.password = NULL,
#endif
.user = NULL,
.database = NULL,
.timezone = NULL,
.restful = false,
.token = NULL,
.is_raw_time = false,
.is_use_passwd = false,
.dump_config = false,
......@@ -87,8 +87,7 @@ SShellArguments args = {
.pktLen = 1000,
.pktNum = 100,
.pktType = "TCP",
.netTestRole = NULL
};
.netTestRole = NULL};
/*
* Main function.
......@@ -127,12 +126,15 @@ int main(int argc, char* argv[]) {
exit(0);
}
/* Initialize the shell */
TAOS* con = shellInit(&args);
if (con == NULL) {
exit(EXIT_FAILURE);
if (args.restful) {
if (convertHostToServAddr()) {
exit(EXIT_FAILURE);
}
}
/* Initialize the shell */
shellInit(&args);
if (tsem_init(&cancelSem, 0, 0) != 0) {
printf("failed to create cancel semphore\n");
exit(EXIT_FAILURE);
......@@ -148,11 +150,11 @@ int main(int argc, char* argv[]) {
taosSetSignal(SIGABRT, shellQueryInterruptHandler);
/* Get grant information */
shellGetGrantInfo(con);
shellGetGrantInfo(args.con);
/* Loop to query the input. */
while (1) {
pthread_create(&pid, NULL, shellLoopQuery, con);
pthread_create(&pid, NULL, shellLoopQuery, args.con);
pthread_join(pid, NULL);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册