Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
fix: Remove encoding for the topic (#828)
Browse files Browse the repository at this point in the history
Signed-off-by: Zixuan Liu <[email protected]>
  • Loading branch information
nodece authored and maxsxu committed Mar 14, 2023
1 parent d0ef25d commit 56d77ba
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 24 deletions.
10 changes: 5 additions & 5 deletions pkg/pulsar/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (s *schemas) GetSchemaInfo(topic string) (*utils.SchemaInfo, error) {
}
var response utils.GetSchemaResponse
endpoint := s.pulsar.endpoint(s.basePath, topicName.GetTenant(), topicName.GetNamespace(),
topicName.GetEncodedTopic(), "schema")
topicName.GetLocalName(), "schema")

err = s.pulsar.Client.Get(endpoint, &response)
if err != nil {
Expand All @@ -80,7 +80,7 @@ func (s *schemas) GetSchemaInfoWithVersion(topic string) (*utils.SchemaInfoWithV
}
var response utils.GetSchemaResponse
endpoint := s.pulsar.endpoint(s.basePath, topicName.GetTenant(), topicName.GetNamespace(),
topicName.GetEncodedTopic(), "schema")
topicName.GetLocalName(), "schema")

err = s.pulsar.Client.Get(endpoint, &response)
if err != nil {
Expand All @@ -99,7 +99,7 @@ func (s *schemas) GetSchemaInfoByVersion(topic string, version int64) (*utils.Sc
}

var response utils.GetSchemaResponse
endpoint := s.pulsar.endpoint(s.basePath, topicName.GetTenant(), topicName.GetNamespace(), topicName.GetEncodedTopic(),
endpoint := s.pulsar.endpoint(s.basePath, topicName.GetTenant(), topicName.GetNamespace(), topicName.GetLocalName(),
"schema", strconv.FormatInt(version, 10))

err = s.pulsar.Client.Get(endpoint, &response)
Expand All @@ -118,7 +118,7 @@ func (s *schemas) DeleteSchema(topic string) error {
}

endpoint := s.pulsar.endpoint(s.basePath, topicName.GetTenant(), topicName.GetNamespace(),
topicName.GetEncodedTopic(), "schema")
topicName.GetLocalName(), "schema")

fmt.Println(endpoint)

Expand All @@ -132,7 +132,7 @@ func (s *schemas) CreateSchemaByPayload(topic string, schemaPayload utils.PostSc
}

endpoint := s.pulsar.endpoint(s.basePath, topicName.GetTenant(), topicName.GetNamespace(),
topicName.GetEncodedTopic(), "schema")
topicName.GetLocalName(), "schema")

return s.pulsar.Client.Post(endpoint, &schemaPayload)
}
2 changes: 1 addition & 1 deletion pkg/pulsar/utils/topic_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (t *TopicName) IsPersistent() bool {
}

func (t *TopicName) GetRestPath() string {
return fmt.Sprintf("%s/%s/%s/%s", t.domain, t.tenant, t.namespace, t.GetEncodedTopic())
return fmt.Sprintf("%s/%s/%s/%s", t.domain, t.tenant, t.namespace, t.topic)
}

func (t *TopicName) GetEncodedTopic() string {
Expand Down
18 changes: 0 additions & 18 deletions pkg/pulsar/utils/topic_name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package utils

import (
"net/url"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -74,20 +73,3 @@ func TestGetTopicName(t *testing.T) {
assert.Equal(t, "topic name can not be empty", err.Error())
assert.Nil(t, fail)
}

func TestTopicNameEncodeTest(t *testing.T) {
encodedName := "a%3Aen-in_in_business_content_item_20150312173022_https%5C%3A%2F%2Fin.news.example.com%2Fr"
rawName := "a:en-in_in_business_content_item_20150312173022_https\\://in.news.example.com/r"

assert.Equal(t, encodedName, url.QueryEscape(rawName))
o, err := url.QueryUnescape(encodedName)
assert.Nil(t, err)
assert.Equal(t, rawName, o)

topicName, err := GetTopicName("persistent://prop/ns/" + rawName)
assert.Nil(t, err)

assert.Equal(t, rawName, topicName.topic)
assert.Equal(t, encodedName, topicName.GetEncodedTopic())
assert.Equal(t, "persistent/prop/ns/"+encodedName, topicName.GetRestPath())
}

0 comments on commit 56d77ba

Please sign in to comment.