Skip to content

Commit

Permalink
fix: remove pwd (vesoft-inc#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
hetao92 authored Mar 8, 2022
1 parent 4a1c714 commit 3b858b5
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 15 deletions.
2 changes: 0 additions & 2 deletions app/config/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -42,6 +41,5 @@ export default {
getImportWokingDir,
deteleFile,
getFiles,
getAppInfo,
uploadFiles,
};
6 changes: 4 additions & 2 deletions app/store/models/nebula.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions app/utils/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})` : '()'
Expand Down
7 changes: 6 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions server/pkg/webserver/base/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
31 changes: 25 additions & 6 deletions server/pkg/webserver/controller/gateway.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -66,16 +66,35 @@ 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{
Code: base.Error,
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
}
Expand Down

0 comments on commit 3b858b5

Please sign in to comment.