fixup streams stuff (#90)

This commit is contained in:
Asim Aslam
2021-04-30 20:48:42 +01:00
committed by GitHub
parent f5f67bc614
commit 500acefe47
4 changed files with 36 additions and 14 deletions

View File

@@ -26,6 +26,7 @@ var (
type Token struct {
Token string `gorm:"primaryKey"`
Topic string
Account string
ExpiresAt time.Time
}
@@ -35,13 +36,17 @@ type Streams struct {
Time func() time.Time
}
// fmtTopic returns a topic string with namespace prefix
func fmtTopic(acc *auth.Account, topic string) string {
func getAccount(acc *auth.Account) string {
owner := acc.Metadata["apikey_owner"]
if len(owner) == 0 {
owner = acc.ID
}
return fmt.Sprintf("%s.%s.%s", acc.Issuer, owner, topic)
return fmt.Sprintf("%s.%s", acc.Issuer, owner)
}
// fmtTopic returns a topic string with namespace prefix
func fmtTopic(acc *auth.Account, topic string) string {
return fmt.Sprintf("%s.%s", getAccount(acc), topic)
}
// validateTopicInput validates that topic is alphanumeric