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

impl: add env variable url\token support for cloud platform (#13607)

上级 bdf4b98a
......@@ -85,6 +85,7 @@ void get_history_path(char* history);
void shellCheck(TAOS* con, SShellArguments* args);
void cleanup_handler(void* arg);
int convertHostToServAddr();
char *last_strstr(const char *haystack, const char *needle);
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);
......
......@@ -76,12 +76,12 @@ void shellInit(SShellArguments *_args) {
_args->database = calloc(1, 128);
_args->socket = socket(AF_INET, SOCK_STREAM, 0);
if (_args->socket < 0) {
fprintf(stderr, "failed to create socket");
fprintf(stderr, "failed to create socket\n");
exit(EXIT_FAILURE);
}
int retConn = connect(_args->socket, (struct sockaddr *)&(_args->serv_addr), sizeof(struct sockaddr));
if (retConn < 0) {
fprintf(stderr, "failed to connect");
fprintf(stderr, "failed to connect\n");
close(_args->socket);
exit(EXIT_FAILURE);
}
......@@ -1145,6 +1145,20 @@ int taos_base64_encode(unsigned char *source, size_t sourcelen, char *target, si
return 1;
}
char *last_strstr(const char *haystack, const char *needle) {
if (*needle == '\0')
return (char *) haystack;
char *res = NULL;
for (;;) {
char *p = strstr(haystack, needle);
if (p == NULL) break;
res = p;
haystack = p + 1;
}
return res;
}
int convertHostToServAddr() {
if (args.port == 0) {
args.port = 6041;
......@@ -1154,7 +1168,7 @@ int convertHostToServAddr() {
}
struct hostent *server = gethostbyname(args.host);
if ((server == NULL) || (server->h_addr == NULL)) {
fprintf(stderr, "no such host: %s", args.host);
fprintf(stderr, "no such host: %s\n", args.host);
return -1;
}
memset(&(args.serv_addr), 0, sizeof(struct sockaddr_in));
......
......@@ -102,6 +102,25 @@ int main(int argc, char* argv[]) {
exit(EXIT_FAILURE);
}
char* cloud_url = getenv("TDENGINE_CLOUD_URL");
if (cloud_url != NULL) {
char* tmp = last_strstr(cloud_url, ":");
if ((tmp == NULL) && ((tmp + 1) != NULL )) {
fprintf(stderr, "Invalid format in environment variable TDENGINE_CLOUD_URL: %s\n", cloud_url);
exit(EXIT_FAILURE);
} else {
args.port = atoi(tmp + 1);
tmp[0] = '\0';
args.host = cloud_url;
}
}
char* cloud_token = getenv("TDENGINE_CLOUD_TOKEN");
if (cloud_token != NULL) {
args.token = cloud_token;
}
shellParseArgument(argc, argv, &args);
if (args.dump_config) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册