Skip to content

Commit 8c0ab0d

Browse files
committed
refactor: rename topic to route
Signed-off-by: Felix Gateru <felix.gateru@gmail.com>
1 parent bee31d0 commit 8c0ab0d

File tree

23 files changed

+142
-166
lines changed

23 files changed

+142
-166
lines changed

.github/workflows/api-tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
- name: Set access token
5959
run: |
6060
export USER_TOKEN=$(curl -sSX POST $TOKENS_URL -H "Content-Type: application/json" -d "{\"identity\": \"$USER_IDENTITY\",\"secret\": \"$USER_SECRET\"}" | jq -r .access_token)
61-
export DOMAIN_ID=$(curl -sSX POST $CREATE_DOMAINS_URL -H "Content-Type: application/json" -H "Authorization: Bearer $USER_TOKEN" -d "{\"name\":\"$DOMAIN_NAME\",\"topic\":\"$DOMAIN_NAME\"}" | jq -r .id)
61+
export DOMAIN_ID=$(curl -sSX POST $CREATE_DOMAINS_URL -H "Content-Type: application/json" -H "Authorization: Bearer $USER_TOKEN" -d "{\"name\":\"$DOMAIN_NAME\",\"route\":\"$DOMAIN_NAME\"}" | jq -r .id)
6262
echo "USER_TOKEN=$USER_TOKEN" >> $GITHUB_ENV
6363
export CLIENT_SECRET=$(supermq-cli provision test | /usr/bin/grep -Eo '"secret": "[^"]+"' | awk 'NR % 2 == 0' | sed 's/"secret": "\(.*\)"/\1/')
6464
echo "CLIENT_SECRET=$CLIENT_SECRET" >> $GITHUB_ENV

api/http/common.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const (
9292

9393
var (
9494
nameRegExp = regexp.MustCompile(`^[a-z0-9][a-z0-9_-]{34}[a-z0-9]$`)
95-
topicRegExp = regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9_-]{0,35}$`)
95+
routeRegExp = regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9_-]{0,35}$`)
9696
errUnreadableName = errors.New("name containing double underscores or double dashes not allowed")
9797
)
9898

@@ -119,14 +119,14 @@ func ValidateName(id string) error {
119119
return nil
120120
}
121121

122-
// ValidateTopic validates topic format.
123-
func ValidateTopic(topic string) error {
124-
if !topicRegExp.MatchString(topic) {
125-
return apiutil.ErrInvalidTopicFormat
122+
// ValidateRoute validates route format.
123+
func ValidateRoute(route string) error {
124+
if !routeRegExp.MatchString(route) {
125+
return apiutil.ErrInvalidRouteFormat
126126
}
127127

128-
if strings.Contains(topic, "__") || strings.Contains(topic, "--") {
129-
return errors.Wrap(apiutil.ErrInvalidTopicFormat, errUnreadableName)
128+
if strings.Contains(route, "__") || strings.Contains(route, "--") {
129+
return errors.Wrap(apiutil.ErrInvalidRouteFormat, errUnreadableName)
130130
}
131131

132132
return nil
@@ -176,7 +176,7 @@ func EncodeError(_ context.Context, err error, w http.ResponseWriter) {
176176
errors.Contains(err, errors.ErrMalformedEntity),
177177
errors.Contains(err, apiutil.ErrMissingID),
178178
errors.Contains(err, apiutil.ErrMissingName),
179-
errors.Contains(err, apiutil.ErrMissingTopic),
179+
errors.Contains(err, apiutil.ErrMissingRoute),
180180
errors.Contains(err, apiutil.ErrMissingEmail),
181181
errors.Contains(err, apiutil.ErrInvalidEmail),
182182
errors.Contains(err, apiutil.ErrMissingHost),
@@ -233,7 +233,7 @@ func EncodeError(_ context.Context, err error, w http.ResponseWriter) {
233233
errors.Contains(err, apiutil.ErrMissingRoleMembers),
234234
errors.Contains(err, apiutil.ErrMissingDescription),
235235
errors.Contains(err, apiutil.ErrMissingEntityID),
236-
errors.Contains(err, apiutil.ErrInvalidTopicFormat):
236+
errors.Contains(err, apiutil.ErrInvalidRouteFormat):
237237
err = unwrap(err)
238238
w.WriteHeader(http.StatusBadRequest)
239239

api/http/util/errors.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ var (
177177
// ErrMissingName indicates missing identity name.
178178
ErrMissingName = errors.New("missing identity name")
179179

180-
// ErrMissingTopic indicates missing topic.
181-
ErrMissingTopic = errors.New("missing topic")
180+
// ErrMissingRoute indicates missing route.
181+
ErrMissingRoute = errors.New("missing route")
182182

183183
// ErrInvalidLevel indicates an invalid group level.
184184
ErrInvalidLevel = errors.New("invalid group level (should be between 0 and 5)")
@@ -263,6 +263,6 @@ var (
263263
// ErrInvalidNameFormat indicates invalid name format.
264264
ErrInvalidNameFormat = errors.New("invalid name format")
265265

266-
// ErrInvalidTopicFormat indicates invalid topic format.
267-
ErrInvalidTopicFormat = errors.New("invalid topic format")
266+
// ErrInvalidRouteFormat indicates invalid route format.
267+
ErrInvalidRouteFormat = errors.New("invalid route format")
268268
)

apidocs/openapi/domains.yaml

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ paths:
5959
"401":
6060
description: Missing or invalid access token provided.
6161
"409":
62-
description: Failed due to using an existing topic.
62+
description: Failed due to using an existing route.
6363
"415":
6464
description: Missing or invalid content type.
6565
"422":
@@ -123,9 +123,9 @@ paths:
123123
$ref: "#/components/responses/ServiceError"
124124

125125
patch:
126-
summary: Updates name, metadata, tags and topic of the domain.
126+
summary: Updates name, metadata and tags of the domain.
127127
description: |
128-
Updates name, metadata, tags and topic of the domain.
128+
Updates name, metadata and tags of the domain.
129129
tags:
130130
- Domains
131131
parameters:
@@ -930,13 +930,13 @@ components:
930930
type: object
931931
example: { "domain": "example.com" }
932932
description: Arbitrary, object-encoded domain's data.
933-
topic:
933+
route:
934934
type: string
935-
example: domain topic
936-
description: Domain topic.
935+
example: domain_route
936+
description: Domain route.
937937
required:
938938
- name
939-
- topic
939+
- route
940940
Domain:
941941
type: object
942942
properties:
@@ -960,10 +960,10 @@ components:
960960
type: object
961961
example: { "domain": "example.com" }
962962
description: Arbitrary, object-encoded domain's data.
963-
topic:
963+
route:
964964
type: string
965-
example: domain topic
966-
description: Domain topic.
965+
example: domain_route
966+
description: Domain route.
967967
status:
968968
type: string
969969
description: Domain Status
@@ -1034,10 +1034,6 @@ components:
10341034
type: object
10351035
example: { "domain": "example.com" }
10361036
description: Arbitrary, object-encoded domain's data.
1037-
topic:
1038-
type: string
1039-
example: domain topic
1040-
description: Domain topic.
10411037

10421038
SendInvitationReqObj:
10431039
type: object
@@ -1291,7 +1287,7 @@ components:
12911287
schema:
12921288
$ref: "#/components/schemas/DomainReqObj"
12931289
DomainUpdateReq:
1294-
description: JSON-formated document describing the name, topic, tags, and metadata of the domain to be updated
1290+
description: JSON-formated document describing the name, tags, and metadata of the domain to be updated
12951291
required: true
12961292
content:
12971293
application/json:

auth/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ The following actions are supported:
4040

4141
## Domains
4242

43-
Domains are used to group users and clients. Each domain has a unique topic that is associated with the domain. Domains are used to group users and their entities.
43+
Domains are used to group users and clients. Each domain has a unique route that is associated with the domain. Domains are used to group users and their entities.
4444

4545
Domain consists of the following fields:
4646

4747
- ID - UUID uniquely representing domain
4848
- Name - name of the domain
4949
- Tags - array of tags
5050
- Metadata - Arbitrary, object-encoded domain's data
51-
- Topic - unique topic of the domain
51+
- Route - unique route of the domain used in messaging
5252
- CreatedAt - timestamp at which the domain is created
5353
- UpdatedAt - timestamp at which the domain is updated
5454
- UpdatedBy - user that updated the domain

cli/domains.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import (
1212

1313
var cmdDomains = []cobra.Command{
1414
{
15-
Use: "create <name> <topic> <token>",
15+
Use: "create <name> <route> <token>",
1616
Short: "Create Domain",
17-
Long: "Create Domain with provided name and topic. \n" +
17+
Long: "Create Domain with provided name and route. \n" +
1818
"For example:\n" +
19-
"\tsupermq-cli domains create domain_1 domain_1_topic $TOKEN\n",
19+
"\tsupermq-cli domains create domain_1 domain_1_route $TOKEN\n",
2020
Run: func(cmd *cobra.Command, args []string) {
2121
if len(args) != 3 {
2222
logUsageCmd(*cmd, cmd.Use)
@@ -25,7 +25,7 @@ var cmdDomains = []cobra.Command{
2525

2626
dom := smqsdk.Domain{
2727
Name: args[0],
28-
Topic: args[1],
28+
Route: args[1],
2929
}
3030
d, err := sdk.CreateDomain(dom, args[2])
3131
if err != nil {
@@ -108,9 +108,9 @@ var cmdDomains = []cobra.Command{
108108
{
109109
Use: "update <domain_id> <JSON_string> <user_auth_token>",
110110
Short: "Update domains",
111-
Long: "Updates domains name, topic and metadata \n" +
111+
Long: "Updates domains name, route and metadata \n" +
112112
"Usage:\n" +
113-
"\tsupermq-cli domains update <domain_id> '{\"name\":\"new name\", \"topic\":\"new_topic\", \"metadata\":{\"key\": \"value\"}}' $TOKEN \n",
113+
"\tsupermq-cli domains update <domain_id> '{\"name\":\"new name\", \"route\":\"new_route\", \"metadata\":{\"key\": \"value\"}}' $TOKEN \n",
114114
Run: func(cmd *cobra.Command, args []string) {
115115
if len(args) != 4 && len(args) != 3 {
116116
logUsageCmd(*cmd, cmd.Use)

cli/domains_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var (
2424
domain = smqsdk.Domain{
2525
ID: testsutil.GenerateUUID(&testing.T{}),
2626
Name: "Test domain",
27-
Topic: "topic",
27+
Route: "route",
2828
}
2929
roleID = testsutil.GenerateUUID(&testing.T{})
3030
)
@@ -49,7 +49,7 @@ func TestCreateDomainsCmd(t *testing.T) {
4949
desc: "create domain successfully",
5050
args: []string{
5151
dom.Name,
52-
dom.Topic,
52+
dom.Route,
5353
validToken,
5454
},
5555
logType: entityLog,
@@ -59,7 +59,7 @@ func TestCreateDomainsCmd(t *testing.T) {
5959
desc: "create domain with invalid args",
6060
args: []string{
6161
dom.Name,
62-
dom.Topic,
62+
dom.Route,
6363
validToken,
6464
extraArg,
6565
},
@@ -69,7 +69,7 @@ func TestCreateDomainsCmd(t *testing.T) {
6969
desc: "create domain with invalid token",
7070
args: []string{
7171
dom.Name,
72-
dom.Topic,
72+
dom.Route,
7373
invalidToken,
7474
},
7575
sdkErr: errors.NewSDKErrorWithStatus(svcerr.ErrAuthorization, http.StatusUnauthorized),

domains/api/http/endpoint.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func createDomainEndpoint(svc domains.Service) endpoint.Endpoint {
3535
Name: req.Name,
3636
Metadata: req.Metadata,
3737
Tags: req.Tags,
38-
Topic: req.Topic,
38+
Route: req.Route,
3939
}
4040
domain, _, err := svc.CreateDomain(ctx, session, d)
4141
if err != nil {
@@ -86,7 +86,6 @@ func updateDomainEndpoint(svc domains.Service) endpoint.Endpoint {
8686
Name: req.Name,
8787
Metadata: &metadata,
8888
Tags: req.Tags,
89-
Topic: req.Topic,
9089
}
9190
domain, err := svc.UpdateDomain(ctx, session, req.domainID, d)
9291
if err != nil {

0 commit comments

Comments
 (0)