From 71ae453b8331b61b21d492d32652b2aefcc83bd3 Mon Sep 17 00:00:00 2001 From: Nut He <18328704+hetao92@users.noreply.github.com> Date: Mon, 7 Mar 2022 19:43:20 +0800 Subject: [PATCH] fix: remove pwd --- app/config/service.ts | 2 -- app/store/models/nebula.ts | 6 +++-- app/utils/gql.ts | 5 ++-- package-lock.json | 7 ++++- package.json | 1 + server/pkg/webserver/base/types.go | 5 ++-- server/pkg/webserver/controller/gateway.go | 31 +++++++++++++++++----- 7 files changed, 42 insertions(+), 15 deletions(-) diff --git a/app/config/service.ts b/app/config/service.ts index fdea0d8e..6cbdccdf 100644 --- a/app/config/service.ts +++ b/app/config/service.ts @@ -22,7 +22,6 @@ const deteleFile = params => { return _delete(`/api/files/${filename}`)(); }; const getFiles = get('/api/files'); -const getAppInfo = get('/api/app'); const uploadFiles = (params?, config?) => put('/api/files')(params, { ...config, @@ -42,6 +41,5 @@ export default { getImportWokingDir, deteleFile, getFiles, - getAppInfo, uploadFiles, }; diff --git a/app/store/models/nebula.ts b/app/store/models/nebula.ts index 0128e2fc..c1277519 100644 --- a/app/store/models/nebula.ts +++ b/app/store/models/nebula.ts @@ -1,5 +1,6 @@ import { createModel } from '@rematch/core'; import { message } from 'antd'; +import { Base64 } from 'js-base64'; import cookies from 'js-cookie'; import _ from 'lodash'; import intl from 'react-intl-universal'; @@ -182,14 +183,15 @@ export const nebula = createModel({ { address, port, - username, - password, }, { trackEventConfig: { category: 'user', action: 'sign_in', }, + headers: { + Authorization: `Bearer ${Base64.encode(`${username}:${password}`)}`, + }, }, )) as any; if (code === 0) { diff --git a/app/utils/gql.ts b/app/utils/gql.ts index 60844fe4..80619a75 100644 --- a/app/utils/gql.ts +++ b/app/utils/gql.ts @@ -177,8 +177,9 @@ export const getTagOrEdgeCreateGQL = (params: { .join(', ') : ''; const ttlStr = ttlConfig - ? `TTL_DURATION = ${ttlConfig.ttl_duration || - ''}, TTL_COL = "${handleEscape(ttlConfig.ttl_col) || ''}"` + ? `TTL_DURATION = ${ttlConfig.ttl_duration || ''}, TTL_COL = "${ + ttlConfig.ttl_col ? handleEscape(ttlConfig.ttl_col) : '' + }"` : ''; const gql = `CREATE ${type} ${handleKeyword(name)} ${ fieldsStr.length > 0 ? `(${fieldsStr})` : '()' diff --git a/package-lock.json b/package-lock.json index 43bd1291..0ac4a3f8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8003,6 +8003,11 @@ "integrity": "sha1-UVKcOzDV/RWdpgwnzu3Blfr41BQ=", "dev": true }, + "js-base64": { + "version": "3.7.2", + "resolved": "https://registry.npmmirror.com/js-base64/-/js-base64-3.7.2.tgz", + "integrity": "sha512-NnRs6dsyqUXejqk/yv2aiXlAvOs56sLkX6nUdeaNezI5LFFLlsZjOThmwnrcwh5ZZRwZlCMnVAY3CvhIhoVEKQ==" + }, "js-cookie": { "version": "2.2.1", "resolved": "https://registry.nlark.com/js-cookie/download/js-cookie-2.2.1.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fjs-cookie%2Fdownload%2Fjs-cookie-2.2.1.tgz", @@ -13612,7 +13617,7 @@ "dependencies": { "acorn": { "version": "8.7.0", - "resolved": "https://registry.npmmirror.com/acorn/download/acorn-8.7.0.tgz", + "resolved": "https://registry.npmmirror.com/acorn/-/acorn-8.7.0.tgz", "integrity": "sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ==", "dev": true } diff --git a/package.json b/package.json index 64f2e077..17f3137c 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "file-loader": "^6.2.0", "file-saver": "^2.0.5", "http-proxy-middleware": "^0.20.0", + "js-base64": "^3.7.2", "js-cookie": "^2.2.1", "json-bigint": "^1.0.0", "json2csv": "^5.0.6", diff --git a/server/pkg/webserver/base/types.go b/server/pkg/webserver/base/types.go index c6daa797..27b906ad 100644 --- a/server/pkg/webserver/base/types.go +++ b/server/pkg/webserver/base/types.go @@ -3,6 +3,7 @@ package base type StatusCode int const ( - Error StatusCode = -1 - Success StatusCode = 0 + Error StatusCode = -1 + Success StatusCode = 0 + AuthorizationError StatusCode = 401 ) diff --git a/server/pkg/webserver/controller/gateway.go b/server/pkg/webserver/controller/gateway.go index edcc67ea..7a937663 100644 --- a/server/pkg/webserver/controller/gateway.go +++ b/server/pkg/webserver/controller/gateway.go @@ -1,7 +1,9 @@ package controller import ( + "encoding/base64" "fmt" + "strings" "github.com/vesoft-inc/nebula-http-gateway/ccore/nebula/gateway/dao" "github.com/vesoft-inc/nebula-http-gateway/ccore/nebula/types" @@ -20,10 +22,8 @@ type execNGQLParams struct { } type connectDBParams struct { - Address string `json:"address"` - Port int `json:"port"` - Username string `json:"username"` - Password string `json:"password"` + Address string `json:"address"` + Port int `json:"port"` } type disConnectDBParams struct { @@ -66,8 +66,27 @@ func ExecNGQL(ctx iris.Context) base.Result { } func ConnectDB(ctx iris.Context) base.Result { + token := ctx.GetHeader("Authorization") + tokenSlice := strings.Split(token, " ") + if len(tokenSlice) != 2 { + return base.Response{ + Code: base.AuthorizationError, + Message: "Not get token", + } + } + + decode, err := base64.StdEncoding.DecodeString(tokenSlice[1]) + if err != nil { + return base.Response{ + Code: base.AuthorizationError, + Message: err.Error(), + } + } + account := strings.Split(string(decode), ":") + username, password := account[0], account[1] + params := new(connectDBParams) - err := ctx.ReadJSON(params) + err = ctx.ReadJSON(params) if err != nil { zap.L().Warn("connectDBParams get fail", zap.Error(err)) return base.Response{ @@ -75,7 +94,7 @@ func ConnectDB(ctx iris.Context) base.Result { Message: err.Error(), } } - clientInfo, err := dao.Connect(params.Address, params.Port, params.Username, params.Password) + clientInfo, err := dao.Connect(params.Address, params.Port, username, password) if err != nil { return nil }