apm_get_code_setting.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package containers
  2. import (
  3. "fmt"
  4. "github.com/coroot/coroot-node-agent/utils"
  5. . "github.com/coroot/coroot-node-agent/utils/modelse"
  6. klog "github.com/sirupsen/logrus"
  7. )
  8. func (c *Container) GetCodeSetting(r *Registry) (CodeSettingResp, error) {
  9. nodeInfo := r.nodeInfo.GetNodeInfo()
  10. if nodeInfo == nil {
  11. return CodeSettingResp{}, fmt.Errorf("[GetCodeSetting] Unknown node info.")
  12. }
  13. req := CodeSettingReq{
  14. AccountId: nodeInfo.AccountID,
  15. HostId: nodeInfo.HostID,
  16. Appid: c.AppInfo.AppIdHash.IntVal,
  17. AgentId: c.AppInfo.AgentId,
  18. }
  19. //klog.Infof("[GetCodeSetting] req: %s.", utils.ToString(req))
  20. resp, err := r.connServer.GetCodeSetting(req)
  21. if err != nil {
  22. klog.WithError(err).Errorf("[GetCodeSetting] Failed GetCodeSetting %s.", utils.ToString(req))
  23. return resp, err
  24. }
  25. //fmt.Println(resp)
  26. //c.saveWhiteStackSettingInfo(resp)
  27. return resp, err
  28. }
  29. func (c *Container) saveWhiteStackSettingInfo(resp CodeSettingResp) {
  30. c.WhiteSettingInfo.WhiteStackSettingInfo.WhiteList = resp.BlackWhiteSettings.WhiteList
  31. c.WhiteSettingInfo.WhiteStackSettingInfo.BlackList = resp.BlackWhiteSettings.BlackList
  32. c.WhiteSettingInfo.WhiteStackSettingInfo.OpenStack = resp.BlackWhiteSettings.CollectStack
  33. }
  34. func (c *Container) stackRuleUpdate(resp CodeSettingResp) bool {
  35. if c.noOrigRule() {
  36. return false
  37. }
  38. return resp.BlackWhiteSettings.WhiteList != c.WhiteSettingInfo.WhiteStackSettingInfo.WhiteList ||
  39. resp.BlackWhiteSettings.BlackList != c.WhiteSettingInfo.WhiteStackSettingInfo.BlackList
  40. }
  41. func (c *Container) noStackRule(resp CodeSettingResp) bool {
  42. return resp.BlackWhiteSettings.WhiteList == "" && resp.BlackWhiteSettings.BlackList == ""
  43. }
  44. func (c *Container) hasStackRule(resp CodeSettingResp) bool {
  45. return resp.BlackWhiteSettings.WhiteList != "" || resp.BlackWhiteSettings.BlackList != ""
  46. }
  47. func (c *Container) noOrigRule() bool {
  48. return c.WhiteSettingInfo.WhiteStackSettingInfo.WhiteList == "" && c.WhiteSettingInfo.WhiteStackSettingInfo.BlackList == ""
  49. }