Documentation
¶
Index ¶
- Constants
- Variables
- func AllowQuery(allowQueryWhenLessThanAuditLevel string, sqlResults []AuditSQLResV2) bool
- func GenerateCloudbeaverUserId(name string) string
- func RemoveCloudbeaverUserIdPrefix(name string) string
- type AuditResDataV2
- type AuditResults
- type AuditSQLReply
- type AuditSQLReq
- type AuditSQLResV2
- type CBVersion
- type Client
- type ClientOption
- func ImmediatelyCloseReqBody() ClientOption
- func UseMultipartForm() ClientOption
- func WithCookie(cookie []*http.Cookie) ClientOption
- func WithHTTPClient(httpclient *http.Client) ClientOption
- func WithHttpResHandler(fn func(response *http.Response)) ClientOption
- func WithLogger(logger *utilLog.Helper) ClientOption
- func WithMaxRetries(maxRetries int) ClientOption
- type CloudBeaverV2215
- func (CloudBeaverV2215) CreateConnectionQuery() string
- func (CloudBeaverV2215) CreateUserQuery() string
- func (CloudBeaverV2215) DeleteConnectionQuery() string
- func (CloudBeaverV2215) GetActiveUserQuery() string
- func (CloudBeaverV2215) GetExecutionContextListQuery() string
- func (CloudBeaverV2215) GetUserConnectionsQuery() string
- func (CloudBeaverV2215) GrantUserRoleQuery() string
- func (CloudBeaverV2215) IsUserExistQuery(userId string) (string, map[string]interface{})
- func (CloudBeaverV2215) LoginQuery() string
- func (CloudBeaverV2215) SetUserConnectionsQuery() string
- func (CloudBeaverV2215) UpdateConnectionQuery() string
- func (CloudBeaverV2215) UpdatePasswordQuery() string
- type CloudBeaverV2221
- type CloudBeaverV2223
- type CloudBeaverV2321
- type CloudBeaverV2521
- type ContextKey
- type DirectAuditParams
- type File
- type GraphQLImpl
- type MutationResolverImpl
- func (r *MutationResolverImpl) AsyncSQLExecuteQuery(ctx context.Context, projectID *string, connectionID string, contextID string, ...) (*model.AsyncTaskInfo, error)
- func (r *MutationResolverImpl) AsyncSQLExecuteResults(ctx context.Context, taskID string) (*model.SQLExecuteInfo, error)
- func (r *MutationResolverImpl) AuditSQL(ctx context.Context, sql string, connectionID string) (auditSuccess bool, result []AuditSQLResV2, err error)
- type NavNodeChildrenResponse
- type NavNodeInfo
- type NavNodeObject
- type Next
- type QueryResolverImpl
- type Request
- type ResolverImpl
- type SQLExecuteResultsHandler
Constants ¶
const ( UsernamePrefix = "dms-" SQLEDirectAudit ContextKey = "sqle_direct_audit" SQLEProxyName = _const.SqleComponentName )
const AuditResultKey = "audit_result"
const GraphQLConfigVersionQuery = `
query serverConfig {
serverConfig {
version
}
}`
Variables ¶
var ( Version2215 = CBVersion{ // contains filtered or unexported fields } Version2221 = CBVersion{ // contains filtered or unexported fields } Version2223 = CBVersion{ // contains filtered or unexported fields } Version2321 = CBVersion{ // contains filtered or unexported fields } Version2521 = CBVersion{ // contains filtered or unexported fields } )
var GraphQLHandlerRouters = map[string]gqlBehavior{ "asyncReadDataFromContainer": { UseLocalHandler: true, NeedModifyRemoteRes: false, Preprocessing: func(ctx echo.Context, params *graphql.RawParams) (err error) { if filter, ok := params.Variables["filter"].(map[string]interface{}); ok { if filter["limit"] != nil { params.Variables["filter"].(map[string]interface{})["limit"], err = strconv.Atoi(fmt.Sprintf("%v", params.Variables["filter"].(map[string]interface{})["limit"])) } } return err }, }, "asyncSqlExecuteQuery": { UseLocalHandler: true, NeedModifyRemoteRes: false, Preprocessing: func(ctx echo.Context, params *graphql.RawParams) (err error) { keysToConvert := map[string]struct{}{ "limit": {}, "attributePosition": {}, "orderPosition": {}, } if filter, ok := params.Variables["filter"]; ok { if err := convertKeysToInt(filter, keysToConvert); err != nil { log.Printf("convertKeysToInt error: %v", err) } } return err }, }, "getAsyncTaskInfo": { UseLocalHandler: true, }, "getSqlExecuteTaskResults": { UseLocalHandler: true, NeedModifyRemoteRes: true, }, "updateResultsDataBatch": { UseLocalHandler: true, }, "asyncUpdateResultsDataBatch": { UseLocalHandler: true, }, "getActiveUser": { UseLocalHandler: true, NeedModifyRemoteRes: true, }, "authLogout": { Disable: true, }, "authLogin": { Disable: true, }, "configureServer": { Disable: true, }, "createUser": { Disable: true, }, "setUserCredentials": { Disable: true, }, "enableUser": { Disable: true, }, "grantUserRole": { Disable: true, }, "setConnections": { Disable: true, }, "saveUserMetaParameters": { Disable: true, }, "deleteUser": { Disable: true, }, "createRole": { Disable: true, }, "updateRole": { Disable: true, }, "deleteRole": { Disable: true, }, "authChangeLocalPassword": { Disable: true, }, "navNodeChildren": {}, }
Functions ¶
func AllowQuery ¶
func AllowQuery(allowQueryWhenLessThanAuditLevel string, sqlResults []AuditSQLResV2) bool
AllowQuery 根据AllowQueryWhenLessThanAuditLevel字段判断能否执行SQL
Types ¶
type AuditResDataV2 ¶
type AuditResDataV2 struct {
AuditLevel string `json:"audit_level" enums:"normal,notice,warn,error,"`
Score int32 `json:"score"`
PassRate float64 `json:"pass_rate"`
SQLResults []AuditSQLResV2 `json:"sql_results"`
}
type AuditResults ¶
type AuditResults struct {
SQL string
IsSuccess bool
Results []AuditSQLResV2
}
type AuditSQLReply ¶
type AuditSQLReply struct {
Code int `json:"code" example:"0"`
Message string `json:"message" example:"ok"`
Data *AuditResDataV2 `json:"data"`
}
type AuditSQLReq ¶
type AuditSQLReq struct {
InstanceType string `json:"instance_type" form:"instance_type" example:"MySQL" valid:"required"`
// 调用方不应该关心SQL是否被完美的拆分成独立的条目, 拆分SQL由SQLE实现
SQLContent string `json:"sql_content" form:"sql_content" example:"select * from t1; select * from t2;" valid:"required"`
SQLType string `json:"sql_type" form:"sql_type" example:"sql" enums:"sql,mybatis," valid:"omitempty,oneof=sql mybatis"`
ProjectId string `json:"project_id" form:"project_id" example:"700300" valid:"required"`
RuleTemplateName string `json:"rule_template_name" form:"rule_template_name" example:"default" valid:"required"`
InstanceName string `json:"instance_name" form:"instance_name" example:"instance1"`
SchemaName string `json:"schema_name" form:"schema_name" example:"schema1"`
}
type AuditSQLResV2 ¶
type CBVersion ¶
type CBVersion struct {
// contains filtered or unexported fields
}
CloudBeaver 版本号格式一般为 X.X.X.X 格式,例如 '22.3.1.202212261505' , 其中前三位为版本号
func NewCBVersion ¶
type Client ¶
type Client struct {
// Log is called with various debug information.
// To log to standard out, use:
// client.Log = func(s string) { log.Println(s) }
Log func(s string)
HttpResHandler func(res *http.Response)
// contains filtered or unexported fields
}
Client is a client for interacting with a GraphQL API.
func NewGraphQlClient ¶
func NewGraphQlClient(endpoint string, opts ...ClientOption) *Client
NewClient makes a new Client capable of making GraphQL requests.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption are functions that are passed into NewClient to modify the behaviour of the Client.
func ImmediatelyCloseReqBody ¶
func ImmediatelyCloseReqBody() ClientOption
ImmediatelyCloseReqBody will close the req body immediately after each request body is ready
func UseMultipartForm ¶
func UseMultipartForm() ClientOption
UseMultipartForm uses multipart/form-data and activates support for files.
func WithCookie ¶
func WithCookie(cookie []*http.Cookie) ClientOption
func WithHTTPClient ¶
func WithHTTPClient(httpclient *http.Client) ClientOption
WithHTTPClient specifies the underlying http.Client to use when making requests.
NewClient(endpoint, WithHTTPClient(specificHTTPClient))
func WithHttpResHandler ¶
func WithHttpResHandler(fn func(response *http.Response)) ClientOption
func WithLogger ¶
func WithLogger(logger *utilLog.Helper) ClientOption
func WithMaxRetries ¶
func WithMaxRetries(maxRetries int) ClientOption
WithMaxRetries 设置最大重试次数,默认为0表示不重试
type CloudBeaverV2215 ¶
type CloudBeaverV2215 struct{}
TODO 暂时无法确定这套查询语句是兼容到22.1.5版本还是22.1.4版本, 因为虽然找到了22.1.4版本的镜像, 但没找到22.1.4版本的代码
func (CloudBeaverV2215) CreateConnectionQuery ¶
func (CloudBeaverV2215) CreateConnectionQuery() string
func (CloudBeaverV2215) CreateUserQuery ¶
func (CloudBeaverV2215) CreateUserQuery() string
func (CloudBeaverV2215) DeleteConnectionQuery ¶
func (CloudBeaverV2215) DeleteConnectionQuery() string
func (CloudBeaverV2215) GetActiveUserQuery ¶
func (CloudBeaverV2215) GetActiveUserQuery() string
func (CloudBeaverV2215) GetExecutionContextListQuery ¶
func (CloudBeaverV2215) GetExecutionContextListQuery() string
func (CloudBeaverV2215) GetUserConnectionsQuery ¶
func (CloudBeaverV2215) GetUserConnectionsQuery() string
func (CloudBeaverV2215) GrantUserRoleQuery ¶
func (CloudBeaverV2215) GrantUserRoleQuery() string
func (CloudBeaverV2215) IsUserExistQuery ¶
func (CloudBeaverV2215) IsUserExistQuery(userId string) (string, map[string]interface{})
func (CloudBeaverV2215) LoginQuery ¶
func (CloudBeaverV2215) LoginQuery() string
func (CloudBeaverV2215) SetUserConnectionsQuery ¶
func (CloudBeaverV2215) SetUserConnectionsQuery() string
func (CloudBeaverV2215) UpdateConnectionQuery ¶
func (CloudBeaverV2215) UpdateConnectionQuery() string
func (CloudBeaverV2215) UpdatePasswordQuery ¶
func (CloudBeaverV2215) UpdatePasswordQuery() string
type CloudBeaverV2221 ¶
type CloudBeaverV2221 struct {
CloudBeaverV2215
}
func (CloudBeaverV2221) CreateUserQuery ¶
func (CloudBeaverV2221) CreateUserQuery() string
type CloudBeaverV2223 ¶
type CloudBeaverV2223 struct {
CloudBeaverV2221
}
func (CloudBeaverV2223) CreateUserQuery ¶
func (CloudBeaverV2223) CreateUserQuery() string
func (CloudBeaverV2223) GrantUserRoleQuery ¶
func (CloudBeaverV2223) GrantUserRoleQuery() string
type CloudBeaverV2321 ¶
type CloudBeaverV2321 struct {
CloudBeaverV2223
}
func (CloudBeaverV2321) GetActiveUserQuery ¶
func (CloudBeaverV2321) GetActiveUserQuery() string
func (CloudBeaverV2321) IsUserExistQuery ¶
func (CloudBeaverV2321) IsUserExistQuery(userId string) (string, map[string]interface{})
type CloudBeaverV2521 ¶
type CloudBeaverV2521 struct {
CloudBeaverV2321
}
func (CloudBeaverV2521) GetUserConnectionsQuery ¶
func (CloudBeaverV2521) GetUserConnectionsQuery() string
type ContextKey ¶
type ContextKey string
type DirectAuditParams ¶
type DirectAuditParams struct {
AuditSQLReq
SQLEAddr string
AllowQueryWhenLessThanAuditLevel string
}
type GraphQLImpl ¶
type GraphQLImpl interface {
CreateConnectionQuery() string
UpdateConnectionQuery() string
DeleteConnectionQuery() string
GetUserConnectionsQuery() string
SetUserConnectionsQuery() string
IsUserExistQuery(userId string) (string, map[string]interface{})
UpdatePasswordQuery() string
CreateUserQuery() string
GrantUserRoleQuery() string
LoginQuery() string
GetActiveUserQuery() string
GetExecutionContextListQuery() string
}
不同版本的CloudBeaver间存在不兼容查询语句 说明: 接口传参时不要删除旧版查询语句的查询参数,多余的参数对新接口没有影响但是可以兼容旧版本
func NewGraphQL ¶
func NewGraphQL(url string) (GraphQLImpl, error)
type MutationResolverImpl ¶
type MutationResolverImpl struct {
*resolver.MutationResolverImpl
Ctx echo.Context
Next Next
// SQLExecuteResultsHandlerFn 为对SQL结果集的处理方法,具体处理逻辑为业务行为,由外部biz层定义后传入
SQLExecuteResultsHandlerFn SQLExecuteResultsHandler
}
func (*MutationResolverImpl) AsyncSQLExecuteQuery ¶
func (r *MutationResolverImpl) AsyncSQLExecuteQuery(ctx context.Context, projectID *string, connectionID string, contextID string, sql string, resultID *string, filter *model.SQLDataFilter, dataFormat *model.ResultDataFormat, readLogs *bool) (*model.AsyncTaskInfo, error)
func (*MutationResolverImpl) AsyncSQLExecuteResults ¶
func (r *MutationResolverImpl) AsyncSQLExecuteResults(ctx context.Context, taskID string) (*model.SQLExecuteInfo, error)
func (*MutationResolverImpl) AuditSQL ¶
func (r *MutationResolverImpl) AuditSQL(ctx context.Context, sql string, connectionID string) (auditSuccess bool, result []AuditSQLResV2, err error)
AuditSQL todo: this is a provisional programme that will need to be adjusted at a later stage
type NavNodeChildrenResponse ¶
type NavNodeChildrenResponse struct {
NavNodeChildren []NavNodeInfo `json:"navNodeChildren"`
NavNodeInfo NavNodeInfo `json:"navNodeInfo"`
} `json:"data"`
}
NavNodeChildrenResponse 导航节点子节点响应
type QueryResolverImpl ¶
type QueryResolverImpl struct {
*resolver.QueryResolverImpl
Ctx echo.Context
Next Next
}
func (*QueryResolverImpl) ActiveUser ¶
type Request ¶
type Request struct {
// Header represent any request headers that will be set
// when the request is made.
Header http.Header
// contains filtered or unexported fields
}
Request is a GraphQL request.
func NewRequest ¶
NewRequest makes a new Request with the specified string.
func (*Request) File ¶
File sets a file to upload. Files are only supported with a Client that was created with the UseMultipartForm option.
func (*Request) SetOperationName ¶
SetOperationName set operation name 发往SQLE的请求如果指定了OperationName, 请求会被SQLE拦截并通过对应逻辑处理, 不添加OperationName的请求会被SQLE直接转发
type ResolverImpl ¶
type ResolverImpl struct {
*resolver.Resolver
Ctx echo.Context
Next Next
// SQLExecuteResultsHandlerFn 为对SQL结果集的处理方法,具体处理逻辑为业务行为,由外部biz层定义后传入
SQLExecuteResultsHandlerFn SQLExecuteResultsHandler
EnableResultsHandlerFn bool
}
func NewResolverImpl ¶
func NewResolverImpl(ctx echo.Context, next Next, SQLExecuteResultsHandlerFn SQLExecuteResultsHandler, enableResultsHandlerFn bool) *ResolverImpl
func (*ResolverImpl) Mutation ¶
func (r *ResolverImpl) Mutation() resolver.MutationResolver
func (*ResolverImpl) Query ¶
func (r *ResolverImpl) Query() resolver.QueryResolver
Query returns generated.QueryResolver implementation.
type SQLExecuteResultsHandler ¶
type SQLExecuteResultsHandler func(ctx context.Context, result *model.SQLExecuteInfo) error