mirror of
https://github.com/absmach/magistrala.git
synced 2026-06-23 04:10:28 +00:00
SMQ-2760 - Rename domain alias to route (#2776)
Signed-off-by: Felix Gateru <felix.gateru@gmail.com>
This commit is contained in:
@@ -58,7 +58,7 @@ jobs:
|
||||
- name: Set access token
|
||||
run: |
|
||||
export USER_TOKEN=$(curl -sSX POST $TOKENS_URL -H "Content-Type: application/json" -d "{\"identity\": \"$USER_IDENTITY\",\"secret\": \"$USER_SECRET\"}" | jq -r .access_token)
|
||||
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)
|
||||
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)
|
||||
echo "USER_TOKEN=$USER_TOKEN" >> $GITHUB_ENV
|
||||
export CLIENT_SECRET=$(supermq-cli provision test | /usr/bin/grep -Eo '"secret": "[^"]+"' | awk 'NR % 2 == 0' | sed 's/"secret": "\(.*\)"/\1/')
|
||||
echo "CLIENT_SECRET=$CLIENT_SECRET" >> $GITHUB_ENV
|
||||
|
||||
+17
-2
@@ -92,6 +92,7 @@ const (
|
||||
|
||||
var (
|
||||
nameRegExp = regexp.MustCompile(`^[a-z0-9][a-z0-9_-]{34}[a-z0-9]$`)
|
||||
routeRegExp = regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9_-]{0,35}$`)
|
||||
errUnreadableName = errors.New("name containing double underscores or double dashes not allowed")
|
||||
)
|
||||
|
||||
@@ -118,6 +119,19 @@ func ValidateName(id string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidateRoute validates route format.
|
||||
func ValidateRoute(route string) error {
|
||||
if !routeRegExp.MatchString(route) {
|
||||
return apiutil.ErrInvalidRouteFormat
|
||||
}
|
||||
|
||||
if strings.Contains(route, "__") || strings.Contains(route, "--") {
|
||||
return errors.Wrap(apiutil.ErrInvalidRouteFormat, errUnreadableName)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// EncodeResponse encodes successful response.
|
||||
func EncodeResponse(_ context.Context, w http.ResponseWriter, response interface{}) error {
|
||||
if ar, ok := response.(supermq.Response); ok {
|
||||
@@ -162,7 +176,7 @@ func EncodeError(_ context.Context, err error, w http.ResponseWriter) {
|
||||
errors.Contains(err, errors.ErrMalformedEntity),
|
||||
errors.Contains(err, apiutil.ErrMissingID),
|
||||
errors.Contains(err, apiutil.ErrMissingName),
|
||||
errors.Contains(err, apiutil.ErrMissingAlias),
|
||||
errors.Contains(err, apiutil.ErrMissingRoute),
|
||||
errors.Contains(err, apiutil.ErrMissingEmail),
|
||||
errors.Contains(err, apiutil.ErrInvalidEmail),
|
||||
errors.Contains(err, apiutil.ErrMissingHost),
|
||||
@@ -218,7 +232,8 @@ func EncodeError(_ context.Context, err error, w http.ResponseWriter) {
|
||||
errors.Contains(err, apiutil.ErrMissingPolicyEntityType),
|
||||
errors.Contains(err, apiutil.ErrMissingRoleMembers),
|
||||
errors.Contains(err, apiutil.ErrMissingDescription),
|
||||
errors.Contains(err, apiutil.ErrMissingEntityID):
|
||||
errors.Contains(err, apiutil.ErrMissingEntityID),
|
||||
errors.Contains(err, apiutil.ErrInvalidRouteFormat):
|
||||
err = unwrap(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
|
||||
|
||||
@@ -177,8 +177,8 @@ var (
|
||||
// ErrMissingName indicates missing identity name.
|
||||
ErrMissingName = errors.New("missing identity name")
|
||||
|
||||
// ErrMissingName indicates missing alias.
|
||||
ErrMissingAlias = errors.New("missing alias")
|
||||
// ErrMissingRoute indicates missing route.
|
||||
ErrMissingRoute = errors.New("missing route")
|
||||
|
||||
// ErrInvalidLevel indicates an invalid group level.
|
||||
ErrInvalidLevel = errors.New("invalid group level (should be between 0 and 5)")
|
||||
@@ -262,4 +262,7 @@ var (
|
||||
|
||||
// ErrInvalidNameFormat indicates invalid name format.
|
||||
ErrInvalidNameFormat = errors.New("invalid name format")
|
||||
|
||||
// ErrInvalidRouteFormat indicates invalid route format.
|
||||
ErrInvalidRouteFormat = errors.New("invalid route format")
|
||||
)
|
||||
|
||||
@@ -59,7 +59,7 @@ paths:
|
||||
"401":
|
||||
description: Missing or invalid access token provided.
|
||||
"409":
|
||||
description: Failed due to using an existing alias.
|
||||
description: Failed due to using an existing route.
|
||||
"415":
|
||||
description: Missing or invalid content type.
|
||||
"422":
|
||||
@@ -123,9 +123,9 @@ paths:
|
||||
$ref: "#/components/responses/ServiceError"
|
||||
|
||||
patch:
|
||||
summary: Updates name, metadata, tags and alias of the domain.
|
||||
summary: Updates name, metadata and tags of the domain.
|
||||
description: |
|
||||
Updates name, metadata, tags and alias of the domain.
|
||||
Updates name, metadata and tags of the domain.
|
||||
tags:
|
||||
- Domains
|
||||
parameters:
|
||||
@@ -930,13 +930,13 @@ components:
|
||||
type: object
|
||||
example: { "domain": "example.com" }
|
||||
description: Arbitrary, object-encoded domain's data.
|
||||
alias:
|
||||
route:
|
||||
type: string
|
||||
example: domain alias
|
||||
description: Domain alias.
|
||||
example: domain_route
|
||||
description: Domain route.
|
||||
required:
|
||||
- name
|
||||
- alias
|
||||
- route
|
||||
Domain:
|
||||
type: object
|
||||
properties:
|
||||
@@ -960,10 +960,10 @@ components:
|
||||
type: object
|
||||
example: { "domain": "example.com" }
|
||||
description: Arbitrary, object-encoded domain's data.
|
||||
alias:
|
||||
route:
|
||||
type: string
|
||||
example: domain alias
|
||||
description: Domain alias.
|
||||
example: domain_route
|
||||
description: Domain route.
|
||||
status:
|
||||
type: string
|
||||
description: Domain Status
|
||||
@@ -1034,10 +1034,6 @@ components:
|
||||
type: object
|
||||
example: { "domain": "example.com" }
|
||||
description: Arbitrary, object-encoded domain's data.
|
||||
alias:
|
||||
type: string
|
||||
example: domain alias
|
||||
description: Domain alias.
|
||||
|
||||
SendInvitationReqObj:
|
||||
type: object
|
||||
@@ -1291,7 +1287,7 @@ components:
|
||||
schema:
|
||||
$ref: "#/components/schemas/DomainReqObj"
|
||||
DomainUpdateReq:
|
||||
description: JSON-formated document describing the name, alias, tags, and metadata of the domain to be updated
|
||||
description: JSON-formated document describing the name, tags, and metadata of the domain to be updated
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
|
||||
+46
-46
@@ -40,7 +40,7 @@ The following actions are supported:
|
||||
|
||||
## Domains
|
||||
|
||||
Domains are used to group users and clients. Each domain has a unique alias that is used to identify the domain. Domains are used to group users and their entities.
|
||||
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.
|
||||
|
||||
Domain consists of the following fields:
|
||||
|
||||
@@ -48,7 +48,7 @@ Domain consists of the following fields:
|
||||
- Name - name of the domain
|
||||
- Tags - array of tags
|
||||
- Metadata - Arbitrary, object-encoded domain's data
|
||||
- Alias - unique alias of the domain
|
||||
- Route - unique route of the domain used in messaging
|
||||
- CreatedAt - timestamp at which the domain is created
|
||||
- UpdatedAt - timestamp at which the domain is updated
|
||||
- UpdatedBy - user that updated the domain
|
||||
@@ -59,50 +59,50 @@ Domain consists of the following fields:
|
||||
|
||||
The service is configured using the environment variables presented in the following table. Note that any unset variables will be replaced with their default values.
|
||||
|
||||
| Variable | Description | Default |
|
||||
| --------------------------------- | ----------------------------------------------------------------------- | ------------------------------ |
|
||||
| SMQ_AUTH_LOG_LEVEL | Log level for the Auth service (debug, info, warn, error) | info |
|
||||
| SMQ_AUTH_DB_HOST | Database host address | localhost |
|
||||
| SMQ_AUTH_DB_PORT | Database host port | 5432 |
|
||||
| SMQ_AUTH_DB_USER | Database user | supermq |
|
||||
| SMQ_AUTH_DB_PASSWORD | Database password | supermq |
|
||||
| SMQ_AUTH_DB_NAME | Name of the database used by the service | auth |
|
||||
| SMQ_AUTH_DB_SSL_MODE | Database connection SSL mode (disable, require, verify-ca, verify-full) | disable |
|
||||
| SMQ_AUTH_DB_SSL_CERT | Path to the PEM encoded certificate file | "" |
|
||||
| SMQ_AUTH_DB_SSL_KEY | Path to the PEM encoded key file | "" |
|
||||
| SMQ_AUTH_DB_SSL_ROOT_CERT | Path to the PEM encoded root certificate file | "" |
|
||||
| SMQ_AUTH_HTTP_HOST | Auth service HTTP host | "" |
|
||||
| SMQ_AUTH_HTTP_PORT | Auth service HTTP port | 8189 |
|
||||
| SMQ_AUTH_HTTP_SERVER_CERT | Path to the PEM encoded HTTP server certificate file | "" |
|
||||
| SMQ_AUTH_HTTP_SERVER_KEY | Path to the PEM encoded HTTP server key file | "" |
|
||||
| SMQ_AUTH_GRPC_HOST | Auth service gRPC host | "" |
|
||||
| SMQ_AUTH_GRPC_PORT | Auth service gRPC port | 8181 |
|
||||
| SMQ_AUTH_GRPC_SERVER_CERT | Path to the PEM encoded gRPC server certificate file | "" |
|
||||
| SMQ_AUTH_GRPC_SERVER_KEY | Path to the PEM encoded gRPC server key file | "" |
|
||||
| SMQ_AUTH_GRPC_SERVER_CA_CERTS | Path to the PEM encoded gRPC server CA certificate file | "" |
|
||||
| SMQ_AUTH_GRPC_CLIENT_CA_CERTS | Path to the PEM encoded gRPC client CA certificate file | "" |
|
||||
| SMQ_AUTH_SECRET_KEY | String used for signing tokens | secret |
|
||||
| SMQ_AUTH_ACCESS_TOKEN_DURATION | The access token expiration period | 1h |
|
||||
| SMQ_AUTH_REFRESH_TOKEN_DURATION | The refresh token expiration period | 24h |
|
||||
| SMQ_AUTH_INVITATION_DURATION | The invitation token expiration period | 168h |
|
||||
| SMQ_AUTH_CACHE_URL | Redis URL for caching PAT scopes | redis://localhost:6379/0 |
|
||||
| SMQ_AUTH_CACHE_KEY_DURATION | Duration for which PAT scope cache keys are valid | 10m |
|
||||
| SMQ_SPICEDB_HOST | SpiceDB host address | localhost |
|
||||
| SMQ_SPICEDB_PORT | SpiceDB host port | 50051 |
|
||||
| SMQ_SPICEDB_PRE_SHARED_KEY | SpiceDB pre-shared key | 12345678 |
|
||||
| SMQ_SPICEDB_SCHEMA_FILE | Path to SpiceDB schema file | ./docker/spicedb/schema.zed |
|
||||
| SMQ_JAEGER_URL | Jaeger server URL | <http://jaeger:4318/v1/traces> |
|
||||
| SMQ_JAEGER_TRACE_RATIO | Jaeger sampling ratio | 1.0 |
|
||||
| SMQ_SEND_TELEMETRY | Send telemetry to supermq call home server | true |
|
||||
| SMQ_AUTH_ADAPTER_INSTANCE_ID | Adapter instance ID | "" |
|
||||
| SMQ_AUTH_CALLOUT_URLS | Comma-separated list of callout URLs | "" |
|
||||
| SMQ_AUTH_CALLOUT_METHOD | Callout method | POST |
|
||||
| SMQ_AUTH_CALLOUT_TLS_VERIFICATION | Enable TLS verification for callouts | true |
|
||||
| SMQ_AUTH_CALLOUT_TIMEOUT | Callout timeout | 10s |
|
||||
| SMQ_AUTH_CALLOUT_CA_CERT | Path to CA certificate file | "" |
|
||||
| SMQ_AUTH_CALLOUT_CERT | Path to client certificate file | "" |
|
||||
| SMQ_AUTH_CALLOUT_KEY | Path to client key file | "" |
|
||||
| SMQ_AUTH_CALLOUT_INVOKE_PERMISSIONS | Invoke callout if the authorization permission matches any of the given permissions. | "" |
|
||||
| Variable | Description | Default |
|
||||
| ----------------------------------- | ------------------------------------------------------------------------------------ | ------------------------------ |
|
||||
| SMQ_AUTH_LOG_LEVEL | Log level for the Auth service (debug, info, warn, error) | info |
|
||||
| SMQ_AUTH_DB_HOST | Database host address | localhost |
|
||||
| SMQ_AUTH_DB_PORT | Database host port | 5432 |
|
||||
| SMQ_AUTH_DB_USER | Database user | supermq |
|
||||
| SMQ_AUTH_DB_PASSWORD | Database password | supermq |
|
||||
| SMQ_AUTH_DB_NAME | Name of the database used by the service | auth |
|
||||
| SMQ_AUTH_DB_SSL_MODE | Database connection SSL mode (disable, require, verify-ca, verify-full) | disable |
|
||||
| SMQ_AUTH_DB_SSL_CERT | Path to the PEM encoded certificate file | "" |
|
||||
| SMQ_AUTH_DB_SSL_KEY | Path to the PEM encoded key file | "" |
|
||||
| SMQ_AUTH_DB_SSL_ROOT_CERT | Path to the PEM encoded root certificate file | "" |
|
||||
| SMQ_AUTH_HTTP_HOST | Auth service HTTP host | "" |
|
||||
| SMQ_AUTH_HTTP_PORT | Auth service HTTP port | 8189 |
|
||||
| SMQ_AUTH_HTTP_SERVER_CERT | Path to the PEM encoded HTTP server certificate file | "" |
|
||||
| SMQ_AUTH_HTTP_SERVER_KEY | Path to the PEM encoded HTTP server key file | "" |
|
||||
| SMQ_AUTH_GRPC_HOST | Auth service gRPC host | "" |
|
||||
| SMQ_AUTH_GRPC_PORT | Auth service gRPC port | 8181 |
|
||||
| SMQ_AUTH_GRPC_SERVER_CERT | Path to the PEM encoded gRPC server certificate file | "" |
|
||||
| SMQ_AUTH_GRPC_SERVER_KEY | Path to the PEM encoded gRPC server key file | "" |
|
||||
| SMQ_AUTH_GRPC_SERVER_CA_CERTS | Path to the PEM encoded gRPC server CA certificate file | "" |
|
||||
| SMQ_AUTH_GRPC_CLIENT_CA_CERTS | Path to the PEM encoded gRPC client CA certificate file | "" |
|
||||
| SMQ_AUTH_SECRET_KEY | String used for signing tokens | secret |
|
||||
| SMQ_AUTH_ACCESS_TOKEN_DURATION | The access token expiration period | 1h |
|
||||
| SMQ_AUTH_REFRESH_TOKEN_DURATION | The refresh token expiration period | 24h |
|
||||
| SMQ_AUTH_INVITATION_DURATION | The invitation token expiration period | 168h |
|
||||
| SMQ_AUTH_CACHE_URL | Redis URL for caching PAT scopes | redis://localhost:6379/0 |
|
||||
| SMQ_AUTH_CACHE_KEY_DURATION | Duration for which PAT scope cache keys are valid | 10m |
|
||||
| SMQ_SPICEDB_HOST | SpiceDB host address | localhost |
|
||||
| SMQ_SPICEDB_PORT | SpiceDB host port | 50051 |
|
||||
| SMQ_SPICEDB_PRE_SHARED_KEY | SpiceDB pre-shared key | 12345678 |
|
||||
| SMQ_SPICEDB_SCHEMA_FILE | Path to SpiceDB schema file | ./docker/spicedb/schema.zed |
|
||||
| SMQ_JAEGER_URL | Jaeger server URL | <http://jaeger:4318/v1/traces> |
|
||||
| SMQ_JAEGER_TRACE_RATIO | Jaeger sampling ratio | 1.0 |
|
||||
| SMQ_SEND_TELEMETRY | Send telemetry to supermq call home server | true |
|
||||
| SMQ_AUTH_ADAPTER_INSTANCE_ID | Adapter instance ID | "" |
|
||||
| SMQ_AUTH_CALLOUT_URLS | Comma-separated list of callout URLs | "" |
|
||||
| SMQ_AUTH_CALLOUT_METHOD | Callout method | POST |
|
||||
| SMQ_AUTH_CALLOUT_TLS_VERIFICATION | Enable TLS verification for callouts | true |
|
||||
| SMQ_AUTH_CALLOUT_TIMEOUT | Callout timeout | 10s |
|
||||
| SMQ_AUTH_CALLOUT_CA_CERT | Path to CA certificate file | "" |
|
||||
| SMQ_AUTH_CALLOUT_CERT | Path to client certificate file | "" |
|
||||
| SMQ_AUTH_CALLOUT_KEY | Path to client key file | "" |
|
||||
| SMQ_AUTH_CALLOUT_INVOKE_PERMISSIONS | Invoke callout if the authorization permission matches any of the given permissions. | "" |
|
||||
|
||||
## Deployment
|
||||
|
||||
|
||||
+6
-6
@@ -12,11 +12,11 @@ import (
|
||||
|
||||
var cmdDomains = []cobra.Command{
|
||||
{
|
||||
Use: "create <name> <alias> <token>",
|
||||
Use: "create <name> <route> <token>",
|
||||
Short: "Create Domain",
|
||||
Long: "Create Domain with provided name and alias. \n" +
|
||||
Long: "Create Domain with provided name and route. \n" +
|
||||
"For example:\n" +
|
||||
"\tsupermq-cli domains create domain_1 domain_1_alias $TOKEN\n",
|
||||
"\tsupermq-cli domains create domain_1 domain_1_route $TOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 3 {
|
||||
logUsageCmd(*cmd, cmd.Use)
|
||||
@@ -25,7 +25,7 @@ var cmdDomains = []cobra.Command{
|
||||
|
||||
dom := smqsdk.Domain{
|
||||
Name: args[0],
|
||||
Alias: args[1],
|
||||
Route: args[1],
|
||||
}
|
||||
d, err := sdk.CreateDomain(cmd.Context(), dom, args[2])
|
||||
if err != nil {
|
||||
@@ -108,9 +108,9 @@ var cmdDomains = []cobra.Command{
|
||||
{
|
||||
Use: "update <domain_id> <JSON_string> <user_auth_token>",
|
||||
Short: "Update domains",
|
||||
Long: "Updates domains name, alias and metadata \n" +
|
||||
Long: "Updates domains name, route and metadata \n" +
|
||||
"Usage:\n" +
|
||||
"\tsupermq-cli domains update <domain_id> '{\"name\":\"new name\", \"alias\":\"new_alias\", \"metadata\":{\"key\": \"value\"}}' $TOKEN \n",
|
||||
"\tsupermq-cli domains update <domain_id> '{\"name\":\"new name\", \"route\":\"new_route\", \"metadata\":{\"key\": \"value\"}}' $TOKEN \n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 4 && len(args) != 3 {
|
||||
logUsageCmd(*cmd, cmd.Use)
|
||||
|
||||
+4
-4
@@ -24,7 +24,7 @@ var (
|
||||
domain = smqsdk.Domain{
|
||||
ID: testsutil.GenerateUUID(&testing.T{}),
|
||||
Name: "Test domain",
|
||||
Alias: "alias",
|
||||
Route: "route",
|
||||
}
|
||||
roleID = testsutil.GenerateUUID(&testing.T{})
|
||||
)
|
||||
@@ -49,7 +49,7 @@ func TestCreateDomainsCmd(t *testing.T) {
|
||||
desc: "create domain successfully",
|
||||
args: []string{
|
||||
dom.Name,
|
||||
dom.Alias,
|
||||
dom.Route,
|
||||
validToken,
|
||||
},
|
||||
logType: entityLog,
|
||||
@@ -59,7 +59,7 @@ func TestCreateDomainsCmd(t *testing.T) {
|
||||
desc: "create domain with invalid args",
|
||||
args: []string{
|
||||
dom.Name,
|
||||
dom.Alias,
|
||||
dom.Route,
|
||||
validToken,
|
||||
extraArg,
|
||||
},
|
||||
@@ -69,7 +69,7 @@ func TestCreateDomainsCmd(t *testing.T) {
|
||||
desc: "create domain with invalid token",
|
||||
args: []string{
|
||||
dom.Name,
|
||||
dom.Alias,
|
||||
dom.Route,
|
||||
invalidToken,
|
||||
},
|
||||
sdkErr: errors.NewSDKErrorWithStatus(svcerr.ErrAuthorization, http.StatusUnauthorized),
|
||||
|
||||
@@ -827,7 +827,7 @@ func TestRetrieveAll(t *testing.T) {
|
||||
"department": namegen.Generate(),
|
||||
},
|
||||
Status: clients.EnabledStatus,
|
||||
CreatedAt: time.Now().UTC().Truncate(time.Microsecond),
|
||||
CreatedAt: time.Now().UTC(),
|
||||
}
|
||||
if i%50 == 0 {
|
||||
client.Status = clients.DisabledStatus
|
||||
|
||||
@@ -35,7 +35,7 @@ func createDomainEndpoint(svc domains.Service) endpoint.Endpoint {
|
||||
Name: req.Name,
|
||||
Metadata: req.Metadata,
|
||||
Tags: req.Tags,
|
||||
Alias: req.Alias,
|
||||
Route: req.Route,
|
||||
}
|
||||
domain, _, err := svc.CreateDomain(ctx, session, d)
|
||||
if err != nil {
|
||||
@@ -86,7 +86,6 @@ func updateDomainEndpoint(svc domains.Service) endpoint.Endpoint {
|
||||
Name: req.Name,
|
||||
Metadata: &metadata,
|
||||
Tags: req.Tags,
|
||||
Alias: req.Alias,
|
||||
}
|
||||
domain, err := svc.UpdateDomain(ctx, session, req.domainID, d)
|
||||
if err != nil {
|
||||
|
||||
@@ -40,7 +40,7 @@ var (
|
||||
Tags: []string{"tag1", "tag2"},
|
||||
Metadata: validMetadata,
|
||||
Status: domains.EnabledStatus,
|
||||
Alias: "mydomain",
|
||||
Route: "mydomain",
|
||||
}
|
||||
validToken = "token"
|
||||
inValidToken = "invalid"
|
||||
@@ -123,7 +123,7 @@ func TestCreateDomain(t *testing.T) {
|
||||
Name: "test",
|
||||
Metadata: domains.Metadata{"role": "domain"},
|
||||
Tags: []string{"tag1", "tag2"},
|
||||
Alias: "test",
|
||||
Route: "test",
|
||||
},
|
||||
token: validToken,
|
||||
contentType: contentType,
|
||||
@@ -136,7 +136,7 @@ func TestCreateDomain(t *testing.T) {
|
||||
Name: "test",
|
||||
Metadata: domains.Metadata{"role": "domain"},
|
||||
Tags: []string{"tag1", "tag2"},
|
||||
Alias: "test",
|
||||
Route: "test",
|
||||
},
|
||||
token: "",
|
||||
contentType: contentType,
|
||||
@@ -149,7 +149,7 @@ func TestCreateDomain(t *testing.T) {
|
||||
Name: "test",
|
||||
Metadata: domains.Metadata{"role": "domain"},
|
||||
Tags: []string{"tag1", "tag2"},
|
||||
Alias: "test",
|
||||
Route: "test",
|
||||
},
|
||||
token: inValidToken,
|
||||
contentType: contentType,
|
||||
@@ -163,7 +163,7 @@ func TestCreateDomain(t *testing.T) {
|
||||
Name: "",
|
||||
Metadata: domains.Metadata{"role": "domain"},
|
||||
Tags: []string{"tag1", "tag2"},
|
||||
Alias: "test",
|
||||
Route: "test",
|
||||
},
|
||||
token: validToken,
|
||||
contentType: contentType,
|
||||
@@ -171,17 +171,17 @@ func TestCreateDomain(t *testing.T) {
|
||||
err: apiutil.ErrMissingName,
|
||||
},
|
||||
{
|
||||
desc: "register a new domain with an empty alias",
|
||||
desc: "register a new domain with an empty route",
|
||||
domain: domains.Domain{
|
||||
Name: "test",
|
||||
Metadata: domains.Metadata{"role": "domain"},
|
||||
Tags: []string{"tag1", "tag2"},
|
||||
Alias: "",
|
||||
Route: "",
|
||||
},
|
||||
token: validToken,
|
||||
contentType: contentType,
|
||||
status: http.StatusBadRequest,
|
||||
err: apiutil.ErrMissingAlias,
|
||||
err: apiutil.ErrMissingRoute,
|
||||
},
|
||||
{
|
||||
desc: "register a new domain with invalid content type",
|
||||
@@ -189,7 +189,7 @@ func TestCreateDomain(t *testing.T) {
|
||||
Name: "test",
|
||||
Metadata: domains.Metadata{"role": "domain"},
|
||||
Tags: []string{"tag1", "tag2"},
|
||||
Alias: "test",
|
||||
Route: "test",
|
||||
},
|
||||
token: validToken,
|
||||
contentType: "application/xml",
|
||||
@@ -204,7 +204,7 @@ func TestCreateDomain(t *testing.T) {
|
||||
"test": make(chan int),
|
||||
},
|
||||
Tags: []string{"tag1", "tag2"},
|
||||
Alias: "test",
|
||||
Route: "test",
|
||||
},
|
||||
token: validToken,
|
||||
contentType: contentType,
|
||||
@@ -217,7 +217,7 @@ func TestCreateDomain(t *testing.T) {
|
||||
Name: "test",
|
||||
Metadata: domains.Metadata{"role": "domain"},
|
||||
Tags: []string{"tag1", "tag2"},
|
||||
Alias: "test",
|
||||
Route: "test",
|
||||
},
|
||||
token: validToken,
|
||||
contentType: contentType,
|
||||
@@ -695,13 +695,12 @@ func TestUpdateDomain(t *testing.T) {
|
||||
updatedName := "test"
|
||||
updatedMetadata := domains.Metadata{"role": "domain"}
|
||||
updatedTags := []string{"tag1", "tag2"}
|
||||
updatedAlias := "test"
|
||||
|
||||
updatedDomain := domains.Domain{
|
||||
ID: ID,
|
||||
Name: updatedName,
|
||||
Metadata: updatedMetadata,
|
||||
Tags: updatedTags,
|
||||
Alias: updatedAlias,
|
||||
}
|
||||
unMetadata := domains.Metadata{
|
||||
"test": make(chan int),
|
||||
@@ -728,7 +727,6 @@ func TestUpdateDomain(t *testing.T) {
|
||||
Name: &updatedName,
|
||||
Metadata: &updatedMetadata,
|
||||
Tags: &updatedTags,
|
||||
Alias: &updatedAlias,
|
||||
},
|
||||
contentType: contentType,
|
||||
status: http.StatusOK,
|
||||
@@ -743,7 +741,6 @@ func TestUpdateDomain(t *testing.T) {
|
||||
Name: &updatedName,
|
||||
Metadata: &updatedMetadata,
|
||||
Tags: &updatedTags,
|
||||
Alias: &updatedAlias,
|
||||
},
|
||||
contentType: contentType,
|
||||
status: http.StatusUnauthorized,
|
||||
@@ -757,7 +754,6 @@ func TestUpdateDomain(t *testing.T) {
|
||||
Name: &updatedName,
|
||||
Metadata: &updatedMetadata,
|
||||
Tags: &updatedTags,
|
||||
Alias: &updatedAlias,
|
||||
},
|
||||
contentType: contentType,
|
||||
status: http.StatusUnauthorized,
|
||||
@@ -772,7 +768,6 @@ func TestUpdateDomain(t *testing.T) {
|
||||
Name: &updatedName,
|
||||
Metadata: &updatedMetadata,
|
||||
Tags: &updatedTags,
|
||||
Alias: &updatedAlias,
|
||||
},
|
||||
contentType: "application/xml",
|
||||
status: http.StatusUnsupportedMediaType,
|
||||
@@ -786,7 +781,6 @@ func TestUpdateDomain(t *testing.T) {
|
||||
Name: &updatedName,
|
||||
Metadata: &unMetadata,
|
||||
Tags: &updatedTags,
|
||||
Alias: &updatedAlias,
|
||||
},
|
||||
contentType: contentType,
|
||||
status: http.StatusBadRequest,
|
||||
@@ -800,7 +794,6 @@ func TestUpdateDomain(t *testing.T) {
|
||||
Name: &updatedName,
|
||||
Metadata: &updatedMetadata,
|
||||
Tags: &updatedTags,
|
||||
Alias: &updatedAlias,
|
||||
},
|
||||
contentType: contentType,
|
||||
status: http.StatusUnprocessableEntity,
|
||||
|
||||
@@ -16,7 +16,7 @@ type createDomainReq struct {
|
||||
Name string `json:"name"`
|
||||
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
Alias string `json:"alias"`
|
||||
Route string `json:"route"`
|
||||
}
|
||||
|
||||
func (req createDomainReq) validate() error {
|
||||
@@ -26,8 +26,11 @@ func (req createDomainReq) validate() error {
|
||||
if req.Name == "" {
|
||||
return apiutil.ErrMissingName
|
||||
}
|
||||
if req.Alias == "" {
|
||||
return apiutil.ErrMissingAlias
|
||||
if req.Route == "" {
|
||||
return apiutil.ErrMissingRoute
|
||||
}
|
||||
if err := validateRoute(req.Route); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -51,7 +54,6 @@ type updateDomainReq struct {
|
||||
Name *string `json:"name,omitempty"`
|
||||
Metadata *map[string]interface{} `json:"metadata,omitempty"`
|
||||
Tags *[]string `json:"tags,omitempty"`
|
||||
Alias *string `json:"alias,omitempty"`
|
||||
}
|
||||
|
||||
func (req updateDomainReq) validate() error {
|
||||
@@ -158,3 +160,14 @@ func (req *invitationReq) validate() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateRoute(route string) error {
|
||||
if err := api.ValidateUUID(route); err == nil {
|
||||
return nil
|
||||
}
|
||||
if err := api.ValidateRoute(route); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
+4
-2
@@ -100,7 +100,6 @@ type DomainReq struct {
|
||||
Name *string `json:"name,omitempty"`
|
||||
Metadata *Metadata `json:"metadata,omitempty"`
|
||||
Tags *[]string `json:"tags,omitempty"`
|
||||
Alias *string `json:"alias,omitempty"`
|
||||
Status *Status `json:"status,omitempty"`
|
||||
UpdatedBy *string `json:"updated_by,omitempty"`
|
||||
UpdatedAt *time.Time `json:"updated_at,omitempty"`
|
||||
@@ -111,7 +110,7 @@ type Domain struct {
|
||||
Name string `json:"name"`
|
||||
Metadata Metadata `json:"metadata,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
Alias string `json:"alias,omitempty"`
|
||||
Route string `json:"route,omitempty"`
|
||||
Status Status `json:"status"`
|
||||
RoleID string `json:"role_id,omitempty"`
|
||||
RoleName string `json:"role_name,omitempty"`
|
||||
@@ -238,6 +237,9 @@ type Repository interface {
|
||||
// RetrieveDomainByID retrieves a domain by its unique ID.
|
||||
RetrieveDomainByID(ctx context.Context, id string) (Domain, error)
|
||||
|
||||
// RetrieveDomainByRoute retrieves a domain by its unique route.
|
||||
RetrieveDomainByRoute(ctx context.Context, route string) (Domain, error)
|
||||
|
||||
// RetrieveAllDomainsByIDs retrieves for given Domain IDs.
|
||||
RetrieveAllDomainsByIDs(ctx context.Context, pm Page) (DomainsPage, error)
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ func (cde createDomainEvent) Encode() (map[string]interface{}, error) {
|
||||
val := map[string]interface{}{
|
||||
"operation": domainCreate,
|
||||
"id": cde.ID,
|
||||
"alias": cde.Alias,
|
||||
"route": cde.Route,
|
||||
"status": cde.Status.String(),
|
||||
"created_at": cde.CreatedAt,
|
||||
"created_by": cde.CreatedBy,
|
||||
@@ -92,7 +92,7 @@ func (rde retrieveDomainEvent) Encode() (map[string]interface{}, error) {
|
||||
val := map[string]interface{}{
|
||||
"operation": domainRetrieve,
|
||||
"id": rde.ID,
|
||||
"alias": rde.Alias,
|
||||
"route": rde.Route,
|
||||
"status": rde.Status.String(),
|
||||
"created_at": rde.CreatedAt,
|
||||
"user_id": rde.UserID,
|
||||
@@ -151,7 +151,7 @@ func (ude updateDomainEvent) Encode() (map[string]interface{}, error) {
|
||||
val := map[string]interface{}{
|
||||
"operation": domainUpdate,
|
||||
"id": ude.domain.ID,
|
||||
"alias": ude.domain.Alias,
|
||||
"route": ude.domain.Route,
|
||||
"status": ude.domain.Status.String(),
|
||||
"created_at": ude.domain.CreatedAt,
|
||||
"created_by": ude.domain.CreatedBy,
|
||||
|
||||
@@ -43,6 +43,7 @@ func (lm *loggingMiddleware) CreateDomain(ctx context.Context, session authn.Ses
|
||||
slog.Group("domain",
|
||||
slog.String("id", d.ID),
|
||||
slog.String("name", d.Name),
|
||||
slog.String("route", d.Route),
|
||||
),
|
||||
}
|
||||
if err != nil {
|
||||
|
||||
@@ -720,6 +720,61 @@ func (_c *Repository_RetrieveDomainByIDWithRoles_Call) RunAndReturn(run func(ctx
|
||||
return _c
|
||||
}
|
||||
|
||||
// RetrieveDomainByRoute provides a mock function for the type Repository
|
||||
func (_mock *Repository) RetrieveDomainByRoute(ctx context.Context, route string) (domains.Domain, error) {
|
||||
ret := _mock.Called(ctx, route)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for RetrieveDomainByRoute")
|
||||
}
|
||||
|
||||
var r0 domains.Domain
|
||||
var r1 error
|
||||
if returnFunc, ok := ret.Get(0).(func(context.Context, string) (domains.Domain, error)); ok {
|
||||
return returnFunc(ctx, route)
|
||||
}
|
||||
if returnFunc, ok := ret.Get(0).(func(context.Context, string) domains.Domain); ok {
|
||||
r0 = returnFunc(ctx, route)
|
||||
} else {
|
||||
r0 = ret.Get(0).(domains.Domain)
|
||||
}
|
||||
if returnFunc, ok := ret.Get(1).(func(context.Context, string) error); ok {
|
||||
r1 = returnFunc(ctx, route)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// Repository_RetrieveDomainByRoute_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RetrieveDomainByRoute'
|
||||
type Repository_RetrieveDomainByRoute_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// RetrieveDomainByRoute is a helper method to define mock.On call
|
||||
// - ctx
|
||||
// - route
|
||||
func (_e *Repository_Expecter) RetrieveDomainByRoute(ctx interface{}, route interface{}) *Repository_RetrieveDomainByRoute_Call {
|
||||
return &Repository_RetrieveDomainByRoute_Call{Call: _e.mock.On("RetrieveDomainByRoute", ctx, route)}
|
||||
}
|
||||
|
||||
func (_c *Repository_RetrieveDomainByRoute_Call) Run(run func(ctx context.Context, route string)) *Repository_RetrieveDomainByRoute_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
run(args[0].(context.Context), args[1].(string))
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *Repository_RetrieveDomainByRoute_Call) Return(domain domains.Domain, err error) *Repository_RetrieveDomainByRoute_Call {
|
||||
_c.Call.Return(domain, err)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *Repository_RetrieveDomainByRoute_Call) RunAndReturn(run func(ctx context.Context, route string) (domains.Domain, error)) *Repository_RetrieveDomainByRoute_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// RetrieveEntitiesRolesActionsMembers provides a mock function for the type Repository
|
||||
func (_mock *Repository) RetrieveEntitiesRolesActionsMembers(ctx context.Context, entityIDs []string) ([]roles.EntityActionRole, []roles.EntityMemberRole, error) {
|
||||
ret := _mock.Called(ctx, entityIDs)
|
||||
|
||||
+50
-23
@@ -48,9 +48,9 @@ func NewRepository(db postgres.Database) domains.Repository {
|
||||
}
|
||||
|
||||
func (repo domainRepo) SaveDomain(ctx context.Context, d domains.Domain) (dd domains.Domain, err error) {
|
||||
q := `INSERT INTO domains (id, name, tags, alias, metadata, created_at, updated_at, updated_by, created_by, status)
|
||||
VALUES (:id, :name, :tags, :alias, :metadata, :created_at, :updated_at, :updated_by, :created_by, :status)
|
||||
RETURNING id, name, tags, alias, metadata, created_at, updated_at, updated_by, created_by, status;`
|
||||
q := `INSERT INTO domains (id, name, tags, route, metadata, created_at, updated_at, updated_by, created_by, status)
|
||||
VALUES (:id, :name, :tags, :route, :metadata, :created_at, :updated_at, :updated_by, :created_by, :status)
|
||||
RETURNING id, name, tags, route, metadata, created_at, updated_at, updated_by, created_by, status;`
|
||||
|
||||
dbd, err := toDBDomain(d)
|
||||
if err != nil {
|
||||
@@ -138,7 +138,7 @@ func (repo domainRepo) RetrieveDomainByIDWithRoles(ctx context.Context, id strin
|
||||
d.id,
|
||||
d.name,
|
||||
d.tags,
|
||||
d.alias,
|
||||
d.route,
|
||||
d.metadata,
|
||||
d.created_at,
|
||||
d.updated_at,
|
||||
@@ -182,7 +182,7 @@ func (repo domainRepo) RetrieveDomainByIDWithRoles(ctx context.Context, id strin
|
||||
|
||||
// RetrieveDomainByID retrieves Domain by its unique ID.
|
||||
func (repo domainRepo) RetrieveDomainByID(ctx context.Context, id string) (domains.Domain, error) {
|
||||
q := `SELECT d.id as id, d.name as name, d.tags as tags, d.alias as alias, d.metadata as metadata, d.created_at as created_at, d.updated_at as updated_at, d.updated_by as updated_by, d.created_by as created_by, d.status as status
|
||||
q := `SELECT d.id as id, d.name as name, d.tags as tags, d.route as route, d.metadata as metadata, d.created_at as created_at, d.updated_at as updated_at, d.updated_by as updated_by, d.created_by as created_by, d.status as status
|
||||
FROM domains d WHERE d.id = :id`
|
||||
|
||||
dbdp := dbDomainsPage{
|
||||
@@ -211,6 +211,37 @@ func (repo domainRepo) RetrieveDomainByID(ctx context.Context, id string) (domai
|
||||
return domains.Domain{}, repoerr.ErrNotFound
|
||||
}
|
||||
|
||||
// RetrieveDomainByRoute retrieves Domain by its unique route.
|
||||
func (repo domainRepo) RetrieveDomainByRoute(ctx context.Context, route string) (domains.Domain, error) {
|
||||
q := `SELECT d.id as id, d.name as name, d.tags as tags, d.route as route, d.metadata as metadata, d.created_at as created_at, d.updated_at as updated_at, d.updated_by as updated_by, d.created_by as created_by, d.status as status
|
||||
FROM domains d WHERE d.route = :route`
|
||||
|
||||
dbdom := dbDomain{
|
||||
Route: &route,
|
||||
}
|
||||
|
||||
rows, err := repo.db.NamedQueryContext(ctx, q, dbdom)
|
||||
if err != nil {
|
||||
return domains.Domain{}, postgres.HandleError(repoerr.ErrViewEntity, err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
dbd := dbDomain{}
|
||||
if rows.Next() {
|
||||
if err = rows.StructScan(&dbd); err != nil {
|
||||
return domains.Domain{}, postgres.HandleError(repoerr.ErrViewEntity, err)
|
||||
}
|
||||
|
||||
domain, err := toDomain(dbd)
|
||||
if err != nil {
|
||||
return domains.Domain{}, errors.Wrap(repoerr.ErrFailedOpDB, err)
|
||||
}
|
||||
|
||||
return domain, nil
|
||||
}
|
||||
return domains.Domain{}, repoerr.ErrNotFound
|
||||
}
|
||||
|
||||
// RetrieveAllByIDs retrieves for given Domain IDs .
|
||||
func (repo domainRepo) RetrieveAllDomainsByIDs(ctx context.Context, pm domains.Page) (domains.DomainsPage, error) {
|
||||
var q string
|
||||
@@ -222,7 +253,7 @@ func (repo domainRepo) RetrieveAllDomainsByIDs(ctx context.Context, pm domains.P
|
||||
return domains.DomainsPage{}, errors.Wrap(repoerr.ErrFailedOpDB, err)
|
||||
}
|
||||
|
||||
q = `SELECT d.id as id, d.name as name, d.tags as tags, d.alias as alias, d.metadata as metadata, d.created_at as created_at, d.updated_at as updated_at, d.updated_by as updated_by, d.created_by as created_by, d.status as status
|
||||
q = `SELECT d.id as id, d.name as name, d.tags as tags, d.route as route, d.metadata as metadata, d.created_at as created_at, d.updated_at as updated_at, d.updated_by as updated_by, d.created_by as created_by, d.status as status
|
||||
FROM domains d`
|
||||
q = fmt.Sprintf("%s %s LIMIT %d OFFSET %d;", q, query, pm.Limit, pm.Offset)
|
||||
|
||||
@@ -272,7 +303,7 @@ func (repo domainRepo) ListDomains(ctx context.Context, pm domains.Page) (domain
|
||||
d.id as id,
|
||||
d.name as name,
|
||||
d.tags as tags,
|
||||
d.alias as alias,
|
||||
d.route as route,
|
||||
d.metadata as metadata,
|
||||
d.created_at as created_at,
|
||||
d.updated_at as updated_at,
|
||||
@@ -291,7 +322,7 @@ func (repo domainRepo) ListDomains(ctx context.Context, pm domains.Page) (domain
|
||||
d.id as id,
|
||||
d.name as name,
|
||||
d.tags as tags,
|
||||
d.alias as alias,
|
||||
d.route as route,
|
||||
d.metadata as metadata,
|
||||
d.status as status,
|
||||
d.role_id AS role_id,
|
||||
@@ -371,10 +402,6 @@ func (repo domainRepo) UpdateDomain(ctx context.Context, id string, dr domains.D
|
||||
query = append(query, "status = :status")
|
||||
d.Status = *dr.Status
|
||||
}
|
||||
if dr.Alias != nil {
|
||||
query = append(query, "alias = :alias")
|
||||
d.Alias = *dr.Alias
|
||||
}
|
||||
d.UpdatedAt = time.Now()
|
||||
if dr.UpdatedAt != nil {
|
||||
query = append(query, "updated_at = :updated_at")
|
||||
@@ -389,7 +416,7 @@ func (repo domainRepo) UpdateDomain(ctx context.Context, id string, dr domains.D
|
||||
}
|
||||
q := fmt.Sprintf(`UPDATE domains SET %s
|
||||
WHERE id = :id
|
||||
RETURNING id, name, tags, alias, metadata, created_at, updated_at, updated_by, created_by, status;`,
|
||||
RETURNING id, name, tags, route, metadata, created_at, updated_at, updated_by, created_by, status;`,
|
||||
upq)
|
||||
|
||||
dbd, err := toDBDomain(d)
|
||||
@@ -438,7 +465,7 @@ func (repo domainRepo) userDomainsBaseQuery() string {
|
||||
d.id as id,
|
||||
d.name as name,
|
||||
d.tags as tags,
|
||||
d.alias as alias,
|
||||
d.route as route,
|
||||
d.metadata as metadata,
|
||||
d.created_at as created_at,
|
||||
d.updated_at as updated_at,
|
||||
@@ -497,7 +524,7 @@ type dbDomain struct {
|
||||
Name string `db:"name"`
|
||||
Metadata []byte `db:"metadata,omitempty"`
|
||||
Tags pgtype.TextArray `db:"tags,omitempty"`
|
||||
Alias *string `db:"alias,omitempty"`
|
||||
Route *string `db:"route,omitempty"`
|
||||
Status domains.Status `db:"status"`
|
||||
RoleID string `db:"role_id"`
|
||||
RoleName string `db:"role_name"`
|
||||
@@ -523,9 +550,9 @@ func toDBDomain(d domains.Domain) (dbDomain, error) {
|
||||
if err := tags.Set(d.Tags); err != nil {
|
||||
return dbDomain{}, err
|
||||
}
|
||||
var alias *string
|
||||
if d.Alias != "" {
|
||||
alias = &d.Alias
|
||||
var route *string
|
||||
if d.Route != "" {
|
||||
route = &d.Route
|
||||
}
|
||||
|
||||
var updatedBy *string
|
||||
@@ -542,7 +569,7 @@ func toDBDomain(d domains.Domain) (dbDomain, error) {
|
||||
Name: d.Name,
|
||||
Metadata: data,
|
||||
Tags: tags,
|
||||
Alias: alias,
|
||||
Route: route,
|
||||
Status: d.Status,
|
||||
RoleID: d.RoleID,
|
||||
CreatedBy: d.CreatedBy,
|
||||
@@ -563,9 +590,9 @@ func toDomain(d dbDomain) (domains.Domain, error) {
|
||||
for _, e := range d.Tags.Elements {
|
||||
tags = append(tags, e.String)
|
||||
}
|
||||
var alias string
|
||||
if d.Alias != nil {
|
||||
alias = *d.Alias
|
||||
var route string
|
||||
if d.Route != nil {
|
||||
route = *d.Route
|
||||
}
|
||||
var updatedBy string
|
||||
if d.UpdatedBy != nil {
|
||||
@@ -588,7 +615,7 @@ func toDomain(d dbDomain) (domains.Domain, error) {
|
||||
Name: d.Name,
|
||||
Metadata: metadata,
|
||||
Tags: tags,
|
||||
Alias: alias,
|
||||
Route: route,
|
||||
RoleID: d.RoleID,
|
||||
RoleName: d.RoleName,
|
||||
Actions: d.Actions,
|
||||
|
||||
@@ -18,9 +18,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const (
|
||||
invalid = "invalid"
|
||||
)
|
||||
const invalid = "invalid"
|
||||
|
||||
var (
|
||||
domainID = testsutil.GenerateUUID(&testing.T{})
|
||||
@@ -45,7 +43,7 @@ func TestSaveDomain(t *testing.T) {
|
||||
domain: domains.Domain{
|
||||
ID: domainID,
|
||||
Name: "test",
|
||||
Alias: "test",
|
||||
Route: "test",
|
||||
Tags: []string{"test"},
|
||||
Metadata: map[string]interface{}{
|
||||
"test": "test",
|
||||
@@ -63,7 +61,7 @@ func TestSaveDomain(t *testing.T) {
|
||||
domain: domains.Domain{
|
||||
ID: domainID,
|
||||
Name: "test",
|
||||
Alias: "test",
|
||||
Route: "test",
|
||||
Tags: []string{"test"},
|
||||
Metadata: map[string]interface{}{
|
||||
"test": "test",
|
||||
@@ -81,7 +79,7 @@ func TestSaveDomain(t *testing.T) {
|
||||
domain: domains.Domain{
|
||||
ID: "",
|
||||
Name: "test1",
|
||||
Alias: "test1",
|
||||
Route: "test1",
|
||||
Tags: []string{"test"},
|
||||
Metadata: map[string]interface{}{
|
||||
"test": "test",
|
||||
@@ -95,11 +93,11 @@ func TestSaveDomain(t *testing.T) {
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
desc: "add domain with empty alias",
|
||||
desc: "add domain with empty route",
|
||||
domain: domains.Domain{
|
||||
ID: testsutil.GenerateUUID(&testing.T{}),
|
||||
Name: "test1",
|
||||
Alias: "",
|
||||
Route: "",
|
||||
Tags: []string{"test"},
|
||||
Metadata: map[string]interface{}{
|
||||
"test": "test",
|
||||
@@ -117,7 +115,7 @@ func TestSaveDomain(t *testing.T) {
|
||||
domain: domains.Domain{
|
||||
ID: domainID,
|
||||
Name: "test1",
|
||||
Alias: "test1",
|
||||
Route: "test1",
|
||||
Tags: []string{"test"},
|
||||
Metadata: map[string]interface{}{
|
||||
"key": make(chan int),
|
||||
@@ -154,7 +152,7 @@ func TestRetrieveByID(t *testing.T) {
|
||||
domain := domains.Domain{
|
||||
ID: domainID,
|
||||
Name: "test",
|
||||
Alias: "test",
|
||||
Route: "test",
|
||||
Tags: []string{"test"},
|
||||
Metadata: map[string]interface{}{
|
||||
"test": "test",
|
||||
@@ -167,7 +165,7 @@ func TestRetrieveByID(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err := repo.SaveDomain(context.Background(), domain)
|
||||
require.Nil(t, err, fmt.Sprintf("failed to save client %s", domain.ID))
|
||||
require.Nil(t, err, fmt.Sprintf("failed to save domain %s", domain.ID))
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -176,19 +174,19 @@ func TestRetrieveByID(t *testing.T) {
|
||||
err error
|
||||
}{
|
||||
{
|
||||
desc: "retrieve existing client",
|
||||
desc: "retrieve existing domain",
|
||||
domainID: domain.ID,
|
||||
response: domain,
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
desc: "retrieve non-existing client",
|
||||
desc: "retrieve non-existing domain",
|
||||
domainID: invalid,
|
||||
response: domains.Domain{},
|
||||
err: repoerr.ErrNotFound,
|
||||
},
|
||||
{
|
||||
desc: "retrieve with empty client id",
|
||||
desc: "retrieve with empty domain id",
|
||||
domainID: "",
|
||||
response: domains.Domain{},
|
||||
err: repoerr.ErrNotFound,
|
||||
@@ -204,6 +202,68 @@ func TestRetrieveByID(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRetrieveByRoute(t *testing.T) {
|
||||
t.Cleanup(func() {
|
||||
_, err := db.Exec("DELETE FROM domains")
|
||||
require.Nil(t, err, fmt.Sprintf("clean domains unexpected error: %s", err))
|
||||
})
|
||||
|
||||
repo := postgres.NewRepository(database)
|
||||
|
||||
validRoute := "testRoute"
|
||||
domain := domains.Domain{
|
||||
ID: domainID,
|
||||
Name: "test",
|
||||
Route: validRoute,
|
||||
Tags: []string{"test"},
|
||||
Metadata: map[string]interface{}{
|
||||
"test": "test",
|
||||
},
|
||||
CreatedBy: userID,
|
||||
UpdatedBy: userID,
|
||||
CreatedAt: time.Now().UTC().Truncate(time.Millisecond),
|
||||
UpdatedAt: time.Now().UTC().Truncate(time.Millisecond),
|
||||
Status: domains.EnabledStatus,
|
||||
}
|
||||
|
||||
_, err := repo.SaveDomain(context.Background(), domain)
|
||||
require.Nil(t, err, fmt.Sprintf("failed to save domain %s", domain.ID))
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
route string
|
||||
response domains.Domain
|
||||
err error
|
||||
}{
|
||||
{
|
||||
desc: "retrieve existing domain",
|
||||
route: validRoute,
|
||||
response: domain,
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
desc: "retrieve doamin with invalid route",
|
||||
route: invalid,
|
||||
response: domains.Domain{},
|
||||
err: repoerr.ErrNotFound,
|
||||
},
|
||||
{
|
||||
desc: "retrieve with empty domain route",
|
||||
route: "",
|
||||
response: domains.Domain{},
|
||||
err: repoerr.ErrNotFound,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
d, err := repo.RetrieveDomainByRoute(context.Background(), tc.route)
|
||||
assert.Equal(t, tc.response, d, fmt.Sprintf("%s: expected %v got %v\n", tc.desc, tc.response, d))
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %v got %v\n", tc.desc, tc.err, err))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRetrieveAllByIDs(t *testing.T) {
|
||||
t.Cleanup(func() {
|
||||
_, err := db.Exec("DELETE FROM domains")
|
||||
@@ -217,7 +277,7 @@ func TestRetrieveAllByIDs(t *testing.T) {
|
||||
domain := domains.Domain{
|
||||
ID: testsutil.GenerateUUID(t),
|
||||
Name: fmt.Sprintf(`"test%d"`, i),
|
||||
Alias: fmt.Sprintf(`"test%d"`, i),
|
||||
Route: fmt.Sprintf(`"test%d"`, i),
|
||||
Tags: []string{"test"},
|
||||
Metadata: map[string]interface{}{
|
||||
"test": "test",
|
||||
@@ -453,14 +513,13 @@ func TestUpdate(t *testing.T) {
|
||||
}
|
||||
updatedTags := []string{"test1"}
|
||||
updatedStatus := domains.DisabledStatus
|
||||
updatedAlias := "test1"
|
||||
|
||||
repo := postgres.NewRepository(database)
|
||||
|
||||
domain := domains.Domain{
|
||||
ID: domainID,
|
||||
Name: "test",
|
||||
Alias: "test",
|
||||
Route: "test",
|
||||
Tags: []string{"test"},
|
||||
Metadata: map[string]interface{}{
|
||||
"test": "test",
|
||||
@@ -471,7 +530,7 @@ func TestUpdate(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err := repo.SaveDomain(context.Background(), domain)
|
||||
require.Nil(t, err, fmt.Sprintf("failed to save client %s", domain.ID))
|
||||
require.Nil(t, err, fmt.Sprintf("failed to save domain %s", domain.ID))
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -490,7 +549,7 @@ func TestUpdate(t *testing.T) {
|
||||
response: domains.Domain{
|
||||
ID: domainID,
|
||||
Name: "test1",
|
||||
Alias: "test",
|
||||
Route: "test",
|
||||
Tags: []string{"test"},
|
||||
Metadata: map[string]interface{}{
|
||||
"test1": "test1",
|
||||
@@ -503,19 +562,18 @@ func TestUpdate(t *testing.T) {
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
desc: "update existing domain name, metadata, tags, status and alias",
|
||||
desc: "update existing domain name, metadata, tags and status",
|
||||
domainID: domain.ID,
|
||||
d: domains.DomainReq{
|
||||
Name: &updatedName,
|
||||
Metadata: &updatedMetadata,
|
||||
Tags: &updatedTags,
|
||||
Status: &updatedStatus,
|
||||
Alias: &updatedAlias,
|
||||
},
|
||||
response: domains.Domain{
|
||||
ID: domainID,
|
||||
Name: "test1",
|
||||
Alias: "test1",
|
||||
Route: "test",
|
||||
Tags: []string{"test1"},
|
||||
Metadata: map[string]interface{}{
|
||||
"test1": "test1",
|
||||
@@ -580,7 +638,7 @@ func TestDelete(t *testing.T) {
|
||||
domain := domains.Domain{
|
||||
ID: domainID,
|
||||
Name: "test",
|
||||
Alias: "test",
|
||||
Route: "test",
|
||||
Tags: []string{"test"},
|
||||
Metadata: map[string]interface{}{
|
||||
"test": "test",
|
||||
@@ -591,7 +649,7 @@ func TestDelete(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err := repo.SaveDomain(context.Background(), domain)
|
||||
require.Nil(t, err, fmt.Sprintf("failed to save client %s", domain.ID))
|
||||
require.Nil(t, err, fmt.Sprintf("failed to save domain %s", domain.ID))
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -636,7 +694,7 @@ func TestListDomains(t *testing.T) {
|
||||
domain := domains.Domain{
|
||||
ID: testsutil.GenerateUUID(t),
|
||||
Name: fmt.Sprintf(`"test%d"`, i),
|
||||
Alias: fmt.Sprintf(`"test%d"`, i),
|
||||
Route: fmt.Sprintf(`"test%d"`, i),
|
||||
Tags: []string{"test"},
|
||||
Metadata: map[string]interface{}{
|
||||
"test": "test",
|
||||
|
||||
@@ -61,6 +61,15 @@ func Migration() (*migrate.MemoryMigrationSource, error) {
|
||||
`DROP TABLE IF EXISTS invitations`,
|
||||
},
|
||||
},
|
||||
{
|
||||
Id: "domain_3",
|
||||
Up: []string{
|
||||
`ALTER TABLE domains RENAME COLUMN alias TO route;`,
|
||||
},
|
||||
Down: []string{
|
||||
`ALTER TABLE domains RENAME COLUMN route TO alias;`,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -823,7 +823,7 @@ func saveDomain(t *testing.T, repo domains.Repository) domains.Domain {
|
||||
domain := domains.Domain{
|
||||
ID: testsutil.GenerateUUID(t),
|
||||
Name: "test",
|
||||
Alias: "test",
|
||||
Route: "test",
|
||||
Tags: []string{"test"},
|
||||
Metadata: map[string]interface{}{
|
||||
"test": "test",
|
||||
|
||||
@@ -49,7 +49,7 @@ var (
|
||||
ID: validID,
|
||||
Name: groupName,
|
||||
Tags: []string{"tag1", "tag2"},
|
||||
Alias: "test",
|
||||
Route: "test",
|
||||
RoleID: "test_role_id",
|
||||
CreatedBy: validID,
|
||||
UpdatedBy: validID,
|
||||
@@ -66,7 +66,7 @@ var (
|
||||
ID: validID,
|
||||
Name: groupName,
|
||||
Tags: []string{"tag1", "tag2"},
|
||||
Alias: "test",
|
||||
Route: "test",
|
||||
RoleID: "test_role_id",
|
||||
CreatedBy: validID,
|
||||
UpdatedBy: validID,
|
||||
@@ -303,7 +303,7 @@ func TestUpdateDomain(t *testing.T) {
|
||||
|
||||
updatedDomain := domain
|
||||
updatedDomain.Name = valid
|
||||
updatedDomain.Alias = valid
|
||||
updatedDomain.Route = valid
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -319,8 +319,7 @@ func TestUpdateDomain(t *testing.T) {
|
||||
session: validSession,
|
||||
domainID: domain.ID,
|
||||
updateReq: domains.DomainReq{
|
||||
Name: &valid,
|
||||
Alias: &valid,
|
||||
Name: &valid,
|
||||
},
|
||||
updateRes: updatedDomain,
|
||||
err: nil,
|
||||
@@ -330,8 +329,7 @@ func TestUpdateDomain(t *testing.T) {
|
||||
session: validSession,
|
||||
domainID: "",
|
||||
updateReq: domains.DomainReq{
|
||||
Name: &valid,
|
||||
Alias: &valid,
|
||||
Name: &valid,
|
||||
},
|
||||
updateErr: repoerr.ErrNotFound,
|
||||
err: svcerr.ErrUpdateEntity,
|
||||
@@ -341,8 +339,7 @@ func TestUpdateDomain(t *testing.T) {
|
||||
session: validSession,
|
||||
domainID: domain.ID,
|
||||
updateReq: domains.DomainReq{
|
||||
Name: &valid,
|
||||
Alias: &valid,
|
||||
Name: &valid,
|
||||
},
|
||||
updateErr: errors.ErrMalformedEntity,
|
||||
err: svcerr.ErrUpdateEntity,
|
||||
|
||||
@@ -27,7 +27,7 @@ var (
|
||||
|
||||
errID = errors.New("missing or invalid 'id'")
|
||||
errName = errors.New("missing or invalid 'name'")
|
||||
errAlias = errors.New("missing or invalid 'alias'")
|
||||
errRoute = errors.New("missing or invalid 'route'")
|
||||
errTags = errors.New("invalid 'tags'")
|
||||
errStatus = errors.New("missing or invalid 'status'")
|
||||
errConvertStatus = errors.New("failed to convert status")
|
||||
@@ -60,11 +60,11 @@ func ToDomains(data map[string]interface{}) (domains.Domain, error) {
|
||||
}
|
||||
d.Status = st
|
||||
|
||||
alias, ok := data["alias"].(string)
|
||||
route, ok := data["route"].(string)
|
||||
if !ok {
|
||||
return domains.Domain{}, errAlias
|
||||
return domains.Domain{}, errRoute
|
||||
}
|
||||
d.Alias = alias
|
||||
d.Route = route
|
||||
|
||||
cby, ok := data["created_by"].(string)
|
||||
if !ok {
|
||||
@@ -145,9 +145,9 @@ func decodeUpdateDomainEvent(data map[string]interface{}) (domains.Domain, error
|
||||
d.Name = name
|
||||
}
|
||||
|
||||
alias, ok := data["alias"].(string)
|
||||
route, ok := data["route"].(string)
|
||||
if ok {
|
||||
d.Alias = alias
|
||||
d.Route = route
|
||||
}
|
||||
|
||||
itags, ok := data["tags"].([]interface{})
|
||||
|
||||
@@ -128,7 +128,6 @@ func (es *eventHandler) updateDomainHandler(ctx context.Context, data map[string
|
||||
domains.DomainReq{
|
||||
Name: &d.Name,
|
||||
Metadata: &d.Metadata,
|
||||
Alias: &d.Alias,
|
||||
Tags: &d.Tags,
|
||||
UpdatedBy: &d.UpdatedBy,
|
||||
UpdatedAt: &d.UpdatedAt,
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ type Domain struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Metadata Metadata `json:"metadata,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
Alias string `json:"alias,omitempty"`
|
||||
Route string `json:"route,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
Permission string `json:"permission,omitempty"`
|
||||
CreatedBy string `json:"created_by,omitempty"`
|
||||
|
||||
@@ -36,7 +36,7 @@ var (
|
||||
Name: authDomain.Name,
|
||||
Metadata: authDomain.Metadata,
|
||||
Tags: authDomain.Tags,
|
||||
Alias: authDomain.Alias,
|
||||
Route: authDomain.Route,
|
||||
}
|
||||
validRoles = []roles.MemberRoleActions{
|
||||
{
|
||||
@@ -50,7 +50,7 @@ var (
|
||||
Name: sdkDomain.Name,
|
||||
Metadata: sdkDomain.Metadata,
|
||||
Tags: sdkDomain.Tags,
|
||||
Alias: sdkDomain.Alias,
|
||||
Route: sdkDomain.Route,
|
||||
Roles: validRoles,
|
||||
}
|
||||
updatedDomianName = "updated-domain"
|
||||
@@ -127,7 +127,7 @@ func TestCreateDomain(t *testing.T) {
|
||||
Name: "",
|
||||
Metadata: sdkDomain.Metadata,
|
||||
Tags: sdkDomain.Tags,
|
||||
Alias: sdkDomain.Alias,
|
||||
Route: sdkDomain.Route,
|
||||
},
|
||||
svcReq: domains.Domain{},
|
||||
svcRes: domains.Domain{},
|
||||
@@ -2342,7 +2342,7 @@ func generateTestDomain(t *testing.T) (domains.Domain, sdk.Domain) {
|
||||
Name: "test-domain",
|
||||
Metadata: domains.Metadata(validMetadata),
|
||||
Tags: []string{"tag1", "tag2"},
|
||||
Alias: "test-alias",
|
||||
Route: "test-route",
|
||||
Status: domains.EnabledStatus,
|
||||
CreatedBy: ownerID,
|
||||
CreatedAt: createdAt,
|
||||
@@ -2356,7 +2356,7 @@ func generateTestDomain(t *testing.T) (domains.Domain, sdk.Domain) {
|
||||
Name: ad.Name,
|
||||
Metadata: validMetadata,
|
||||
Tags: ad.Tags,
|
||||
Alias: ad.Alias,
|
||||
Route: ad.Route,
|
||||
Status: ad.Status.String(),
|
||||
CreatedBy: ad.CreatedBy,
|
||||
CreatedAt: ad.CreatedAt,
|
||||
|
||||
Reference in New Issue
Block a user