cloudbeaver

package
v0.0.0-...-6dce122 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 31, 2025 License: MPL-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UsernamePrefix             = "dms-"
	SQLEDirectAudit ContextKey = "sqle_direct_audit"
	SQLEProxyName              = _const.SqleComponentName
)
View Source
const AuditResultKey = "audit_result"
View Source
const GraphQLConfigVersionQuery = `
query serverConfig {
  serverConfig {
    version
  }
}`

Variables

View Source
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
	}
)
View Source
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

func GenerateCloudbeaverUserId

func GenerateCloudbeaverUserId(name string) string

func RemoveCloudbeaverUserIdPrefix

func RemoveCloudbeaverUserIdPrefix(name string) string

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 AuditSQLResV2 struct {
	Number      uint                 `json:"number"`
	ExecSQL     string               `json:"exec_sql"`
	AuditResult dbmodel.AuditResults `json:"audit_result"`
	AuditLevel  string               `json:"audit_level"`
	SQLType     string               `json:"sql_type"`
}

type CBVersion

type CBVersion struct {
	// contains filtered or unexported fields
}

CloudBeaver 版本号格式一般为 X.X.X.X 格式,例如 '22.3.1.202212261505' , 其中前三位为版本号

func NewCBVersion

func NewCBVersion(versionStr string) (CBVersion, error)

func (CBVersion) LessThan

func (v CBVersion) LessThan(version CBVersion) bool

只比较前三位, 因为只有前三位与版本有关

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.

func (*Client) Run

func (c *Client) Run(ctx context.Context, req *Request, resp interface{}) error

Run executes the query and unmarshals the response from the data field into the response object. Pass in a nil response object to skip response parsing. If the request fails or the server returns an error, the first error will be returned.

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 File

type File struct {
	Field string
	Name  string
	R     io.Reader
}

File represents a file to upload.

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 struct {
	Data struct {
		NavNodeChildren []NavNodeInfo `json:"navNodeChildren"`
		NavNodeInfo     NavNodeInfo   `json:"navNodeInfo"`
	} `json:"data"`
}

NavNodeChildrenResponse 导航节点子节点响应

type NavNodeInfo struct {
	ID          string         `json:"id"`
	Name        string         `json:"name"`
	PlainName   *string        `json:"plainName"`
	HasChildren bool           `json:"hasChildren"`
	NodeType    string         `json:"nodeType"`
	Icon        string         `json:"icon"`
	Folder      bool           `json:"folder"`
	Inline      bool           `json:"inline"`
	Navigable   bool           `json:"navigable"`
	Filtered    bool           `json:"filtered"`
	Features    []string       `json:"features"`
	ProjectID   string         `json:"projectId"`
	Object      *NavNodeObject `json:"object"`
}

NavNodeInfo 导航节点信息

type NavNodeObject struct {
	Features []string `json:"features"`
}

NavNodeObject 导航节点对象信息

type Next

type Next func(c echo.Context) ([]byte, error)

type QueryResolverImpl

type QueryResolverImpl struct {
	*resolver.QueryResolverImpl
	Ctx  echo.Context
	Next Next
}

func (*QueryResolverImpl) ActiveUser

func (r *QueryResolverImpl) ActiveUser(ctx context.Context) (*model.UserInfo, error)

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

func NewRequest(q string, variables map[string]interface{}) *Request

NewRequest makes a new Request with the specified string.

func (*Request) File

func (req *Request) File(fieldname, filename string, r io.Reader)

File sets a file to upload. Files are only supported with a Client that was created with the UseMultipartForm option.

func (*Request) Files

func (req *Request) Files() []File

Files gets the files in this request.

func (*Request) Query

func (req *Request) Query() string

Query gets the query string of this request.

func (*Request) SetOperationName

func (req *Request) SetOperationName(operationName string)

SetOperationName set operation name 发往SQLE的请求如果指定了OperationName, 请求会被SQLE拦截并通过对应逻辑处理, 不添加OperationName的请求会被SQLE直接转发

func (*Request) Var

func (req *Request) Var(key string, value interface{})

Var sets a variable.

func (*Request) Vars

func (req *Request) Vars() map[string]interface{}

Vars gets the variables for this Request.

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL