diff --git a/server/go.mod b/server/go.mod index b1c91e87fbbdcb33a62ac6df67b1fcdd79e7afba..75f65f67c1bcb201505fa51170e0951d1c72f687 100644 --- a/server/go.mod +++ b/server/go.mod @@ -3,7 +3,7 @@ module openeuler.org/PilotGo/atune-plugin go 1.18 require ( - gitee.com/openeuler/PilotGo/sdk v0.0.0-20240119073421-18be29f9d1eb + gitee.com/openeuler/PilotGo/sdk v0.0.0-20240312015409-d8d39b77d9ca github.com/gin-gonic/gin v1.9.1 gopkg.in/yaml.v2 v2.4.0 gorm.io/driver/mysql v1.5.1 diff --git a/server/go.sum b/server/go.sum index b6c42636abbb06e679dccaf2278c94b61613d2ef..7736895fe8b2dd6ec6a49088fcbda17d373732d4 100644 --- a/server/go.sum +++ b/server/go.sum @@ -2,6 +2,10 @@ gitee.com/openeuler/PilotGo/sdk v0.0.0-20240119031301-10921c4f0434 h1:owh3m67r7E gitee.com/openeuler/PilotGo/sdk v0.0.0-20240119031301-10921c4f0434/go.mod h1:zEVmY3l48/CvR2kIM3DJpD/jWTG1qkOxRoHJii/D0us= gitee.com/openeuler/PilotGo/sdk v0.0.0-20240119073421-18be29f9d1eb h1:eacdBijlrmerXMnAoWFGMrHeqqouS2do6o/97GtfuM0= gitee.com/openeuler/PilotGo/sdk v0.0.0-20240119073421-18be29f9d1eb/go.mod h1:zEVmY3l48/CvR2kIM3DJpD/jWTG1qkOxRoHJii/D0us= +gitee.com/openeuler/PilotGo/sdk v0.0.0-20240308065731-d286881c19cc h1:MoX1+uSPJRZ2YHxyCL+I7ZgmodmKTadITZI8ZcxJcGI= +gitee.com/openeuler/PilotGo/sdk v0.0.0-20240308065731-d286881c19cc/go.mod h1:zEVmY3l48/CvR2kIM3DJpD/jWTG1qkOxRoHJii/D0us= +gitee.com/openeuler/PilotGo/sdk v0.0.0-20240312015409-d8d39b77d9ca h1:7jD/c+W4Y/biAJgAEKfcsUk3vlTbzCPjcaFl7y3hms0= +gitee.com/openeuler/PilotGo/sdk v0.0.0-20240312015409-d8d39b77d9ca/go.mod h1:zEVmY3l48/CvR2kIM3DJpD/jWTG1qkOxRoHJii/D0us= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/common/machine.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/common/machine.go index 23241fbd83a4f75c24becd8cdb6054cf809e4212..2a8f7d0a6e2b18f51882ccefaa6471530d2d406a 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/common/machine.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/common/machine.go @@ -18,7 +18,19 @@ type BatchList struct { } type Batch struct { - BatchId int `json:"batch_id"` - DepartmentIDs []string `json:"department_ids"` + BatchIds []int `json:"batch_ids"` + DepartmentIDs []int `json:"department_ids"` MachineUUIDs []string `json:"machine_uuids"` } + +type File struct { + Path string `json:"path"` + Name string `json:"name"` + Content string `json:"content"` +} + +type NodeResult struct { + UUID string + Error string + Data interface{} +} diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/logger/logger.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/logger/logger.go index 32cc99bcb895cb2bf7a13cf18539910990e6803d..6854d6fe42a98f93f49eaa54fb851968af88a8a2 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/logger/logger.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/logger/logger.go @@ -112,6 +112,10 @@ func Error(format string, args ...interface{}) { logrus.Errorf(format, args...) } +func ErrorStack(msg string, err error) { + logrus.Errorf(msg+"\n%+v", err) +} + func Fatal(format string, args ...interface{}) { logrus.Fatalf(format, args...) } @@ -143,7 +147,7 @@ func RequestLogger() gin.HandlerFunc { clientIP := c.ClientIP() // 日志格式 - if reqUri != "/api/v1/pluginapi/heartbeat" { + if reqUri != "/api/v1/pluginapi/heartbeat" && reqUri != "/plugin/prometheus/target" { Debug("status_code:%d latency_time:%s client_ip:%s req_method:%s req_uri:%s", statusCode, latencyTime, diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/batch.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/batch.go index 9057d48ef7109953012382471ea896ae9753e5e8..088761aab7d49d209415d1e3db0e7036f718de7f 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/batch.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/batch.go @@ -13,7 +13,11 @@ func (c *Client) BatchList() ([]*common.BatchList, error) { return nil, errors.New("unbind PilotGo-server platform") } url := "http://" + c.Server() + "/api/v1/pluginapi/batch_list" - r, err := httputils.Get(url, nil) + r, err := httputils.Get(url, &httputils.Params{ + Cookie: map[string]string{ + TokenCookie: c.token, + }, + }) if err != nil { return nil, err } @@ -33,7 +37,11 @@ func (c *Client) BatchUUIDList(batchId string) ([]string, error) { return nil, errors.New("unbind PilotGo-server platform") } url := "http://" + c.Server() + "/api/v1/pluginapi/batch_uuid?batchId=" + batchId - r, err := httputils.Get(url, nil) + r, err := httputils.Get(url, &httputils.Params{ + Cookie: map[string]string{ + TokenCookie: c.token, + }, + }) if err != nil { return nil, err } diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/client.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/client.go index ef1d239c65d05dc7de3bdedc6459f83a591e47ff..5c936d4b5b96aa864406e05dee319dbf92ea300b 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/client.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/client.go @@ -7,6 +7,8 @@ import ( "github.com/gin-gonic/gin" ) +const TokenCookie = "PluginToken" + type GetTagsCallback func([]string) []common.Tag type Client struct { @@ -17,6 +19,9 @@ type Client struct { // 远程PilotGo server地址 server string + // 鉴权token + token string + // 用于event消息处理 eventChan chan *common.EventMessage eventCallbackMap map[int]EventCallback diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/config.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/config.go index a23122edad4c3c2d276450ee1ec76d5caf62dd65..643bb9bac0c527c14200e24d6919daf89417bbc9 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/config.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/config.go @@ -13,7 +13,11 @@ func (c *Client) ApplyConfig(batch *common.Batch, path, content string) error { return errors.New("unbind PilotGo-server platform") } url := c.Server() + "/api/v1/pluginapi/apply_config" - r, err := httputils.Put(url, nil) + r, err := httputils.Put(url, &httputils.Params{ + Cookie: map[string]string{ + TokenCookie: c.token, + }, + }) if err != nil { return err } diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/event.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/event.go index 4ec5f1b73fb3fbccd27662547302449161743400..8d76833b10b5aff0da075e92c16bb5f7edb2198b 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/event.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/event.go @@ -23,6 +23,9 @@ func (c *Client) ListenEvent(eventTypes []int, callbacks []EventCallback) error url := c.Server() + "/api/v1/pluginapi/listener?eventTypes=" + strings.Join(eventtypes, ",") r, err := httputils.Put(url, &httputils.Params{ Body: c.PluginInfo, + Cookie: map[string]string{ + TokenCookie: c.token, + }, }) if err != nil { return err @@ -62,6 +65,9 @@ func (c *Client) UnListenEvent(eventTypes []int) error { url := c.Server() + "/api/v1/pluginapi/listener?eventTypes=" + strings.Join(eventtypes, ",") r, err := httputils.Delete(url, &httputils.Params{ Body: c.PluginInfo, + Cookie: map[string]string{ + TokenCookie: c.token, + }, }) if err != nil { return err @@ -97,6 +103,9 @@ func (c *Client) PublishEvent(msg common.EventMessage) error { url := c.Server() + "/api/v1/pluginapi/publish_event" r, err := httputils.Put(url, &httputils.Params{ Body: &msg, + Cookie: map[string]string{ + TokenCookie: c.token, + }, }) if err != nil { return err diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/handler.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/handler.go index 65d977888df4a6ca37d9dd9f4459f3d79e00a9fc..b8c9def763e9a5dbcd95c5ff326f86c0ec615859 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/handler.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/handler.go @@ -74,6 +74,13 @@ func bindHandler(c *gin.Context) { logger.Error("已有PilotGo-server与此插件绑定") } client.cond.Broadcast() + + for _, c := range c.Request.Cookies() { + if c.Name == TokenCookie { + client.token = c.Value + } + } + client.sendHeartBeat() response.Success(c, nil, "bind server success") } diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/heartbeat.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/heartbeat.go index b0e16977a8017cc6617767819fc22648306fbe7b..fa1fb9ce81f7a12f5afdea91406b783284d6bf1b 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/heartbeat.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/heartbeat.go @@ -44,6 +44,9 @@ func (client *Client) sendHeartbeat(clientID string) error { ServerUrl := "http://" + client.Server() + "/api/v1/pluginapi/heartbeat" resp, err := httputils.Post(ServerUrl, &httputils.Params{ Body: p, + Cookie: map[string]string{ + TokenCookie: client.token, + }, }) if err != nil { return err diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/machine.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/machine.go index b28129a11ac23160ea6f3b6ab6658fbf1bcae22b..94043cfcfc3e9b22a4954c01c263ae6167738d9f 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/machine.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/machine.go @@ -13,7 +13,11 @@ func (c *Client) MachineList() ([]*common.MachineNode, error) { return nil, errors.New("unbind PilotGo-server platform") } url := "http://" + c.Server() + "/api/v1/pluginapi/machine_list" - r, err := httputils.Get(url, nil) + r, err := httputils.Get(url, &httputils.Params{ + Cookie: map[string]string{ + TokenCookie: c.token, + }, + }) if err != nil { return nil, err } @@ -33,7 +37,11 @@ func (c *Client) MachineInfoByUUID(machine_uuid string) (*common.MachineNode, er return nil, errors.New("unbind PilotGo-server platform") } url := "http://" + c.Server() + "/api/v1/pluginapi/machine_info?machine_uuid=" + machine_uuid - r, err := httputils.Get(url, nil) + r, err := httputils.Get(url, &httputils.Params{ + Cookie: map[string]string{ + TokenCookie: c.token, + }, + }) if err != nil { return nil, err } diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/permission.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/permission.go index 2e208bb9c7576b4e5cf5d0ac278571cd961ff5fe..155b66e6463ee8c8320fbe6342d61456d45b937b 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/permission.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/permission.go @@ -34,6 +34,9 @@ func (c *Client) HasPermission(resource, operate string) (bool, error) { r, err := httputils.Post(url, &httputils.Params{ Body: p, + Cookie: map[string]string{ + TokenCookie: c.token, + }, }) if err != nil { return false, err diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/plugin.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/plugin.go index fcde30184f5fd7d499d176bf20860f2ed93d29bf..e878f3323da4e8e8bdf0a22eb2aae84eb7b5e6bf 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/plugin.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/plugin.go @@ -32,7 +32,11 @@ func (c *Client) GetPluginInfo(name string) (*PluginInfo, error) { return nil, errors.New("unbind PilotGo-server platform") } url := c.Server() + "/api/v1/pluginapi/plugins" - r, err := httputils.Get(url, nil) + r, err := httputils.Get(url, &httputils.Params{ + Cookie: map[string]string{ + TokenCookie: c.token, + }, + }) if err != nil { return nil, err } diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/script.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/script.go index 5809e5c07ad6e08f1819690ee8057808a992b9b7..2d28745e89f5bd2860e71201ec48976062f9d4b1 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/script.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/script.go @@ -30,6 +30,9 @@ func (c *Client) RunCommand(batch *common.Batch, cmd string) ([]*common.CmdResul r, err := httputils.Post(url, &httputils.Params{ Body: p, + Cookie: map[string]string{ + TokenCookie: c.token, + }, }) if err != nil { return nil, err @@ -67,6 +70,9 @@ func (c *Client) RunScript(batch *common.Batch, script string, params []string) r, err := httputils.Post(url, &httputils.Params{ Body: p, + Cookie: map[string]string{ + TokenCookie: c.token, + }, }) if err != nil { return nil, err @@ -97,6 +103,9 @@ func (c *Client) RunCommandAsync(batch *common.Batch, cmd string, callback RunCo r, err := httputils.Post(url, &httputils.Params{ Body: p, + Cookie: map[string]string{ + TokenCookie: c.token, + }, }) if err != nil { return err diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/service.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/service.go index 8790c9a96715a5e43606be4f24ee1c591d1f15f3..29597123325bcb098ffe8740891162296ecea300 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/service.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/service.go @@ -21,6 +21,9 @@ func (c *Client) ServiceStatus(batch *common.Batch, servicename string) ([]*comm r, err := httputils.Put(url, &httputils.Params{ Body: p, + Cookie: map[string]string{ + TokenCookie: c.token, + }, }) if err != nil { return nil, err @@ -47,6 +50,9 @@ func (c *Client) StartService(batch *common.Batch, serviceName string) ([]*commo r, err := httputils.Put(url, &httputils.Params{ Body: p, + Cookie: map[string]string{ + TokenCookie: c.token, + }, }) if err != nil { return nil, err @@ -73,6 +79,9 @@ func (c *Client) StopService(batch *common.Batch, serviceName string) ([]*common r, err := httputils.Put(url, &httputils.Params{ Body: p, + Cookie: map[string]string{ + TokenCookie: c.token, + }, }) if err != nil { return nil, err diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/utils/httputils/request.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/utils/httputils/request.go index 3c371e3f18b4a94345498293a0e8936c7e2caf5b..2cca0c24b28bc71797359825b1bff8f8e943d697 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/utils/httputils/request.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/utils/httputils/request.go @@ -54,6 +54,16 @@ func request(method, url string, param *Params) (*Response, error) { } } } + + // 处理token + if len(param.Cookie) > 0 { + for k, v := range param.Cookie { + req.AddCookie(&http.Cookie{ + Name: k, + Value: v, + }) + } + } } hc := &http.Client{Transport: &http.Transport{ @@ -88,6 +98,8 @@ type Params struct { Form map[string]string // Body 参数会被序列化成json字符串 Body interface{} + // Cookit 参数会被添加到请求cookie当中 + Cookie map[string]string } type Response struct { diff --git a/server/vendor/modules.txt b/server/vendor/modules.txt index 60d056de3004a98d3eff51b5428c6faea0c8a384..4846c71b433253db5c695361204c4d74100a0cf3 100644 --- a/server/vendor/modules.txt +++ b/server/vendor/modules.txt @@ -1,4 +1,4 @@ -# gitee.com/openeuler/PilotGo/sdk v0.0.0-20240119073421-18be29f9d1eb +# gitee.com/openeuler/PilotGo/sdk v0.0.0-20240312015409-d8d39b77d9ca ## explicit; go 1.17 gitee.com/openeuler/PilotGo/sdk/common gitee.com/openeuler/PilotGo/sdk/logger