Skip to content

Commit de27422

Browse files
committed
reorganising types + added missing Read function
1 parent b1cbddc commit de27422

File tree

2 files changed

+10
-129
lines changed

2 files changed

+10
-129
lines changed

guac_connections.go

Lines changed: 8 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -2,83 +2,11 @@ package guacapi
22

33
import (
44
"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-
}
775

78-
return connresp, err
79-
}
6+
. "github.com/mdanidl/guac-api/types"
7+
)
808

81-
func (g *Guac) AddConnection(conn *GuacConnection) (GuacConnection, error) {
9+
func (g *Guac) CreateConnection(conn *GuacConnection) (GuacConnection, error) {
8210
ret := GuacConnection{}
8311
resp, err := g.Call("POST", "/api/session/data/mysql/connections", nil, conn)
8412
if err != nil {
@@ -97,47 +25,12 @@ func (g *Guac) DeleteConnection(conn *GuacConnection) error {
9725
return nil
9826
}
9927

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)
10431
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
11533
}
116-
34+
err = json.Unmarshal(resp, &ret)
11735
return ret, nil
11836
}
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-
}

sessiontoken.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"net/http"
99
"net/url"
1010
"strconv"
11+
12+
. "github.com/mdanidl/guac-api/types"
1113
)
1214

1315
type Guac struct {
@@ -16,20 +18,6 @@ type Guac struct {
1618
Password string
1719
Token string
1820
}
19-
type ConnectResponse struct {
20-
AuthToken string `json:"authToken"`
21-
Username string `json:"username"`
22-
Datasource string `json:"dataSource"`
23-
Availabledatasources []string `json:"availableDataSource"`
24-
}
25-
26-
type ErrorResponse struct {
27-
Message string `json:"message"`
28-
// TranslatableMessage []map[string]string `json:"translatableMessage"`
29-
StatusCode string `json:"statusCode"`
30-
Expected string `json:"expected"`
31-
Type string `json:"type"`
32-
}
3321

3422
func (g *Guac) Connect() error {
3523
resp, err := http.PostForm(g.URI+"/api/tokens",

0 commit comments

Comments
 (0)