Skip to content

Commit

Permalink
Merge pull request #48 from MZC-CSC/main
Browse files Browse the repository at this point in the history
user ticket and menu manage
  • Loading branch information
raccoon-mh authored Aug 29, 2024
2 parents 07e0aaa + a4a1d67 commit 639fa57
Show file tree
Hide file tree
Showing 15 changed files with 2,423 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ database.yml
scripts/nginx/
scripts/init/init.env
scripts/init/init.env

debugconsole/assets/*
9 changes: 8 additions & 1 deletion actions/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,15 @@ func App() *buffalo.App {
ticketPath.Middleware.Skip(middleware.IsTicketValidMiddleware, GetPermissionTicket, GetAllPermissions, GetAllAvailableMenus)
ticketPath.POST("/", GetPermissionTicket)
ticketPath.GET("/", GetAllPermissions)
ticketPath.GET("/menus", GetAllAvailableMenus)
ticketPath.GET("/framework/{framework}/menus", GetAllAvailableMenus)

userPath := app.Group(apiPath + "/user")
app.Middleware.Skip(middleware.IsAuthMiddleware, CreateUser)
app.Middleware.Skip(middleware.SetContextMiddleware, CreateUser)
app.Middleware.Skip(middleware.IsTicketValidMiddleware, CreateUser)
userPath.POST("/", CreateUser)
userPath.POST("/active", ActiveUser)
userPath.POST("/deactive", DeactiveUser)
userPath.GET("/", GetUsers)
userPath.PUT("/id/{userId}", UpdateUser)
userPath.DELETE("/id/{userId}", DeleteUser)
Expand Down Expand Up @@ -117,6 +122,7 @@ func App() *buffalo.App {

resourcePath := app.Group(apiPath + "/resource")
resourcePath.POST("/", CreateResources)
resourcePath.Middleware.Skip(middleware.IsTicketValidMiddleware, CreateApiResourcesByApiYaml, CreateMenuResourcesByMenuYaml)
resourcePath.POST("/file/framework/{framework}", CreateApiResourcesByApiYaml)
resourcePath.POST("/file/framework/{framework}/menu", CreateMenuResourcesByMenuYaml)
// resourcePath.POST("/file/framework/{framework}", CreateResourcesBySwagger) // deprecated : use CreateResourcesByApiYaml
Expand All @@ -136,6 +142,7 @@ func App() *buffalo.App {
permissionPath.PUT("/framewrok/{framework}/operationid/{operationid}", UpdateResourcePermissionByOperationId) // menu could use thie operation by menu Id
// permissionPath.PUT("/framewrok/{framework}/menu/{menu}", UpdateResourcePermissionByMenu)
// permissionPath.DELETE("/id/{permissionid}", DeletePermission) // deprecated : permission is resource dependent, When a resource is deleted, the permissions are also deleted.
permissionPath.Middleware.Skip(middleware.IsTicketValidMiddleware, GetCurrentPermissionCsv, ImportPermissionByCsv)
permissionPath.GET("/file/framework/{framework}", GetCurrentPermissionCsv)
permissionPath.POST("/file/framework/{framework}", ImportPermissionByCsv)

Expand Down
4 changes: 3 additions & 1 deletion actions/ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ func GetAllPermissions(c buffalo.Context) error {

func GetAllAvailableMenus(c buffalo.Context) error {
accessToken := c.Value("accessToken").(string)
ticketMenusPermissions, err := keycloak.KeycloakGetAvailableMenus(accessToken)
framework := c.Param("framework")

ticketMenusPermissions, err := keycloak.KeycloakGetAvailableMenus(accessToken, framework)
if err != nil {
log.Println(err)
return c.Render(http.StatusBadRequest, r.JSON(map[string]string{"error": err.Error()}))
Expand Down
50 changes: 50 additions & 0 deletions actions/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,56 @@ func CreateUser(c buffalo.Context) error {
return c.Render(http.StatusOK, r.JSON(map[string]string{"status": "success"}))
}

func ActiveUser(c buffalo.Context) error {
accessToken := c.Value("accessToken").(string)

activeReq := &keycloak.UserEnableStatusRequest{}
if err := c.Bind(activeReq); err != nil {
log.Println(err)
return c.Render(http.StatusBadRequest, r.JSON(map[string]string{"errors": err.Error()}))
}
validateErr := validate.Validate(
&validators.StringIsPresent{Field: activeReq.UserId, Name: "userId"},
)
if validateErr.HasAny() {
fmt.Println(validateErr)
return c.Render(http.StatusBadRequest, r.JSON(map[string]string{"message": validateErr.Error()}))
}

err := keycloak.KeycloakActiveUser(accessToken, activeReq.UserId)
if err != nil {
log.Println(err)
return c.Render(http.StatusBadRequest, r.JSON(map[string]string{"errors": err.Error()}))
}

return c.Render(http.StatusOK, r.JSON(map[string]string{"status": "success"}))
}

func DeactiveUser(c buffalo.Context) error {
accessToken := c.Value("accessToken").(string)

deactiveReq := &keycloak.UserEnableStatusRequest{}
if err := c.Bind(deactiveReq); err != nil {
log.Println(err)
return c.Render(http.StatusBadRequest, r.JSON(map[string]string{"errors": err.Error()}))
}
validateErr := validate.Validate(
&validators.StringIsPresent{Field: deactiveReq.UserId, Name: "userId"},
)
if validateErr.HasAny() {
fmt.Println(validateErr)
return c.Render(http.StatusBadRequest, r.JSON(map[string]string{"message": validateErr.Error()}))
}

err := keycloak.KeycloakDeactiveUser(accessToken, deactiveReq.UserId)
if err != nil {
log.Println(err)
return c.Render(http.StatusBadRequest, r.JSON(map[string]string{"errors": err.Error()}))
}

return c.Render(http.StatusOK, r.JSON(map[string]string{"status": "success"}))
}

func GetUsers(c buffalo.Context) error {
accessToken := c.Value("accessToken").(string)

Expand Down
24 changes: 24 additions & 0 deletions debugconsole/.air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# .air.toml

[build]
cmd = "go run ./src/server.go"
bin = "bin/main"
full_bin = "false"
include_ext = ["go", "tpl", "tmpl", "html", "js", "css"]
exclude_dir = ["assets", "node_modules"]
exclude_file = []
include_dir = []
log = "debug"
tmp_dir = "tmp"
full_bin = "false"

[log]
color = "true"
time = "true"

[watch]
delay = 1000
# Write your custom file/dir to watch, including the "go" and "non-go" files
full_bin = "false"
include = ["."]
exclude = ["assets", "node_modules"]
19 changes: 19 additions & 0 deletions debugconsole/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module debugconsole

go 1.21.6

require github.com/labstack/echo/v4 v4.12.0

require (
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
)
35 changes: 35 additions & 0 deletions debugconsole/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/labstack/echo/v4 v4.12.0 h1:IKpw49IMryVB2p1a4dzwlhP1O2Tf2E0Ir/450lH+kI0=
github.com/labstack/echo/v4 v4.12.0/go.mod h1:UP9Cr2DJXbOK3Kr9ONYzNowSh7HP0aG0ShAyycHSJvM=
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
21 changes: 21 additions & 0 deletions debugconsole/js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// axios 모듈 불러오기
const axios = require('axios');

// GET 요청 예제
axios.get('/proxy/ifconfig.me/get/')
.then(response => {
console.log('GET Response:@@@@', response.data);
})
.catch(error => {
console.error('Error in GET request:', error);
});

// // POST 요청 예제
// axios.post('http://ifconfig.me', )
// .then(response => {
// console.log('POST Response:', response.data);
// })
// .catch(error => {
// console.error('Error in POST request:', error);

// });
Loading

0 comments on commit 639fa57

Please sign in to comment.