Skip to content

Commit

Permalink
Add disabled to action API and moved cond to UI routes
Browse files Browse the repository at this point in the history
  • Loading branch information
marshyski committed Oct 27, 2024
1 parent f38a064 commit f787c2f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pal-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ jobs:
echo
make lint
- name: Build pal Binary
- name: Build pal Binary and Packages
run: |
make linux
make pkg
file ./pal
du -sh ./pal
sha256sum ./pal
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ docker:
-e HTTP_AUTH_HEADER='X-Pal-Auth PaLLy!@#890-' -e HTTP_SESSION_SECRET='P@llY^S3$$h' -e DB_ENCRYPT_KEY='8c755319-fd2a-4a89-b0d9-ae7b8d26' \
--health-cmd 'curl -sfk https://127.0.0.1:8443/v1/pal/health || exit 1' --restart=unless-stopped pal:latest

pkg: linux
VERSION=$(VERSION) ARCH=amd64 nfpm pkg --packager deb --target ./
VERSION=$(VERSION) ARCH=amd64 nfpm pkg --packager rpm --target ./
$(MAKE) arm64
pkg: arm64
VERSION=$(VERSION) ARCH=arm64 nfpm pkg --packager deb --target ./
VERSION=$(VERSION) ARCH=arm64 nfpm pkg --packager rpm --target ./
$(MAKE) linux
VERSION=$(VERSION) ARCH=amd64 nfpm pkg --packager deb --target ./
VERSION=$(VERSION) ARCH=amd64 nfpm pkg --packager rpm --target ./

vagrant: pkg
vagrant destroy -f || true
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ make docker
#### Generate random secrets for one-time use

```bash
sudo docker run -d --name=pal -p 8443:8443 \
--health-cmd 'curl -sfk https://127.0.0.1:8443/v1/pal/health || exit 1' --restart=unless-stopped pal:latest
sudo docker run -d --name=pal -p 8443:8443 --health-cmd 'curl -sfk https://127.0.0.1:8443/v1/pal/health || exit 1' --restart=unless-stopped pal:latest

# See generated random secrets
sudo docker logs pal
Expand Down Expand Up @@ -275,10 +274,12 @@ Get action configuration including last_output and other run stats.

```
GET /v1/pal/action?group={{ group }}&action={{ action }}
GET /v1/pal/action?group={{ group }}&action={{ action }}&disabled={{ boolean }}
```

- `group` (**Required**): group name
- `action` (**Required**): action name
- `disabled` (**Optional**): disabled boolean

## Configurations

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ Documentation: https://github.com/marshyski/pal
e.PUT("/v1/pal/notifications", routes.PutNotifications)
e.GET("/v1/pal/run/:group/:action", routes.RunGroup)
e.POST("/v1/pal/run/:group/:action", routes.RunGroup)
e.GET("/v1/pal/cond/:group/:action", routes.GetCond)
e.GET("/v1/pal/action", routes.GetAction)

// Setup UI Routes Only If Basic Auth Isn't Empty
Expand Down Expand Up @@ -224,6 +223,7 @@ Documentation: https://github.com/marshyski/pal
e.GET("/v1/pal/ui/static/*", echo.WrapHandler(http.StripPrefix("/v1/pal/ui/static/", http.FileServer(http.FS(uiFS)))))
e.GET("/favicon.ico", routes.GetFavicon)
e.GET("/robots.txt", routes.GetRobots)
e.GET("/v1/pal/cond/:group/:action", routes.GetCond)
e.GET("/v1/pal/ui", routes.GetActionsPage)
e.GET("/v1/pal/ui/login", routes.GetLoginPage)
e.POST("/v1/pal/ui/login", routes.PostLoginPage)
Expand Down
16 changes: 13 additions & 3 deletions routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,7 @@ func GetHealth(c echo.Context) error {

func GetCond(c echo.Context) error {
if !sessionValid(c) {
if !authHeaderCheck(c.Request().Header) {
return c.JSON(http.StatusUnauthorized, data.GenericResponse{Err: "Unauthorized no valid session or auth header present."})
}
return c.JSON(http.StatusUnauthorized, data.GenericResponse{Err: "Unauthorized no valid session or auth header present."})
}

disable := c.QueryParam("disable")
Expand Down Expand Up @@ -834,6 +832,18 @@ func GetAction(c echo.Context) error {
return c.JSON(http.StatusBadRequest, data.GenericResponse{Err: errorAction})
}

disable := c.QueryParam("disabled")
if disable != "" {
state := false

if disable == "true" {
state = true
}

condDisable(group, action, state)
return c.JSON(http.StatusOK, data.GenericResponse{Message: fmt.Sprintf("changed action state %s/%s disabled to %s", group, action, disable)})
}

resMap := db.DBC.GetGroups()

for _, e := range resMap[group] {
Expand Down

0 comments on commit f787c2f

Please sign in to comment.