diff --git a/pulsaradmin/pkg/admin/admin.go b/pulsaradmin/pkg/admin/admin.go index a22b22c62d..0b1b96254e 100644 --- a/pulsaradmin/pkg/admin/admin.go +++ b/pulsaradmin/pkg/admin/admin.go @@ -112,3 +112,8 @@ func (c *pulsarClient) endpoint(componentPath string, parts ...string) string { path.Join(escapedParts...), ) } + +// this function won't do any escaping +func (c *pulsarClient) endpointWithFullPath(componentPath string, fullPath string) string { + return path.Join(utils.MakeHTTPPath(c.APIVersion.String(), componentPath), fullPath) +} diff --git a/pulsaradmin/pkg/admin/brokers.go b/pulsaradmin/pkg/admin/brokers.go index 7dcea800e3..8ac400fd72 100644 --- a/pulsaradmin/pkg/admin/brokers.go +++ b/pulsaradmin/pkg/admin/brokers.go @@ -19,7 +19,6 @@ package admin import ( "fmt" - "net/url" "strings" "github.com/apache/pulsar-client-go/pulsaradmin/pkg/utils" @@ -120,8 +119,8 @@ func (b *broker) GetOwnedNamespaces(cluster, brokerURL string) (map[string]utils } func (b *broker) UpdateDynamicConfiguration(configName, configValue string) error { - value := url.QueryEscape(configValue) - endpoint := b.pulsar.endpoint(b.basePath, "/configuration/", configName, value) + value := fmt.Sprintf("/configuration/%s/%s", configName, configValue) + endpoint := b.pulsar.endpointWithFullPath(b.basePath, value) return b.pulsar.Client.Post(endpoint, nil) } diff --git a/pulsaradmin/pkg/admin/brokers_test.go b/pulsaradmin/pkg/admin/brokers_test.go index 3ae9e4aec9..5be90f6c34 100644 --- a/pulsaradmin/pkg/admin/brokers_test.go +++ b/pulsaradmin/pkg/admin/brokers_test.go @@ -73,3 +73,21 @@ func TestGetAllActiveBrokers(t *testing.T) { assert.NoError(t, err) assert.NotEmpty(t, brokers) } + +func TestUpdateDynamicConfiguration(t *testing.T) { + readFile, err := os.ReadFile("../../../integration-tests/tokens/admin-token") + assert.NoError(t, err) + cfg := &config.Config{ + Token: string(readFile), + } + admin, err := New(cfg) + assert.NoError(t, err) + assert.NotNil(t, admin) + + err = admin.Brokers().UpdateDynamicConfiguration("allowAutoSubscriptionCreation", "true") + assert.NoError(t, err) + + configurations, err := admin.Brokers().GetDynamicConfigurationNames() + assert.NoError(t, err) + assert.NotEmpty(t, configurations) +}