diff --git a/internal/haproxy/maps.go b/internal/haproxy/maps.go index 0a86502..f3a4e17 100644 --- a/internal/haproxy/maps.go +++ b/internal/haproxy/maps.go @@ -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 @@ -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, } @@ -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 diff --git a/internal/haproxy/utils.go b/internal/haproxy/utils.go index 2c773b9..cb0b20c 100644 --- a/internal/haproxy/utils.go +++ b/internal/haproxy/utils.go @@ -2,8 +2,8 @@ package haproxy import ( "encoding/base64" + "net/url" "regexp" - "strings" ) func basicAuth(username, password string) string { @@ -11,8 +11,8 @@ func basicAuth(username, password string) string { 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 { diff --git a/internal/provider/resource_maps_test.go b/internal/provider/resource_maps_test.go index ec395d4..af1f696 100644 --- a/internal/provider/resource_maps_test.go +++ b/internal/provider/resource_maps_test.go @@ -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"), ),