mirror of
https://github.com/grassrootseconomics/cic-custodial.git
synced 2024-12-22 01:47:31 +01:00
feat: add system global lock to be triggered manually
This commit is contained in:
parent
ad58d1da47
commit
ee907dddbc
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,4 @@
|
||||
cic-custodial
|
||||
dist
|
||||
.env
|
||||
**/*.env
|
||||
covprofile
|
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
@ -10,10 +11,12 @@ import (
|
||||
"github.com/grassrootseconomics/cic-custodial/internal/custodial"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v4/middleware"
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
const (
|
||||
contextTimeout = 5 * time.Second
|
||||
contextTimeout = 5 * time.Second
|
||||
systemGlobalLockKey = "system:global_lock"
|
||||
)
|
||||
|
||||
// Bootstrap API server.
|
||||
@ -47,6 +50,9 @@ func initApiServer(custodialContainer *custodial.Custodial) *echo.Echo {
|
||||
}
|
||||
|
||||
apiRoute := server.Group("/api")
|
||||
|
||||
apiRoute.Use(systemGlobalLock)
|
||||
|
||||
apiRoute.POST("/account/create", api.HandleAccountCreate)
|
||||
apiRoute.POST("/sign/transfer", api.HandleSignTransfer)
|
||||
apiRoute.GET("/track/:trackingId", api.HandleTrackTx)
|
||||
@ -81,3 +87,25 @@ func customHTTPErrorHandler(err error, c echo.Context) {
|
||||
Message: "Internal server error.",
|
||||
})
|
||||
}
|
||||
|
||||
func systemGlobalLock(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
var (
|
||||
cu = c.Get("cu").(*custodial.Custodial)
|
||||
)
|
||||
|
||||
locked, err := cu.RedisClient.Get(c.Request().Context(), systemGlobalLockKey).Bool()
|
||||
if !errors.Is(err, redis.Nil) {
|
||||
return err
|
||||
}
|
||||
|
||||
if locked {
|
||||
return c.JSON(http.StatusOK, api.ErrResp{
|
||||
Ok: false,
|
||||
Message: "System manually locked.",
|
||||
})
|
||||
}
|
||||
|
||||
return next(c)
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
version: "3.9"
|
||||
services:
|
||||
redis:
|
||||
image: redis:6-alpine
|
||||
image: redis:7-alpine
|
||||
restart: unless-stopped
|
||||
command: redis-server --save 60 1 --loglevel warning
|
||||
volumes:
|
||||
@ -20,9 +20,9 @@ services:
|
||||
environment:
|
||||
- POSTGRES_PASSWORD=postgres
|
||||
- POSTGRES_USER=postgres
|
||||
- POSTGRES_DB=cic_custodial
|
||||
volumes:
|
||||
- cic-custodial-pg:/var/lib/postgresql/data
|
||||
- ./init_db.sql:/docker-entrypoint-initdb.d/init_db.sql
|
||||
ports:
|
||||
- "127.0.0.1:5432:5432"
|
||||
healthcheck:
|
||||
@ -37,8 +37,8 @@ services:
|
||||
volumes:
|
||||
- cic-custodial-nats:/nats/data
|
||||
ports:
|
||||
- "4222:4222"
|
||||
- "8222:8222"
|
||||
- "127.0.0.1:4222:4222"
|
||||
- "127.0.0.1:8222:8222"
|
||||
asynqmon:
|
||||
image: hibiken/asynqmon
|
||||
restart: unless-stopped
|
||||
@ -49,6 +49,16 @@ services:
|
||||
depends_on:
|
||||
redis:
|
||||
condition: service_healthy
|
||||
cic-chain-events:
|
||||
image: ghcr.io/grassrootseconomics/cic-chain-events/cic-chain-events:latest
|
||||
restart: unless-stopped
|
||||
env_file:
|
||||
- events.env
|
||||
ports:
|
||||
- '127.0.0.1:5001:5000'
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
volumes:
|
||||
cic-custodial-pg:
|
||||
driver: local
|
2
dev/init_db.sql
Normal file
2
dev/init_db.sql
Normal file
@ -0,0 +1,2 @@
|
||||
CREATE DATABASE cic_custodial;
|
||||
CREATE DATABASE cic_chain_events;
|
Loading…
Reference in New Issue
Block a user