MCPcopy Create free account
hub / github.com/OpenSN-Library/OpenSN-Library / webShellDaemonFunc

Function webShellDaemonFunc

daemon/pkg/module/webshell_module.go:69–121  ·  view source on GitHub ↗
(sigChan chan int, errChan chan error)

Source from the content-addressed store, hash-verified

67}
68
69func webShellDaemonFunc(sigChan chan int, errChan chan error) {
70
71 ctx, cancel := context.WithCancel(context.Background())
72 watchChan := utils.EtcdClient.Watch(
73 ctx,
74 key.NodeWebshellRequestKeySelf,
75 clientv3.WithPrefix(),
76 clientv3.WithPrevKV(),
77 )
78 for {
79
80 select {
81 case sig := <-sigChan:
82 if sig == signal.STOP_SIGNAL {
83 cancel()
84 return
85 }
86 case res := <-watchChan:
87 for _, v := range res.Events {
88 logrus.Infof("Webshell Event: %s", v.Kv.Key)
89 go func(v *clientv3.Event) {
90 oldWebshell := new(model.WebShellAllocRequest)
91 newWebshell := new(model.WebShellAllocRequest)
92 if v.PrevKv != nil && len(v.PrevKv.Value) > 0 {
93 err := json.Unmarshal(v.PrevKv.Value, &oldWebshell)
94 if err != nil {
95 errMsg := fmt.Sprintf("Parse Link Parameter Info From %s Error: %s", string(v.Kv.Key), err.Error())
96 logrus.Error(errMsg)
97 return
98 }
99 }
100
101 if v.Kv != nil && len(v.Kv.Value) > 0 {
102 err := json.Unmarshal(v.Kv.Value, &newWebshell)
103 if err != nil {
104 errMsg := fmt.Sprintf("Parse Link Parameter Info From %s Error: %s", string(v.Kv.Key), err.Error())
105 logrus.Error(errMsg)
106 return
107 }
108 }
109
110 err := UpdateWebShellState(newWebshell, oldWebshell)
111
112 if err != nil {
113 errMsg := fmt.Sprintf("Update Webshell State Error: %s", err.Error())
114 logrus.Error(errMsg)
115 }
116
117 }(v)
118 }
119 }
120 }
121}
122
123func CreateWebshellModule() *LinkParameterModule {
124 return &LinkParameterModule{

Callers

nothing calls this directly

Calls 1

UpdateWebShellStateFunction · 0.85

Tested by

no test coverage detected