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