-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: middleware #208
feat: middleware #208
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
Name: studio-api | ||
Host: 0.0.0.0 | ||
Port: 7002 | ||
Port: 9000 | ||
MaxBytes: 1073741824 | ||
Debug: | ||
Enable: false | ||
Auth: | ||
AccessSecret: "login_secret" | ||
AccessExpire: 7200 | ||
AccessExpire: 1800 | ||
File: | ||
UploadDir: "./upload/" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package gateway | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/vesoft-inc/nebula-studio/server/api/studio/internal/service" | ||
"github.com/vesoft-inc/nebula-studio/server/api/studio/internal/svc" | ||
"github.com/vesoft-inc/nebula-studio/server/api/studio/internal/types" | ||
|
||
"github.com/zeromicro/go-zero/core/logx" | ||
) | ||
|
||
type BatchExecNGQLLogic struct { | ||
logx.Logger | ||
ctx context.Context | ||
svcCtx *svc.ServiceContext | ||
} | ||
|
||
func NewBatchExecNGQLLogic(ctx context.Context, svcCtx *svc.ServiceContext) BatchExecNGQLLogic { | ||
return BatchExecNGQLLogic{ | ||
Logger: logx.WithContext(ctx), | ||
ctx: ctx, | ||
svcCtx: svcCtx, | ||
} | ||
} | ||
|
||
func (l *BatchExecNGQLLogic) BatchExecNGQL(req types.BatchExecNGQLParams) (*types.AnyResponse, error) { | ||
return service.NewGatewayService(l.ctx, l.svcCtx).BatchExecNGQL(&req) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package gateway | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/vesoft-inc/nebula-studio/server/api/studio/internal/service" | ||
"github.com/vesoft-inc/nebula-studio/server/api/studio/internal/svc" | ||
"github.com/vesoft-inc/nebula-studio/server/api/studio/internal/types" | ||
|
||
"github.com/zeromicro/go-zero/core/logx" | ||
) | ||
|
||
type DisonnectLogic struct { | ||
logx.Logger | ||
ctx context.Context | ||
svcCtx *svc.ServiceContext | ||
} | ||
|
||
func NewDisonnectLogic(ctx context.Context, svcCtx *svc.ServiceContext) DisonnectLogic { | ||
return DisonnectLogic{ | ||
Logger: logx.WithContext(ctx), | ||
ctx: ctx, | ||
svcCtx: svcCtx, | ||
} | ||
} | ||
|
||
func (l *DisonnectLogic) Disonnect(req types.DisconnectDBParams) (*types.AnyResponse, error) { | ||
return service.NewGatewayService(l.ctx, l.svcCtx).DisconnectDB(&req) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,12 @@ package service | |
|
||
import ( | ||
"context" | ||
"encoding/base64" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/vesoft-inc/nebula-http-gateway/ccore/nebula/gateway/dao" | ||
"github.com/vesoft-inc/nebula-studio/server/api/studio/internal/svc" | ||
"github.com/vesoft-inc/nebula-studio/server/api/studio/internal/types" | ||
"github.com/vesoft-inc/nebula-studio/server/api/studio/pkg/auth" | ||
"github.com/vesoft-inc/nebula-studio/server/api/studio/pkg/base" | ||
"github.com/vesoft-inc/nebula-studio/server/api/studio/pkg/ecode" | ||
|
||
"github.com/zeromicro/go-zero/core/logx" | ||
|
@@ -19,8 +17,10 @@ var _ GatewayService = (*gatewayService)(nil) | |
|
||
type ( | ||
GatewayService interface { | ||
GetExec(request *types.ExecNGQLParams) (*types.AnyResponse, error) | ||
ExecNGQL(request *types.ExecNGQLParams) (*types.AnyResponse, error) | ||
BatchExecNGQL(request *types.BatchExecNGQLParams) (*types.AnyResponse, error) | ||
ConnectDB(request *types.ConnectDBParams) (*types.ConnectDBResult, error) | ||
DisconnectDB(request *types.DisconnectDBParams) (*types.AnyResponse, error) | ||
} | ||
|
||
gatewayService struct { | ||
|
@@ -38,50 +38,57 @@ func NewGatewayService(ctx context.Context, svcCtx *svc.ServiceContext) GatewayS | |
} | ||
} | ||
|
||
func (s *gatewayService) GetExec(request *types.ExecNGQLParams) (*types.AnyResponse, error) { | ||
return &types.AnyResponse{ | ||
Data: map[string]any{ | ||
"message": "ok", | ||
}, | ||
func (s *gatewayService) ConnectDB(request *types.ConnectDBParams) (*types.ConnectDBResult, error) { | ||
return &types.ConnectDBResult{ | ||
Version: string(request.NebulaVersion), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so where you real make the db connection? logics seems to be delete above? |
||
}, nil | ||
} | ||
|
||
func (s *gatewayService) ConnectDB(request *types.ConnectDBParams) (*types.ConnectDBResult, error) { | ||
fmt.Println("======request999", request) | ||
tokenSplit := strings.Split(request.Authorization, " ") | ||
if len(tokenSplit) != 2 { | ||
return nil, ecode.WithCode(ecode.ErrParam, nil, "invalid authorization") | ||
func (s *gatewayService) DisconnectDB(request *types.DisconnectDBParams) (*types.AnyResponse, error) { | ||
if request.NSID != "" { | ||
dao.Disconnect(request.NSID) | ||
} | ||
return nil, nil | ||
} | ||
|
||
decode, err := base64.StdEncoding.DecodeString(tokenSplit[1]) | ||
func (s *gatewayService) ExecNGQL(request *types.ExecNGQLParams) (*types.AnyResponse, error) { | ||
execute, _, err := dao.Execute(request.NSID, request.Gql, request.ParamList) | ||
if err != nil { | ||
return nil, ecode.WithCode(ecode.ErrParam, err) | ||
return nil, ecode.WithCode(ecode.ErrInternalServer, err, "exec failed") | ||
} | ||
return &types.AnyResponse{Data: execute}, nil | ||
} | ||
|
||
loginInfo := strings.Split(string(decode), ":") | ||
if len(loginInfo) < 2 { | ||
return nil, ecode.WithCode(ecode.ErrParam, nil, "len of account is less than two") | ||
func (s *gatewayService) BatchExecNGQL(request *types.BatchExecNGQLParams) (*types.AnyResponse, error) { | ||
data := make([]map[string]interface{}, 0) | ||
|
||
NSID := request.NSID | ||
gqls := request.Gqls | ||
paramList := request.ParamList | ||
|
||
for _, gql := range gqls { | ||
execute, _, err := dao.Execute(NSID, gql, make([]string, 0)) | ||
gqlRes := map[string]interface{}{"gql": gql, "data": execute} | ||
if err != nil { | ||
gqlRes["message"] = err.Error() | ||
gqlRes["code"] = base.Error | ||
} else { | ||
gqlRes["code"] = base.Success | ||
} | ||
data = append(data, gqlRes) | ||
} | ||
|
||
username, password := loginInfo[0], loginInfo[1] | ||
clientInfo, err := dao.Connect(request.Address, request.Port, username, password) | ||
|
||
tokenString, err := auth.CreateToken( | ||
&auth.AuthData{ | ||
NebulaAddress: request.Address, | ||
Username: username, | ||
ClientID: clientInfo.ClientID, | ||
}, | ||
&s.svcCtx.Config, | ||
) | ||
|
||
fmt.Println("=====tokenString", tokenString) | ||
|
||
if err != nil { | ||
return nil, ecode.WithInternalServer(err, "connect db failed") | ||
if len(paramList) > 0 { | ||
execute, _, err := dao.Execute(NSID, "", paramList) | ||
gqlRes := map[string]interface{}{"gql": strings.Join(paramList, "; "), "data": execute} | ||
if err != nil { | ||
gqlRes["message"] = err.Error() | ||
gqlRes["code"] = base.Error | ||
} else { | ||
gqlRes["code"] = base.Success | ||
} | ||
data = append(data, gqlRes) | ||
} | ||
|
||
return &types.ConnectDBResult{ | ||
Version: string(clientInfo.NebulaVersion), | ||
}, nil | ||
return &types.AnyResponse{Data: data}, nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using a more strict random string?