Skip to content

Commit

Permalink
fix: add encodeurl on map entrie
Browse files Browse the repository at this point in the history
  • Loading branch information
matthisholleville committed Feb 25, 2022
1 parent edddf00 commit 10a3d1f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions internal/haproxy/maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func (c *Client) GetMapEntrie(entrieName string, mapName string) (*models.MapEntrie, error) {
url := c.base_url + "/services/haproxy/runtime/maps_entries/" + replaceSlashInString(entrieName) + "?map=" + mapName
url := c.base_url + "/services/haproxy/runtime/maps_entries/" + encodeUrl(entrieName) + "?map=" + mapName
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
Expand Down Expand Up @@ -43,7 +43,7 @@ func (c *Client) CreateMapEntrie(entrie *models.MapEntrie, mapName string, force
}

func (c *Client) UpdateMapEntrie(entrie *models.MapEntrie, mapName string, forceSync bool) (*models.MapEntrie, error) {
url := c.base_url + "/services/haproxy/runtime/maps_entries/" + replaceSlashInString(entrie.Key) + "?map=" + mapName + "&force_sync=" + strconv.FormatBool(forceSync)
url := c.base_url + "/services/haproxy/runtime/maps_entries/" + encodeUrl(entrie.Key) + "?map=" + mapName + "&force_sync=" + strconv.FormatBool(forceSync)
entrieValue := &models.MapEntrie{
Value: entrie.Value,
}
Expand All @@ -64,7 +64,7 @@ func (c *Client) UpdateMapEntrie(entrie *models.MapEntrie, mapName string, force
}

func (c *Client) DeleteMapEntrie(entrieName string, mapName string, forceSync bool) error {
url := c.base_url + "/services/haproxy/runtime/maps_entries/" + replaceSlashInString(entrieName) + "?map=" + mapName + "&force_sync=" + strconv.FormatBool(forceSync)
url := c.base_url + "/services/haproxy/runtime/maps_entries/" + encodeUrl(entrieName) + "?map=" + mapName + "&force_sync=" + strconv.FormatBool(forceSync)
req, err := http.NewRequest("DELETE", url, nil)
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions internal/haproxy/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ package haproxy

import (
"encoding/base64"
"net/url"
"regexp"
"strings"
)

func basicAuth(username, password string) string {
auth := username + ":" + password
return base64.StdEncoding.EncodeToString([]byte(auth))
}

func replaceSlashInString(value string) string {
return strings.Replace(value, "/", "%2F", -1)
func encodeUrl(s string) string {
return url.QueryEscape(s)
}

func ExtractStringWithRegex(value string, regex string) string {
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resource_maps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestResourceMaps(t *testing.T) {
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testAccMapEntrie("test", "/metrics", "50", "test"),
Config: testAccMapEntrie("test", "https://preprod-tmp-gestion-sans-compta.agicap.cloud|identity-gestion-sans-compta", "enable", "test"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("haproxy_maps.test", "map", "test"),
),
Expand Down

0 comments on commit 10a3d1f

Please sign in to comment.