Skip to content

Commit b79fdb1

Browse files
authored
SMQ-2760 - Rename domain alias to route (#2776)
Signed-off-by: Felix Gateru <felix.gateru@gmail.com>
1 parent 3931eca commit b79fdb1

File tree

24 files changed

+345
-178
lines changed

24 files changed

+345
-178
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\",\"alias\":\"$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: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const (
9292

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

@@ -118,6 +119,19 @@ func ValidateName(id string) error {
118119
return nil
119120
}
120121

122+
// ValidateRoute validates route format.
123+
func ValidateRoute(route string) error {
124+
if !routeRegExp.MatchString(route) {
125+
return apiutil.ErrInvalidRouteFormat
126+
}
127+
128+
if strings.Contains(route, "__") || strings.Contains(route, "--") {
129+
return errors.Wrap(apiutil.ErrInvalidRouteFormat, errUnreadableName)
130+
}
131+
132+
return nil
133+
}
134+
121135
// EncodeResponse encodes successful response.
122136
func EncodeResponse(_ context.Context, w http.ResponseWriter, response interface{}) error {
123137
if ar, ok := response.(supermq.Response); ok {
@@ -162,7 +176,7 @@ func EncodeError(_ context.Context, err error, w http.ResponseWriter) {
162176
errors.Contains(err, errors.ErrMalformedEntity),
163177
errors.Contains(err, apiutil.ErrMissingID),
164178
errors.Contains(err, apiutil.ErrMissingName),
165-
errors.Contains(err, apiutil.ErrMissingAlias),
179+
errors.Contains(err, apiutil.ErrMissingRoute),
166180
errors.Contains(err, apiutil.ErrMissingEmail),
167181
errors.Contains(err, apiutil.ErrInvalidEmail),
168182
errors.Contains(err, apiutil.ErrMissingHost),
@@ -218,7 +232,8 @@ func EncodeError(_ context.Context, err error, w http.ResponseWriter) {
218232
errors.Contains(err, apiutil.ErrMissingPolicyEntityType),
219233
errors.Contains(err, apiutil.ErrMissingRoleMembers),
220234
errors.Contains(err, apiutil.ErrMissingDescription),
221-
errors.Contains(err, apiutil.ErrMissingEntityID):
235+
errors.Contains(err, apiutil.ErrMissingEntityID),
236+
errors.Contains(err, apiutil.ErrInvalidRouteFormat):
222237
err = unwrap(err)
223238
w.WriteHeader(http.StatusBadRequest)
224239

api/http/util/errors.go

Lines changed: 5 additions & 2 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-
// ErrMissingName indicates missing alias.
181-
ErrMissingAlias = errors.New("missing alias")
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)")
@@ -262,4 +262,7 @@ var (
262262

263263
// ErrInvalidNameFormat indicates invalid name format.
264264
ErrInvalidNameFormat = errors.New("invalid name format")
265+
266+
// ErrInvalidRouteFormat indicates invalid route format.
267+
ErrInvalidRouteFormat = errors.New("invalid route format")
265268
)

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 alias.
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 alias of the domain.
126+
summary: Updates name, metadata and tags of the domain.
127127
description: |
128-
Updates name, metadata, tags and alias 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-
alias:
933+
route:
934934
type: string
935-
example: domain alias
936-
description: Domain alias.
935+
example: domain_route
936+
description: Domain route.
937937
required:
938938
- name
939-
- alias
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-
alias:
963+
route:
964964
type: string
965-
example: domain alias
966-
description: Domain alias.
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-
alias:
1038-
type: string
1039-
example: domain alias
1040-
description: Domain alias.
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, alias, 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:

0 commit comments

Comments
 (0)