Skip to content

Commit

Permalink
MG-1962 - add single endpoint to change status of domain
Browse files Browse the repository at this point in the history
Signed-off-by: Janael Pinheiro <ajp@cesar.org.br>
  • Loading branch information
janael-pinheiro authored and AntonioJanael committed Mar 27, 2024
1 parent 70c3d65 commit 417666b
Show file tree
Hide file tree
Showing 17 changed files with 335 additions and 329 deletions.
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:
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
47 changes: 14 additions & 33 deletions auth/api/http/domains/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,58 +115,39 @@ func listDomainsEndpoint(svc auth.Service) endpoint.Endpoint {
}
}

func enableDomainEndpoint(svc auth.Service) endpoint.Endpoint {
func statusDomainEndpoint(svc auth.Service) endpoint.Endpoint {
changeStatusMapping := make(map[string]auth.Status)
changeStatusMapping[auth.Enabled] = auth.EnabledStatus
changeStatusMapping[auth.Disabled] = auth.DisabledStatus
changeStatusMapping[auth.Freezed] = auth.FreezeStatus
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
status := changeStatusMapping[req.Status]
d := auth.DomainReq{
Status: &enable,
Status: &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 150 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 151 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 {
Expand Down
Loading

0 comments on commit 417666b

Please sign in to comment.