Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MG-1962 - Add single endpoint to change status of domain #2127

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 22 additions & 59 deletions api/openapi/auth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,74 +175,23 @@ paths:
description: Database can't process request.
"500":
$ref: "#/components/responses/ServiceError"
/domains/{domainID}/enable:
post:
summary: Enables a domain
description: |
Enables a specific domain that is identified by the domain ID.
tags:
- Domains
parameters:
- $ref: "#/components/parameters/DomainID"
security:
- bearerAuth: []
responses:
"200":
description: Successfully enabled domain.
"400":
description: Failed due to malformed domain's ID.
"401":
description: Missing or invalid access token provided.
"403":
description: Unauthorized access the domain ID.
"404":
description: A non-existent entity request.
"422":
description: Database can't process request.
"500":
$ref: "#/components/responses/ServiceError"

/domains/{domainID}/disable:
post:
summary: Disable a domain
/domains/{domainID}/status:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is important to have one endpoint? It looks more self-documenting to me that way, than having sing status endpoint - which usually prompt me that it is status indicator (i.e. something I would use with GET to fetch the current status), and not a control switch.

put:
summary: changes the domain status
description: |
Disable a specific domain that is identified by the domain ID.
tags:
- Domains
parameters:
- $ref: "#/components/parameters/DomainID"
security:
- bearerAuth: []
responses:
"200":
description: Successfully disabled domain.
"400":
description: Failed due to malformed domain's ID.
"401":
description: Missing or invalid access token provided.
"403":
description: Unauthorized access the domain ID.
"404":
description: A non-existent entity request.
"422":
description: Database can't process request.
"500":
$ref: "#/components/responses/ServiceError"

/domains/{domainID}/freeze:
post:
summary: Freeze a domain
description: |
Freeze a specific domain that is identified by the domain ID.
Changes a specific domain status that is identified by the domain ID.
tags:
- Domains
parameters:
- $ref: "#/components/parameters/DomainID"
requestBody:
$ref: "#/components/requestBodies/DomainStatusUpdateReq"
security:
- bearerAuth: []
responses:
"200":
description: Successfully freezed domain.
description: Successfully enabled domain.
"400":
description: Failed due to malformed domain's ID.
"401":
Expand All @@ -255,7 +204,7 @@ paths:
description: Database can't process request.
"500":
$ref: "#/components/responses/ServiceError"

/domains/{domainID}/users/assign:
post:
summary: Assign users to domain
Expand Down Expand Up @@ -594,6 +543,13 @@ components:
type: string
example: domain alias
description: Domain alias.
DomainStatusUpdate:
type: object
properties:
status:
type: string
example: enabled
description: Domain status.
Permissions:
type: object
properties:
Expand Down Expand Up @@ -783,6 +739,13 @@ components:
application/json:
schema:
$ref: "#/components/schemas/DomainUpdate"
DomainStatusUpdateReq:
description: JSON-formated document describing the domain status to be updated
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/DomainStatusUpdate"
AssignUserReq:
description: JSON-formated document describing the policy related to assigning users to a domain
required: true
Expand Down
18 changes: 7 additions & 11 deletions auth/api/http/domains/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,23 @@ func decodeListDomainRequest(ctx context.Context, r *http.Request) (interface{},
return req, nil
}

func decodeEnableDomainRequest(_ context.Context, r *http.Request) (interface{}, error) {
req := enableDomainReq{
func decodeStatusDomainRequest(_ context.Context, r *http.Request) (interface{}, error) {
req := statusDomainReq{
token: apiutil.ExtractBearerToken(r),
domainID: chi.URLParam(r, "domainID"),
}
return req, nil
}

func decodeDisableDomainRequest(_ context.Context, r *http.Request) (interface{}, error) {
req := disableDomainReq{
token: apiutil.ExtractBearerToken(r),
domainID: chi.URLParam(r, "domainID"),
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
return nil, errors.Wrap(apiutil.ErrValidation, errors.Wrap(err, errors.ErrMalformedEntity))
}
return req, nil
}

func decodeFreezeDomainRequest(_ context.Context, r *http.Request) (interface{}, error) {
req := freezeDomainReq{
func decodeDeleteDomainRequest(_ context.Context, r *http.Request) (interface{}, error) {
req := deleteDomainReq{
token: apiutil.ExtractBearerToken(r),
domainID: chi.URLParam(r, "domainID"),
}

return req, nil
}

Expand Down
42 changes: 9 additions & 33 deletions auth/api/http/domains/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,59 +115,35 @@
}
}

func enableDomainEndpoint(svc auth.Service) endpoint.Endpoint {
func statusDomainEndpoint(svc auth.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
req := request.(enableDomainReq)
req := request.(statusDomainReq)
if err := req.validate(); err != nil {
return nil, err
}

enable := auth.EnabledStatus
d := auth.DomainReq{
Status: &enable,
Status: &req.Status,
}
if _, err := svc.ChangeDomainStatus(ctx, req.token, req.domainID, d); err != nil {
return nil, err
}
return enableDomainRes{}, nil
return statusDomainRes{}, nil
}
}

func disableDomainEndpoint(svc auth.Service) endpoint.Endpoint {
func deleteDomainEndpoint(svc auth.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
req := request.(disableDomainReq)
req := request.(deleteDomainReq)
if err := req.validate(); err != nil {
return nil, err
}

disable := auth.DisabledStatus
d := auth.DomainReq{
Status: &disable,
}
if _, err := svc.ChangeDomainStatus(ctx, req.token, req.domainID, d); err != nil {
return nil, err
d := auth.Domain{
ID: req.domainID,
}
return disableDomainRes{}, nil
return nil, svc.DeleteDomain(ctx, req.token, d)
}
}

Check failure on line 145 in auth/api/http/domains/endpoint.go

View workflow job for this annotation

GitHub Actions / Lint and Build

File is not `gofumpt`-ed (gofumpt)
func freezeDomainEndpoint(svc auth.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
req := request.(freezeDomainReq)
if err := req.validate(); err != nil {
return nil, err
}

freeze := auth.FreezeStatus
d := auth.DomainReq{
Status: &freeze,
}
if _, err := svc.ChangeDomainStatus(ctx, req.token, req.domainID, d); err != nil {
return nil, err
}
return freezeDomainRes{}, nil
}
}

Check failure on line 146 in auth/api/http/domains/endpoint.go

View workflow job for this annotation

GitHub Actions / Lint and Build

unnecessary trailing newline (whitespace)

func assignDomainUsersEndpoint(svc auth.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
Expand Down
Loading
Loading