Skip to content

Commit

Permalink
adding url escapes
Browse files Browse the repository at this point in the history
  • Loading branch information
techBeck03 committed May 27, 2021
1 parent 7adfe07 commit d238874
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
11 changes: 7 additions & 4 deletions connection_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package guacamole
import (
"fmt"
"net/http"
"net/url"
"strings"

"github.com/techBeck03/guacamole-api-client/types"
Expand Down Expand Up @@ -74,8 +75,10 @@ func (c *Client) CreateConnectionGroup(group *types.GuacConnectionGroup) error {
// ReadConnectionGroup gets a connection group by identifier
func (c *Client) ReadConnectionGroup(identifier string) (types.GuacConnectionGroup, error) {
var ret types.GuacConnectionGroup

request, err := c.CreateJSONRequest(http.MethodGet, fmt.Sprintf("%s/%s/%s", c.baseURL, connectionGroupsBasePath, identifier), nil)
request, err := c.CreateJSONRequest(http.MethodGet, fmt.Sprintf("%s/%s/%s", c.baseURL, connectionGroupsBasePath, url.QueryEscape(identifier)), nil)
if err != nil {
return ret, err
}
err = c.Call(request, &ret)
if err != nil {
return ret, err
Expand Down Expand Up @@ -149,7 +152,7 @@ func (c *Client) ReadConnectionGroupByPath(path string) (types.GuacConnectionGro

// UpdateConnectionGroup updates a connection group by identifier
func (c *Client) UpdateConnectionGroup(group *types.GuacConnectionGroup) error {
request, err := c.CreateJSONRequest(http.MethodPut, fmt.Sprintf("%s/%s/%s", c.baseURL, connectionGroupsBasePath, group.Identifier), group)
request, err := c.CreateJSONRequest(http.MethodPut, fmt.Sprintf("%s/%s/%s", c.baseURL, connectionGroupsBasePath, url.QueryEscape(group.Identifier)), group)

if err != nil {
return err
Expand All @@ -164,7 +167,7 @@ func (c *Client) UpdateConnectionGroup(group *types.GuacConnectionGroup) error {

// DeleteConnectionGroup deletes a connection group by identifier
func (c *Client) DeleteConnectionGroup(identifier string) error {
request, err := c.CreateJSONRequest(http.MethodDelete, fmt.Sprintf("%s/%s/%s", c.baseURL, connectionGroupsBasePath, identifier), nil)
request, err := c.CreateJSONRequest(http.MethodDelete, fmt.Sprintf("%s/%s/%s", c.baseURL, connectionGroupsBasePath, url.QueryEscape(identifier)), nil)

if err != nil {
return err
Expand Down
7 changes: 4 additions & 3 deletions connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package guacamole
import (
"fmt"
"net/http"
"net/url"
"strings"

"github.com/techBeck03/guacamole-api-client/types"
Expand Down Expand Up @@ -33,7 +34,7 @@ func (c *Client) ReadConnection(identifier string) (types.GuacConnection, error)
var retParams types.GuacConnectionParameters

// Get connection base details
request, err := c.CreateJSONRequest(http.MethodGet, fmt.Sprintf("%s/%s/%s", c.baseURL, connectionsBasePath, identifier), nil)
request, err := c.CreateJSONRequest(http.MethodGet, fmt.Sprintf("%s/%s/%s", c.baseURL, connectionsBasePath, url.QueryEscape(identifier)), nil)

if err != nil {
return ret, err
Expand Down Expand Up @@ -115,7 +116,7 @@ func (c *Client) ReadConnectionByPath(path string) (types.GuacConnection, error)

// UpdateConnection updates a connection by identifier
func (c *Client) UpdateConnection(connection *types.GuacConnection) error {
request, err := c.CreateJSONRequest(http.MethodPut, fmt.Sprintf("%s/%s/%s", c.baseURL, connectionsBasePath, connection.Identifier), connection)
request, err := c.CreateJSONRequest(http.MethodPut, fmt.Sprintf("%s/%s/%s", c.baseURL, connectionsBasePath, url.QueryEscape(connection.Identifier)), connection)

if err != nil {
return err
Expand All @@ -130,7 +131,7 @@ func (c *Client) UpdateConnection(connection *types.GuacConnection) error {

// DeleteConnection deletes a connection by identifier
func (c *Client) DeleteConnection(identifier string) error {
request, err := c.CreateJSONRequest(http.MethodDelete, fmt.Sprintf("%s/%s/%s", c.baseURL, connectionsBasePath, identifier), nil)
request, err := c.CreateJSONRequest(http.MethodDelete, fmt.Sprintf("%s/%s/%s", c.baseURL, connectionsBasePath, url.QueryEscape(identifier)), nil)

if err != nil {
return err
Expand Down

0 comments on commit d238874

Please sign in to comment.