From 3d8cd002563f0d91ebe4d2955fc9e1b8a2850490 Mon Sep 17 00:00:00 2001 From: Piotr Biernat Date: Thu, 6 Nov 2025 17:55:56 +0100 Subject: [PATCH] Refactoring --- .drone.yml | 62 ------------ .gitignore | 3 +- Makefile | 8 +- README.md | 4 +- deploy/.env.docker | 16 ++++ .../docker/Dockerfile.builder | 0 .../docker/Dockerfile.target | 0 deploy/{ => scripts}/image-build.sh | 6 +- deploy/{ => scripts}/image-push.sh | 0 src/app/app.go | 2 +- src/app/config.go | 3 - src/app/interface.go | 9 +- src/app/plugins.go | 94 ++++++++++++++----- src/app/scheduler.go | 14 +-- src/app/server.go | 16 ++-- src/cmd/scheduler/main.go | 8 +- src/cmd/server/main.go | 8 +- src/go.mod | 2 +- src/go.sum | 4 +- src/internal/http/health_handler.go | 2 +- src/internal/http/login_handler.go | 4 +- src/internal/service/auth.go | 10 +- src/internal/service/guard.go | 6 +- src/internal/ui/login_action.go | 4 +- 24 files changed, 133 insertions(+), 152 deletions(-) delete mode 100644 .drone.yml create mode 100644 deploy/.env.docker rename Dockerfile.builder => deploy/docker/Dockerfile.builder (100%) rename Dockerfile.target => deploy/docker/Dockerfile.target (100%) rename deploy/{ => scripts}/image-build.sh (75%) rename deploy/{ => scripts}/image-push.sh (100%) diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index 303b906..0000000 --- a/.drone.yml +++ /dev/null @@ -1,62 +0,0 @@ -kind: pipeline -type: docker -name: default - -steps: -- name: static_check - image: golang:latest - commands: - - go install honnef.co/go/tools/cmd/staticcheck@latest - - cd src && staticcheck ./... - volumes: - - name: gopath - path: /go - -- name: lint - image: golang:latest - commands: - - go install golang.org/x/lint/golint@latest - - golint ./src/... - volumes: - - name: gopath - path: /go - -- name: analyze - image: golang:latest - commands: - - cd src && go vet ./... - volumes: - - name: gopath - path: /go - -- name: publish_image - image: plugins/docker - environment: - DOCKER_USERNAME: - from_secret: registry_username - DOCKER_PASSWORD: - from_secret: registry_password - commands: - - sleep 5 - - ./deploy/image-build.sh - - ./deploy/image-push.sh - volumes: - - name: docker-sock - path: /var/run - when: - branch: - - main - -services: -- name: docker - image: docker:dind - privileged: true - volumes: - - name: docker-sock - path: /var/run - -volumes: -- name: gopath - temp: {} -- name: docker-sock - temp: {} diff --git a/.gitignore b/.gitignore index bd09b2f..c67d175 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ deploy/.env !deploy/.env.dist -deploy/.env.* +!deploy/.env.docker +deploy/.env.local deploy/server deploy/scheduler diff --git a/Makefile b/Makefile index 04959f9..0db3a28 100644 --- a/Makefile +++ b/Makefile @@ -2,16 +2,16 @@ DEPLOY_DIR := ./deploy SRC_DIR := ./src build-image-dev: - - sh ${DEPLOY_DIR}/image-build.sh dev + - sh ${DEPLOY_DIR}/scripts/image-build.sh dev build-image-prod: - - sh ${DEPLOY_DIR}/image-build.sh + - sh ${DEPLOY_DIR}/scripts/image-build.sh push-image-dev: - - sh ${DEPLOY_DIR}/image-push.sh dev + - sh ${DEPLOY_DIR}/scripts/image-push.sh dev push-image-prod: - - sh ${DEPLOY_DIR}/image-push.sh + - sh ${DEPLOY_DIR}/scripts/image-push.sh build-local-server: - go build -C ${SRC_DIR} -o ../deploy/server cmd/server/main.go diff --git a/README.md b/README.md index 3c731e6..1c34d25 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,9 @@ Prepare local dev environment ```ln -s PATH_TO_THE_STACK_DIR/deploy/certs/identity-svc/identity-svc.key deploy/certs/identity-svc.key``` 4. Build server app binary: - ```make build-local``` + ```make build-local-server``` 5. Run server app: - ```make run-local``` + ```make run-local-server``` Build prod image: $ make build-image-prod diff --git a/deploy/.env.docker b/deploy/.env.docker new file mode 100644 index 0000000..aacfac6 --- /dev/null +++ b/deploy/.env.docker @@ -0,0 +1,16 @@ +SERVER_ADDR=:443 + +APP_NAME=identity-svc +APP_DOMAIN=identity.service.ego.io + +API_DATABASE_URL=postgres://postgres:12345678@db-postgres:5432/egommerce +API_CACHE_ADDR=api-cache:6379 +API_CACHE_USERNAME=default +API_CACHE_PASSWORD=12345678 +API_MONGODB_URL=mongodb://mongodb:12345678@db-mongo:27017 + +JWT_ACCESS_TOKEN_SECRET_KEY=SomeFancySecretAndRandomString +JWT_ACCESS_TOKEN_EXPIRE_TIME=1 # hours + +JWT_REFRESH_TOKEN_SECRET_KEY=SomeFancySecretAndRandomStringAgain +JWT_REFRESH_TOKEN_EXPIRE_TIME=7 # days \ No newline at end of file diff --git a/Dockerfile.builder b/deploy/docker/Dockerfile.builder similarity index 100% rename from Dockerfile.builder rename to deploy/docker/Dockerfile.builder diff --git a/Dockerfile.target b/deploy/docker/Dockerfile.target similarity index 100% rename from Dockerfile.target rename to deploy/docker/Dockerfile.target diff --git a/deploy/image-build.sh b/deploy/scripts/image-build.sh similarity index 75% rename from deploy/image-build.sh rename to deploy/scripts/image-build.sh index 548831b..fb11f8c 100755 --- a/deploy/image-build.sh +++ b/deploy/scripts/image-build.sh @@ -11,7 +11,7 @@ TARGET=${1:-latest} [ ! -d "src/vendor" ] && sh -c "cd src; go mod vendor" echo "Building target $IMAGE_PREFIX images..." -docker build --rm -t $BUILDER_IMAGE -f Dockerfile.builder . +docker build --rm -t $BUILDER_IMAGE -f deploy/docker/Dockerfile.builder . if [ $TARGET = "latest" ] then @@ -23,7 +23,7 @@ then --build-arg BUILD_TIME \ --rm --cache-from $SERVER_IMAGE:$TARGET \ -t $SERVER_IMAGE:$TARGET \ - -f Dockerfile.target . > /dev/null 2>&1 && echo "Successfully tagged $SERVER_IMAGE:$TARGET" + -f deploy/docker/Dockerfile.target . > /dev/null 2>&1 && echo "Successfully tagged $SERVER_IMAGE:$TARGET" else # DEV docker build \ @@ -32,7 +32,7 @@ else --build-arg BUILDER_IMAGE=$BUILDER_IMAGE \ --build-arg BUILD_TIME \ --rm --no-cache -t $SERVER_IMAGE:$TARGET \ - -f Dockerfile.target . > /dev/null 2>&1 && echo "Successfully tagged $SERVER_IMAGE:$TARGET" + -f deploy/docker/Dockerfile.target . > /dev/null 2>&1 && echo "Successfully tagged $SERVER_IMAGE:$TARGET" fi echo "Done." diff --git a/deploy/image-push.sh b/deploy/scripts/image-push.sh similarity index 100% rename from deploy/image-push.sh rename to deploy/scripts/image-push.sh diff --git a/src/app/app.go b/src/app/app.go index ab0c1fb..03dd9b8 100644 --- a/src/app/app.go +++ b/src/app/app.go @@ -36,5 +36,5 @@ func (app *App) Shutdown() { } func (app *App) RegisterPlugin(plugin Plugin) { - app.worker.addPlugin(plugin.name, plugin.fn) + app.worker.addPlugin(plugin.name, plugin.connect, &app.worker) } diff --git a/src/app/config.go b/src/app/config.go index 3947ff8..3028827 100644 --- a/src/app/config.go +++ b/src/app/config.go @@ -16,7 +16,6 @@ const ( defCacheUsername = "default" defCachePassword = "12345678" defDbURL = "postgres://postgres:12345678@db-postgres:5432/egommerce" - defMongoDbURL = "mongodb://mongodb:12345678@db-mongo:27017" ) type Config struct { @@ -33,7 +32,6 @@ type Config struct { CacheAddr string `json:"cache_addr"` CacheUsername string `json:"cache_username"` CachePassword string `json:"cache_password"` - MongoDbUrl string `json:"mongodb_url"` } func NewConfig(name string) *Config { @@ -47,7 +45,6 @@ func NewConfig(name string) *Config { c.CacheUsername = cnf.GetEnv("API_CACHE_USERNAME", defCacheUsername) c.CachePassword = cnf.GetEnv("API_CACHE_PASSWORD", defCachePassword) c.DbURL = cnf.GetEnv("API_DATABASE_URL", defDbURL) - c.MongoDbUrl = cnf.GetEnv("API_MONGO_URL", defMongoDbURL) return c } diff --git a/src/app/interface.go b/src/app/interface.go index 3aa782b..32fe715 100644 --- a/src/app/interface.go +++ b/src/app/interface.go @@ -11,13 +11,6 @@ type ( Start() error OnShutdown() - addPlugin(name string, fn PluginFn) + addPlugin(name string, fn PluginConnectFn, w *WorkerInterface) } - - Plugin struct { - name string - fn PluginFn - } - - PluginFn func() any ) diff --git a/src/app/plugins.go b/src/app/plugins.go index cbc8510..2e34836 100644 --- a/src/app/plugins.go +++ b/src/app/plugins.go @@ -3,12 +3,19 @@ package app import ( "context" "log" - "os" "time" redis "github.com/go-redis/redis/v8" "github.com/jackc/pgx/v5/pgxpool" - db "github.com/jackc/pgx/v5/pgxpool" +) + +type ( + Plugin struct { + name string + connect PluginConnectFn + } + + PluginConnectFn func(w *WorkerInterface) any // returns connection handle ) type PluginManager struct { @@ -21,44 +28,83 @@ func NewPluginManager() *PluginManager { } } -func (pm *PluginManager) addPlugin(name string, fn PluginFn) { - pm.plugins[name] = fn() +func (pm *PluginManager) addPlugin(name string, fn PluginConnectFn, w *WorkerInterface) { + pm.plugins[name] = fn(w) } -func (pm *PluginManager) getCache() *redis.Client { +func (pm *PluginManager) GetCache() *redis.Client { return (pm.plugins["cache"]).(*redis.Client) } -func (pm *PluginManager) getDatabase() *pgxpool.Pool { +func (pm *PluginManager) GetDatabase() *pgxpool.Pool { return (pm.plugins["database"]).(*pgxpool.Pool) } -func CachePlugin(cnf *Config) Plugin { +func CachePlugin(cnf *Config, w WorkerInterface) Plugin { + connectFn := func(w WorkerInterface) *redis.Client { + log.Println("establishing api-cache connection...") + + return redis.NewClient(&redis.Options{ + Addr: cnf.CacheAddr, + Username: cnf.CacheUsername, + Password: cnf.CachePassword, + DB: 0, // TODO + DialTimeout: 100 * time.Millisecond, // TODO + }) + } + + // checking if the connection is still alive and try to reconnect when it is not + go func(conn *redis.Client) { + tick := time.NewTicker(5 * time.Second) // is 5 seconds is not too much? + defer tick.Stop() + + for range tick.C { + if err := conn.Ping(context.Background()).Err(); err != nil { + log.Println("lost connection with api-cache. Reconnecting...") + conn = connectFn(w) + } + } + }(connectFn(w)) + return Plugin{ name: "cache", - fn: func() any { - return redis.NewClient(&redis.Options{ - Addr: cnf.CacheAddr, - Username: cnf.CacheUsername, - Password: cnf.CachePassword, - DB: 0, // TODO - DialTimeout: 100 * time.Millisecond, // TODO - }) + connect: func(w *WorkerInterface) any { + return connectFn(*w) }, } } -func DatabasePlugin(cnf *Config) Plugin { +func DatabasePlugin(cnf *Config, w WorkerInterface) Plugin { + connectFn := func(w WorkerInterface) *pgxpool.Pool { + log.Println("establishing db-postgres connection...") + + conn, err := pgxpool.New(context.Background(), cnf.DbURL) + if err != nil { + log.Printf("failed to connect to the database: %s. Err: %s\n", cnf.DbURL, err.Error()) + return nil + // os.Exit(1) + } + + return conn + } + + // checking if the connection is still alive and try to reconnect when it is not + go func(conn *pgxpool.Pool) { + tick := time.NewTicker(5 * time.Second) // is 5 seconds is not too much? + defer tick.Stop() + + for range tick.C { + if err := conn.Ping(context.Background()); err != nil { + log.Println("lost connection with db-postgres. Reconnecting...") + conn = connectFn(w) + } + } + }(connectFn(w)) + return Plugin{ name: "database", - fn: func() any { - dbConn, err := db.New(context.Background(), cnf.DbURL) - if err != nil { - log.Fatalf("Failed to connect to the Database: %s. Err: %v\n", cnf.DbURL, err) - os.Exit(1) - } - - return dbConn + connect: func(w *WorkerInterface) any { + return connectFn(*w) }, } } diff --git a/src/app/scheduler.go b/src/app/scheduler.go index 22610c0..11cf5c9 100644 --- a/src/app/scheduler.go +++ b/src/app/scheduler.go @@ -22,11 +22,11 @@ func NewScheduler(c *Config) *Scheduler { } func (c *Scheduler) Start() error { // STILL NEEDS REFACTORING ;) - userRepo := repository.NewUserRepository(c.getDatabase()) - roleRepo := repository.NewRoleRepository(c.getDatabase()) - urlRepo := repository.NewURLAccessRepository(c.getDatabase()) - authSrv := service.NewAuthService(userRepo, c.getCache()) - guardSrv := service.NewGuardService(authSrv, c.getCache(), userRepo, roleRepo, urlRepo) + userRepo := repository.NewUserRepository(c.GetDatabase()) + roleRepo := repository.NewRoleRepository(c.GetDatabase()) + urlRepo := repository.NewURLAccessRepository(c.GetDatabase()) + authSrv := service.NewAuthService(userRepo, c.GetCache()) + guardSrv := service.NewGuardService(authSrv, c.GetCache(), userRepo, roleRepo, urlRepo) job := scheduler.NewCachePermissionsJob(guardSrv) sch := clockwerk.New() @@ -39,6 +39,6 @@ func (c *Scheduler) Start() error { // STILL NEEDS REFACTORING ;) func (c *Scheduler) OnShutdown() { log.Println("Scheduler is going down...") - c.getDatabase().Close() - c.getCache().Close() + c.GetDatabase().Close() + c.GetCache().Close() } diff --git a/src/app/server.go b/src/app/server.go index fc3de8c..a28244f 100644 --- a/src/app/server.go +++ b/src/app/server.go @@ -61,7 +61,7 @@ func (s *Server) Start() error { crt, err := tls.LoadX509KeyPair("certs/identity-svc.crt", "certs/identity-svc.key") if err != nil { - log.Fatal(err) + log.Fatal("failed to load certificates: ", err) } tlsCnf := &tls.Config{Certificates: []tls.Certificate{crt}} @@ -74,8 +74,8 @@ func (s *Server) Start() error { func (s *Server) OnShutdown() { log.Printf("Server %s is going down...", s.ID) - s.getDatabase().Close() - s.getCache().Close() + s.GetDatabase().Close() + s.GetCache().Close() s.Shutdown() } @@ -84,13 +84,13 @@ func (s *Server) setupRouter() { s.Options("*", defaultCORS) s.Use(defaultCORS) - s.Get("/health", http.HealthHandlerFn(s.getDatabase(), s.getCache())) + s.Get("/health", http.HealthHandlerFn(s.GetDatabase(), s.GetCache())) s.Group("/v1"). - Post("/login", http.LoginHandlerFn(s.getDatabase(), s.getCache())). - Post("/refresh", http.RefreshHandlerFn(s.getDatabase(), s.getCache())). // add JWTProtected() and get token from Auth Bearer header not from the body? - Post("/register", http.RegisterHandlerFn(s.getDatabase(), s.getCache())). - Get("/access", JWTProtected(), http.AccessHandlerFn(s.getDatabase(), s.getCache())) + Post("/login", http.LoginHandlerFn(s.GetDatabase(), s.GetCache())). + Post("/refresh", http.RefreshHandlerFn(s.GetDatabase(), s.GetCache())). // add JWTProtected() and get token from Auth Bearer header not from the body? + Post("/register", http.RegisterHandlerFn(s.GetDatabase(), s.GetCache())). + Get("/access", JWTProtected(), http.AccessHandlerFn(s.GetDatabase(), s.GetCache())) } func (s *Server) setupMiddleware() { diff --git a/src/cmd/scheduler/main.go b/src/cmd/scheduler/main.go index d467495..225048f 100644 --- a/src/cmd/scheduler/main.go +++ b/src/cmd/scheduler/main.go @@ -15,10 +15,10 @@ func main() { } cnf := app.NewConfig("identity-scheduler") - w := app.NewScheduler(cnf) - a := app.NewApp(w) - a.RegisterPlugin(app.CachePlugin(cnf)) - a.RegisterPlugin(app.DatabasePlugin(cnf)) + srv := app.NewScheduler(cnf) + a := app.NewApp(srv) + a.RegisterPlugin(app.CachePlugin(cnf, srv)) + a.RegisterPlugin(app.DatabasePlugin(cnf, srv)) while := make(chan struct{}) err := a.Start(while) diff --git a/src/cmd/server/main.go b/src/cmd/server/main.go index 644302e..a4058dc 100644 --- a/src/cmd/server/main.go +++ b/src/cmd/server/main.go @@ -15,10 +15,10 @@ func main() { } cnf := app.NewConfig("identity-svc") - w := app.NewServer(cnf) - a := app.NewApp(w) - a.RegisterPlugin(app.CachePlugin(cnf)) - a.RegisterPlugin(app.DatabasePlugin(cnf)) + srv := app.NewServer(cnf) + a := app.NewApp(srv) + a.RegisterPlugin(app.CachePlugin(cnf, srv)) + a.RegisterPlugin(app.DatabasePlugin(cnf, srv)) while := make(chan struct{}) err := a.Start(while) diff --git a/src/go.mod b/src/go.mod index d9c1ada..9121628 100644 --- a/src/go.mod +++ b/src/go.mod @@ -5,7 +5,7 @@ go 1.24.0 toolchain go1.24.1 require ( - git.ego.freeddns.org/egommerce/api-entities v0.3.34 + git.ego.freeddns.org/egommerce/api-entities v0.3.36 git.ego.freeddns.org/egommerce/go-api-pkg v0.5.3 github.com/georgysavva/scany/v2 v2.1.4 github.com/go-pg/migrations/v8 v8.1.0 diff --git a/src/go.sum b/src/go.sum index 5a48424..d818c5a 100644 --- a/src/go.sum +++ b/src/go.sum @@ -1,6 +1,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -git.ego.freeddns.org/egommerce/api-entities v0.3.34 h1:WftM9cvV3JmbS1DlHCIiV3tsYIpALj9IXo90mkgZNWQ= -git.ego.freeddns.org/egommerce/api-entities v0.3.34/go.mod h1:IqynARw+06GOm4eZGZuepmbi7bUxWBnOB4jd5cI7jf8= +git.ego.freeddns.org/egommerce/api-entities v0.3.36 h1:vqIR7CCcRmO7xBpRUnmQuF0DlXozpbBf5w7ud62otvw= +git.ego.freeddns.org/egommerce/api-entities v0.3.36/go.mod h1:IqynARw+06GOm4eZGZuepmbi7bUxWBnOB4jd5cI7jf8= git.ego.freeddns.org/egommerce/go-api-pkg v0.5.3 h1:so+OWWVJEg6JZ5XOSmCpfW7Pd7IL6ETH0QsC6zCwndo= git.ego.freeddns.org/egommerce/go-api-pkg v0.5.3/go.mod h1:T3ia8iprzlTRznPVXYCgEzQb/1UvIcdn9FHabE58vy0= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= diff --git a/src/internal/http/health_handler.go b/src/internal/http/health_handler.go index c9a2e95..1852084 100644 --- a/src/internal/http/health_handler.go +++ b/src/internal/http/health_handler.go @@ -15,7 +15,7 @@ type HealthResponse struct { func HealthHandlerFn(db *pgxpool.Pool, cache *redis.Client) fiber.Handler { return func(c *fiber.Ctx) error { - // Only 404 indicate service as not-healthy + // Default behavior of k8s is only 404 indicate service as not-healthy err := db.Ping(context.Background()) if err != nil { return c.SendStatus(http.StatusNotFound) diff --git a/src/internal/http/login_handler.go b/src/internal/http/login_handler.go index 9c83593..6950c0c 100644 --- a/src/internal/http/login_handler.go +++ b/src/internal/http/login_handler.go @@ -18,7 +18,6 @@ func LoginHandlerFn(db *pgxpool.Pool, cache *redis.Client) fiber.Handler { req := new(identityDTO.AuthLoginRequestDTO) if err := c.BodyParser(req); err != nil { return c.Status(fiber.StatusBadRequest).JSON(&commonDTO.ErrorResponseDTO{Error: "error parsing input"}) - // return srv.Error(c, fiber.StatusBadRequest, "error parsing input") } userRepo := repository.NewUserRepository(db) @@ -26,8 +25,7 @@ func LoginHandlerFn(db *pgxpool.Pool, cache *redis.Client) fiber.Handler { token, err := ui.NewLoginActionUI(authSrv).Execute(req) if err != nil { // TODO: handle other response status codes -- add struct to decorate error with code and message - return c.Status(fiber.StatusBadRequest).JSON(commonDTO.ErrorResponseDTO{Error: err.Error()}) - // return srv.Error(c, fiber.StatusBadRequest, err.Error()) + return c.Status(fiber.StatusBadRequest).JSON(&commonDTO.ErrorResponseDTO{Error: err.Error()}) } return c.JSON(&identityDTO.AuthLoginResponseDTO{Token: token}) diff --git a/src/internal/service/auth.go b/src/internal/service/auth.go index 521e5dc..f4776a2 100644 --- a/src/internal/service/auth.go +++ b/src/internal/service/auth.go @@ -43,11 +43,6 @@ func NewAuthService(userRepo repository.UserRepositoryInterface, cache *redis.Cl func (a *AuthService) Login(login, passwd string) (string, error) { user, err := a.userRepo.FindByUsername(login) if err != nil { - // TODO place code below in better place... - // if err = database.NoRowsInQuerySet(err); err != nil { - // return "", errors.New("no user found") - // } - return "", ErrLoginIncorrect } @@ -61,7 +56,6 @@ func (a *AuthService) Login(login, passwd string) (string, error) { return "", ErrUnableToCacheToken } - // REFACTOR: save uid in cache under "user:$ACCES_TOKEN" key res := a.cache.Set(context.Background(), "user:"+accessToken, user.ID, accessTokenExpireTime) if err := res.Err(); err != nil { fmt.Println("failed to save user:$ACCESS_TOKEN in cache: ", err.Error()) @@ -73,8 +67,8 @@ func (a *AuthService) Login(login, passwd string) (string, error) { } func (a *AuthService) RefreshToken(accessToken string) (string, error) { - // POSSIBLE BIG SECURITY ISSUE- WHEN REFRESH WITH ABANDONED (or EXPIRED) - // ACCESS TOKEN WE GET NEW ACCESS TOKEN + // POSSIBLE BIG SECURITY ISSUE - WHEN REFRESH WITH ABANDONED (or EXPIRED) + // ACCESS TOKEN WE CAN GET A NEW ACCESS TOKEN token, claims, err := jwtSrv.ValidateAccessToken(accessToken) if err != nil || !token.Valid { return "", ErrInvalidAccessToken diff --git a/src/internal/service/guard.go b/src/internal/service/guard.go index 24942d0..19ab48e 100644 --- a/src/internal/service/guard.go +++ b/src/internal/service/guard.go @@ -15,19 +15,19 @@ import ( type GuardService struct { authSrv *AuthService - cache *redis.Client userRepo *repository.UserRepository roleRepo *repository.RoleRepository urlRepo *repository.URLAccessRepository + cache *redis.Client } func NewGuardService(authSrv *AuthService, cache *redis.Client, userRepo *repository.UserRepository, roleRepo *repository.RoleRepository, urlRepo *repository.URLAccessRepository) *GuardService { return &GuardService{ authSrv: authSrv, - cache: cache, userRepo: userRepo, roleRepo: roleRepo, urlRepo: urlRepo, + cache: cache, } } @@ -78,5 +78,3 @@ func (g *GuardService) CacheAllPermissions() error { return nil } - -// func (g *GuardService) fetchURLAccessFromCache() {} diff --git a/src/internal/ui/login_action.go b/src/internal/ui/login_action.go index 7e6d468..dba2b6c 100644 --- a/src/internal/ui/login_action.go +++ b/src/internal/ui/login_action.go @@ -15,8 +15,8 @@ func NewLoginActionUI(authSrv *service.AuthService) *LoginActionUI { } } -func (ui *LoginActionUI) Execute(data *identityDTO.AuthLoginRequestDTO) (string, error) { - token, err := ui.authSrv.Login(data.Username, data.Password) +func (ui *LoginActionUI) Execute(dto *identityDTO.AuthLoginRequestDTO) (string, error) { + token, err := ui.authSrv.Login(dto.Username, dto.Password) if err != nil { // TODO: handle other response status codes -- add struct to decorate error with code and message if err == service.ErrUnableToCacheToken {