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

Commit

Permalink
Add RetentionPolicy parsing (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
rivernate authored and maxsxu committed Mar 14, 2023
1 parent 9b557a9 commit 521b284
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
17 changes: 17 additions & 0 deletions pkg/pulsar/utils/backlog_quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package utils

import "github.com/pkg/errors"

type BacklogQuota struct {
Limit int64 `json:"limit"`
Policy RetentionPolicy `json:"policy"`
Expand All @@ -40,3 +42,18 @@ const (
ProducerException RetentionPolicy = "producer_exception"
ConsumerBacklogEviction RetentionPolicy = "consumer_backlog_eviction"
)

func ParseRetentionPolicy(str string) (RetentionPolicy, error) {
switch str {
case ProducerException.String():
return ProducerException, nil
case ConsumerBacklogEviction.String():
return ConsumerBacklogEviction, nil
default:
return "", errors.Errorf("Invalid retention policy %s", str)
}
}

func (s RetentionPolicy) String() string {
return string(s)
}
6 changes: 3 additions & 3 deletions pkg/pulsar/utils/namespace_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ func validateNamespaceName(tenant, namespace string) error {
return errors.Errorf("Invalid tenant or namespace. [%s/%s]", tenant, namespace)
}

ok := checkName(tenant)
ok := CheckName(tenant)
if !ok {
return errors.Errorf("Tenant name include unsupported special chars. tenant : [%s]", tenant)
}

ok = checkName(namespace)
ok = CheckName(namespace)
if !ok {
return errors.Errorf("Namespace name include unsupported special chars. namespace : [%s]", namespace)
}
Expand All @@ -83,7 +83,7 @@ func validateNamespaceName(tenant, namespace string) error {
// and % is allowed as part of valid URL encoding
const PATTEN = "^[-=:.\\w]*$"

func checkName(name string) bool {
func CheckName(name string) bool {
patten, err := regexp.Compile(PATTEN)
if err != nil {
return false
Expand Down

0 comments on commit 521b284

Please sign in to comment.