-
Notifications
You must be signed in to change notification settings - Fork 9
/
session.go
53 lines (48 loc) · 1.48 KB
/
session.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package cloud66
import (
"fmt"
)
// Session indicates a container based service session
type Session struct {
UID string `json:"uid"`
Title string `json:"title"`
ServiceName string `json:"service_name"`
Command string `json:"command"`
Namespace string `json:"namespace"`
DeploymentName string `json:"deployment_name"`
PodName string `json:"pod_name"`
ContainerName string `json:"container_name"`
}
// StartRemoteSession starts a session via API
func (c *Client) StartRemoteSession(stackUID string, serviceName string) (*AsyncResult, error) {
params := struct {
ServiceName string `json:"service_name"`
}{
ServiceName: serviceName,
}
url := fmt.Sprintf("/stacks/%s/sessions.json", stackUID)
req, err := c.NewRequest("POST", url, params, nil)
if err != nil {
return nil, err
}
var asyncRes *AsyncResult
return asyncRes, c.DoReq(req, &asyncRes, nil)
}
// FetchRemoteSession fetches a session via API
func (c *Client) FetchRemoteSession(stackUID string, sessionUID, serviceName *string) (*Session, error) {
queryStrings := make(map[string]string)
queryStrings["page"] = "1"
if serviceName != nil {
queryStrings["service_name"] = *serviceName
}
if sessionUID != nil {
queryStrings["session_id"] = *sessionUID
}
url := fmt.Sprintf("/stacks/%s/sessions/fetch.json", stackUID)
req, err := c.NewRequest("GET", url, nil, queryStrings)
if err != nil {
return nil, err
}
var session *Session
return session, c.DoReq(req, &session, nil)
}