summaryrefslogtreecommitdiffstats
path: root/lib/xdsserver/apiv1-targets.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2018-03-15 14:50:27 +0100
committerSebastien Douheret <sebastien.douheret@iot.bzh>2018-04-05 01:30:28 +0200
commit08095aa9a0d7b9b7636cdf36a5a5b6df2592bc05 (patch)
treea62f59e6b0116d31b7ad9ec85974129d9698765b /lib/xdsserver/apiv1-targets.go
parent17812a0a4388ab0c87084ef7e8118d87e8fadcf7 (diff)
Added Target and Terminal events through WS.
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'lib/xdsserver/apiv1-targets.go')
-rw-r--r--lib/xdsserver/apiv1-targets.go44
1 files changed, 34 insertions, 10 deletions
diff --git a/lib/xdsserver/apiv1-targets.go b/lib/xdsserver/apiv1-targets.go
index 978dc75..a7048eb 100644
--- a/lib/xdsserver/apiv1-targets.go
+++ b/lib/xdsserver/apiv1-targets.go
@@ -58,9 +58,16 @@ func (s *APIService) addTarget(c *gin.Context) {
return
}
+ // Retrieve session info
+ sess := s.sessions.Get(c)
+ if sess == nil {
+ common.APIError(c, "Unknown sessions")
+ return
+ }
+
s.Log.Debugln("Add target config: ", cfgArg)
- newTgt, err := s.targets.Add(cfgArg)
+ newTgt, err := s.targets.Add(cfgArg, sess)
if err != nil {
common.APIError(c, err.Error())
return
@@ -77,9 +84,16 @@ func (s *APIService) delTarget(c *gin.Context) {
return
}
+ // Retrieve session info
+ sess := s.sessions.Get(c)
+ if sess == nil {
+ common.APIError(c, "Unknown sessions")
+ return
+ }
+
s.Log.Debugln("Delete target id ", id)
- delEntry, err := s.targets.Delete(id)
+ delEntry, err := s.targets.Delete(id, sess)
if err != nil {
common.APIError(c, err.Error())
return
@@ -190,13 +204,8 @@ func (s *APIService) openTgtTerm(c *gin.Context) {
common.APIError(c, "Unknown sessions")
return
}
- sock := sess.IOSocket
- if sock == nil {
- common.APIError(c, "Websocket not established")
- return
- }
- term, err := s.targets.OpenTerminal(id, tid, sock, sess.ID)
+ term, err := s.targets.OpenTerminal(id, tid, sess)
if err != nil {
common.APIError(c, err.Error())
return
@@ -211,7 +220,15 @@ func (s *APIService) closeTgtTerm(c *gin.Context) {
common.APIError(c, err.Error())
return
}
- term, err := s.targets.CloseTerminal(id, tid)
+
+ // Retrieve session info
+ sess := s.sessions.Get(c)
+ if sess == nil {
+ common.APIError(c, "Unknown sessions")
+ return
+ }
+
+ term, err := s.targets.CloseTerminal(id, tid, sess)
if err != nil {
common.APIError(c, err.Error())
return
@@ -233,7 +250,14 @@ func (s *APIService) resizeTgtTerm(c *gin.Context) {
return
}
- term, err := s.targets.ResizeTerminal(id, tid, sizeArg.Cols, sizeArg.Rows)
+ // Retrieve session info
+ sess := s.sessions.Get(c)
+ if sess == nil {
+ common.APIError(c, "Unknown sessions")
+ return
+ }
+
+ term, err := s.targets.ResizeTerminal(id, tid, sizeArg.Cols, sizeArg.Rows, sess)
if err != nil {
common.APIError(c, err.Error())
return