@@ -2,83 +2,11 @@ package guacapi
2
2
3
3
import (
4
4
"encoding/json"
5
- )
6
-
7
- type RootGuacConnection struct {
8
- Name string `json:"name"`
9
- Identifier string `json:"identifier"`
10
- Type string `json:"type"`
11
- ActiveConnections int `json:"activeConnections"`
12
- ChildConnections []GuacConnection `json:"childConnections"`
13
- ChildGroups []GuacConnectionGroups `json:"childConnectionGroups"`
14
- Attributes GuacConnectionGroupAttributes `json:"attributes"`
15
- }
16
- type GuacConnectionGroups struct {
17
- Name string `json:"name"`
18
- Identifier string `json:"identifier"`
19
- ParentIdentifier string `json:"parentIdentifier"`
20
- Type string `json:"type"`
21
- ActiveConnections int `json:"activeConnections"`
22
- ChildConnections []GuacConnection `json:"childConnections"`
23
- ChildGroups []GuacConnectionGroups `json:"childConnectionGroups"`
24
- Attributes GuacConnectionGroupAttributes `json:"attributes"`
25
- }
26
- type GuacConnection struct {
27
- Name string `json:"name"`
28
- Identifier string `json:"identifier,omitempty"`
29
- ParentIdentifier string `json:"parentIdentifier"`
30
- Protocol string `json:"protocol"`
31
- Attributes GuacConnectionAttributes `json:"attributes"`
32
- Properties GuacConnectionParameters `json:"parameters"`
33
- ActiveConnections int `json:"activeConnections,omitempty"`
34
- }
35
- type GuacConnectionGroupAttributes struct {
36
- MaxConnections string `json:"max-connections"`
37
- MaxConnectionsPerUser string `json:"max-connections-per-user"`
38
- EnableSessionAffinity string `json:"enable-session-affinity"`
39
- }
40
-
41
- type GuacConnectionAttributes struct {
42
- GuacdEncryption string `json:"guacd-encryption"`
43
- FailoverOnly string `json:"failover-only"`
44
- Weight string `json:"weight"`
45
- MaxConnections string `json:"max-connections"`
46
- GuacdHostname string `json:"guacd-hostname,omitempty"`
47
- GuacdPort string `json:"guacd-port"`
48
- MaxConnectionsPerUser string `json:"max-connections-per-user"`
49
- }
50
- type GuacConnectionParameters struct {
51
- Port string `json:"port"`
52
- ReadOnly string `json:"read-only"`
53
- SwapRedBlue string `json:"swap-red-blue"`
54
- Cursor string `json:"cursor"`
55
- ColorDepth string `json:"color-depth"`
56
- ClipboardEncoding string `json:"clipboard-encoding"`
57
- RecordingExcludeOutput string `json:"recording-exclude-output"`
58
- RecordingExcludeMouse string `json:"recording-exclude-mouse"`
59
- RecordingIncludeKeys string `json:"recording-include-keys"`
60
- CreateRecordingPath string `json:"create-recording-path"`
61
- DestPort string `json:"dest-port"`
62
- EnableSftp string `json:"enable-sftp"`
63
- SftpPort string `json:"sftp-port"`
64
- SftpServerAliveInterval string `json:"sftp-server-alive-interval"`
65
- EnableAudio string `json:"enable-audio"`
66
- }
67
-
68
- func (g * Guac ) GetAllConnections () (RootGuacConnection , error ) {
69
- body , err := g .Call ("GET" , "/api/session/data/mysql/connectionGroups/ROOT/tree" , nil , nil )
70
-
71
- var connresp RootGuacConnection
72
-
73
- err = json .Unmarshal (body , & connresp )
74
- if err != nil {
75
- return RootGuacConnection {}, err
76
- }
77
5
78
- return connresp , err
79
- }
6
+ . "github.com/mdanidl/guac-api/types"
7
+ )
80
8
81
- func (g * Guac ) AddConnection (conn * GuacConnection ) (GuacConnection , error ) {
9
+ func (g * Guac ) CreateConnection (conn * GuacConnection ) (GuacConnection , error ) {
82
10
ret := GuacConnection {}
83
11
resp , err := g .Call ("POST" , "/api/session/data/mysql/connections" , nil , conn )
84
12
if err != nil {
@@ -97,47 +25,12 @@ func (g *Guac) DeleteConnection(conn *GuacConnection) error {
97
25
return nil
98
26
}
99
27
100
- // TODO
101
- func (g * Guac ) GetAllConnectionsFlat () ([]GuacConnection , error ) {
102
- ret := []GuacConnection {}
103
- conn_tree , err := g .GetAllConnections ()
28
+ func (g * Guac ) ReadConnection (conn * GuacConnection ) (GuacConnection , error ) {
29
+ ret := GuacConnection {}
30
+ resp , err := g .Call ("GET" , "/api/session/data/mysql/connections/" + conn .Identifier , nil , nil )
104
31
if err != nil {
105
- return []GuacConnection {}, err
106
- }
107
-
108
- for _ , root_conns := range conn_tree .ChildConnections {
109
- ret = append (ret , root_conns )
110
- }
111
-
112
- flat_conns_from_groups , err := flatten (conn_tree .ChildGroups )
113
- for _ , conns_from_grps := range flat_conns_from_groups {
114
- ret = append (ret , conns_from_grps )
32
+ return GuacConnection {}, err
115
33
}
116
-
34
+ err = json . Unmarshal ( resp , & ret )
117
35
return ret , nil
118
36
}
119
-
120
- func flatten (nested []GuacConnectionGroups ) ([]GuacConnection , error ) {
121
- flat_conns := []GuacConnection {}
122
- for _ , groups := range nested {
123
- if len (groups .ChildGroups ) > 0 {
124
- conns , err := flatten (groups .ChildGroups )
125
- if err != nil {
126
- return []GuacConnection {}, err
127
- }
128
- for _ , c := range conns {
129
- flat_conns = append (flat_conns , c )
130
- }
131
- }
132
- if len (groups .ChildConnections ) > 0 {
133
- for _ , c := range groups .ChildConnections {
134
- flat_conns = append (flat_conns , c )
135
- }
136
- }
137
- }
138
- return flat_conns , nil
139
- }
140
-
141
- func (g * Guac ) GetConnection (conn GuacConnection ) (GuacConnection , error ) {
142
- return GuacConnection {}, nil
143
- }
0 commit comments