Skip to content

Commit

Permalink
adjust roles and permission acl lists
Browse files Browse the repository at this point in the history
  • Loading branch information
febrihidayan committed Jan 19, 2024
1 parent f714c5f commit efcd810
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 48 deletions.
31 changes: 29 additions & 2 deletions krakend/krakend.json
Original file line number Diff line number Diff line change
Expand Up @@ -383,13 +383,40 @@
}
},
{
"endpoint": "/v1/auth/acl",
"endpoint": "/v1/auth/acl/permissions",
"method": "GET",
"input_headers": ["Authorization"],
"output_encoding": "no-op",
"backend": [
{
"url_pattern": "/v1/auth/acl",
"url_pattern": "/v1/auth/acl/permissions",
"host": [
"http://auth-go:8083"
],
"extra_config": {
"backend/http": {
"return_error_code": true
}
}
}
],
"extra_config": {
"auth/validator": {
"alg": "HS256",
"jwk_url": "http://fake_api:8080/jwk/symmetric.json",
"roles": ["superadministrator", "administrator"],
"disable_jwk_security": true
}
}
},
{
"endpoint": "/v1/auth/acl/roles",
"method": "GET",
"input_headers": ["Authorization"],
"output_encoding": "no-op",
"backend": [
{
"url_pattern": "/v1/auth/acl/roles",
"host": [
"http://auth-go:8083"
],
Expand Down
3 changes: 2 additions & 1 deletion services/auth/domain/usecases/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
)

type AclUsecase interface {
GetAll(ctx context.Context) (*entities.AclMeta, *exceptions.CustomError)
GetAllRole(ctx context.Context) ([]*entities.Role, *exceptions.CustomError)
GetAllPermission(ctx context.Context) ([]*entities.Permission, *exceptions.CustomError)
GetAllUser(ctx context.Context, userId string) (*entities.AclMeta, *exceptions.CustomError)
UpdateUser(ctx context.Context, payload entities.AclUserDto) *exceptions.CustomError
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package acl_handler

import (
"context"
"net/http"

"github.com/febrihidayan/go-architecture-monorepo/pkg/exceptions"
"github.com/febrihidayan/go-architecture-monorepo/pkg/utils"
"github.com/febrihidayan/go-architecture-monorepo/services/auth/internal/delivery/http/response"
)

func (x *aclHttpHandler) GetAllPermission(w http.ResponseWriter, r *http.Request) {
var (
ctx = context.Background()
)

results, err := x.aclUsecase.GetAllPermission(ctx)
if err != nil {
utils.RespondWithError(w, exceptions.MapToHttpStatusCode(err.Status), err.Errors.Errors)
return
}

utils.RespondWithJSON(w, http.StatusOK, response.MapPermissionListResponses(results))
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import (
"github.com/febrihidayan/go-architecture-monorepo/services/auth/internal/delivery/http/response"
)

func (x *aclHttpHandler) GetAll(w http.ResponseWriter, r *http.Request) {
func (x *aclHttpHandler) GetAllRole(w http.ResponseWriter, r *http.Request) {
var (
ctx = context.Background()
)

results, err := x.aclUsecase.GetAll(ctx)
results, err := x.aclUsecase.GetAllRole(ctx)
if err != nil {
utils.RespondWithError(w, exceptions.MapToHttpStatusCode(err.Status), err.Errors.Errors)
return
}

utils.RespondWithJSON(w, http.StatusOK, response.MapAclListResponse(results))
utils.RespondWithJSON(w, http.StatusOK, response.MapRoleListResponses(results))
}
3 changes: 2 additions & 1 deletion services/auth/internal/delivery/http/delivery/acl/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ func AclHttpHandler(
),
}

r.HandleFunc("/v1/auth/acl", handler.GetAll).Methods("GET")
r.HandleFunc("/v1/auth/acl/roles", handler.GetAllRole).Methods("GET")
r.HandleFunc("/v1/auth/acl/permissions", handler.GetAllPermission).Methods("GET")
r.HandleFunc("/v1/auth/acl/access", handler.Access).Methods("GET")
r.HandleFunc("/v1/auth/acl/user/{id}", handler.GetAllUser).Methods("GET")
r.HandleFunc("/v1/auth/acl/user/{id}", handler.UpdateUser).Methods("PUT")
Expand Down
41 changes: 0 additions & 41 deletions services/auth/internal/usecases/acl/get_all.go

This file was deleted.

28 changes: 28 additions & 0 deletions services/auth/internal/usecases/acl/get_all_permission.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package acl

import (
"context"
"log"

"github.com/febrihidayan/go-architecture-monorepo/pkg/exceptions"
"github.com/febrihidayan/go-architecture-monorepo/services/auth/domain/entities"
"github.com/hashicorp/go-multierror"
)

func (x *aclInteractor) GetAllPermission(ctx context.Context) ([]*entities.Permission, *exceptions.CustomError) {
var multilerr *multierror.Error

permissions, err := x.permissionRepo.All(ctx)
if err != nil {
log.Println("GetAllPermission::error#1:", err)
multilerr = multierror.Append(multilerr, err)
return nil, &exceptions.CustomError{
Status: exceptions.ERRREPOSITORY,
Errors: multilerr,
}
}

log.Println("GetAllPermission::success#1:", "successfully")

return permissions, nil
}
28 changes: 28 additions & 0 deletions services/auth/internal/usecases/acl/get_all_role.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package acl

import (
"context"
"log"

"github.com/febrihidayan/go-architecture-monorepo/pkg/exceptions"
"github.com/febrihidayan/go-architecture-monorepo/services/auth/domain/entities"
"github.com/hashicorp/go-multierror"
)

func (x *aclInteractor) GetAllRole(ctx context.Context) ([]*entities.Role, *exceptions.CustomError) {
var multilerr *multierror.Error

roles, err := x.roleRepo.All(ctx)
if err != nil {
log.Println("GetAllRole::error#1:", err)
multilerr = multierror.Append(multilerr, err)
return nil, &exceptions.CustomError{
Status: exceptions.ERRREPOSITORY,
Errors: multilerr,
}
}

log.Println("GetAllRole::success#1:", "successfully")

return roles, nil
}

0 comments on commit efcd810

Please sign in to comment.