Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions cmd/queryer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"os"

"github.com/L4B0MB4/EVTSRC/pkg/client"
tcpClient "github.com/L4B0MB4/EVTSRC/pkg/tcp/client"
"github.com/L4B0MB4/PRYVT/identification/pkg/query/eventhandling"
"github.com/L4B0MB4/PRYVT/identification/pkg/query/httphandler"
"github.com/L4B0MB4/PRYVT/identification/pkg/query/httphandler/controller"
Expand Down Expand Up @@ -32,21 +33,33 @@ func main() {
log.Error().Err(err).Msg("Unsuccessful initialization of client")
return
}
tokenManager, err := auth.NewTokenManager()
if err != nil {
log.Error().Err(err).Msg("Unsuccessful initialization of token manager")
return
}
eventRepo := utilsRepo.NewEventRepository(conn)
userRepo := repository.NewUserRepository(conn)
uc := controller.NewUserController(userRepo, tokenManager)
aut := auth.NewAuthMiddleware(tokenManager)
uc := controller.NewUserController(userRepo)
aut := auth.NewAuthMiddleware()
h := httphandler.NewHttpHandler(uc, aut)

userEventHandler := eventhandling.NewUserEventHandler(userRepo)

eventPolling := eventpolling.NewEventPolling(c, eventRepo, userEventHandler)
go eventPolling.PollEvents()

tcpC, err := tcpClient.NewTcpEventClient()
if err != nil {
log.Error().Err(err).Msg("Unsuccessful initialization of tcp client")
return
}
channel := make(chan string, 1)
go tcpC.ListenForEvents(channel)

eventPolling.PollEventsUntilEmpty()
go func() {
for {
select {
case event := <-channel:
log.Info().Msgf("Received event: %s", event)
eventPolling.PollEventsUntilEmpty()
}
}
}()
h.Start()
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ go 1.23.1
require github.com/mattn/go-sqlite3 v1.14.24

require (
github.com/L4B0MB4/EVTSRC v0.4.5 // indirect
github.com/PRYVT/utils v0.2.0 // indirect
github.com/L4B0MB4/EVTSRC v0.5.3 // indirect
github.com/PRYVT/utils v0.3.0 // indirect
github.com/bytedance/sonic v1.12.2 // indirect
github.com/bytedance/sonic/loader v0.2.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
Expand Down
24 changes: 24 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,38 @@ github.com/L4B0MB4/EVTSRC v0.4.0 h1:Y0/oEoMAv9kgGH/dgN9v1YBno6ZghXbWNPixScz9CX8=
github.com/L4B0MB4/EVTSRC v0.4.0/go.mod h1:hpyNdNWqikZ6dcm8dhZAXgnAXZQNGAfXgRw902zjby0=
github.com/L4B0MB4/EVTSRC v0.4.5 h1:HA4tp4fa/oCPTCl3gTD2FkRjo+nFKWm4rLmpudxcxXg=
github.com/L4B0MB4/EVTSRC v0.4.5/go.mod h1:hpyNdNWqikZ6dcm8dhZAXgnAXZQNGAfXgRw902zjby0=
github.com/L4B0MB4/EVTSRC v0.5.0-rc-1 h1:r8FLKDAnFh0rOZVXTqBB9uQRu800MpAQoszNpW9g+QQ=
github.com/L4B0MB4/EVTSRC v0.5.0-rc-1/go.mod h1:hpyNdNWqikZ6dcm8dhZAXgnAXZQNGAfXgRw902zjby0=
github.com/L4B0MB4/EVTSRC v0.5.0-rc-2 h1:fTuKRKwmhshP3PYkq1Gu/3pywAKcbGGUo/okhZEfGe8=
github.com/L4B0MB4/EVTSRC v0.5.0-rc-2/go.mod h1:hpyNdNWqikZ6dcm8dhZAXgnAXZQNGAfXgRw902zjby0=
github.com/L4B0MB4/EVTSRC v0.5.0-rc-3 h1:bI9Fhh0zq6zU3lVCYBynpYhZb91g1o4hsZ703RCMkn8=
github.com/L4B0MB4/EVTSRC v0.5.0-rc-3/go.mod h1:hpyNdNWqikZ6dcm8dhZAXgnAXZQNGAfXgRw902zjby0=
github.com/L4B0MB4/EVTSRC v0.5.0-rc-4 h1:gUFnWbNnxlk3yYKKs1ymjySYoVyDyWbk0cmXZ3vyWcg=
github.com/L4B0MB4/EVTSRC v0.5.0-rc-4/go.mod h1:hpyNdNWqikZ6dcm8dhZAXgnAXZQNGAfXgRw902zjby0=
github.com/L4B0MB4/EVTSRC v0.5.0-rc-5 h1:CT3eZqVq2b4ghoG5g5bvvrcXZUGVy3AQoV3NAZ12Al0=
github.com/L4B0MB4/EVTSRC v0.5.0-rc-5/go.mod h1:hpyNdNWqikZ6dcm8dhZAXgnAXZQNGAfXgRw902zjby0=
github.com/L4B0MB4/EVTSRC v0.5.1 h1:EB/lK0FTWtepToOtRFJdUhBf6tlb1L0bIRbRTMwArsQ=
github.com/L4B0MB4/EVTSRC v0.5.1/go.mod h1:hpyNdNWqikZ6dcm8dhZAXgnAXZQNGAfXgRw902zjby0=
github.com/L4B0MB4/EVTSRC v0.5.2 h1:bAOYlUmcZ2bg8rWIKnHLnxZPgXrPYyrQbtlz49BKlp4=
github.com/L4B0MB4/EVTSRC v0.5.2/go.mod h1:hpyNdNWqikZ6dcm8dhZAXgnAXZQNGAfXgRw902zjby0=
github.com/L4B0MB4/EVTSRC v0.5.3 h1:oD34lBIO4nY8Jvko8SmpITicbQipPUoKUn3AzBcDKKA=
github.com/L4B0MB4/EVTSRC v0.5.3/go.mod h1:hpyNdNWqikZ6dcm8dhZAXgnAXZQNGAfXgRw902zjby0=
github.com/PRYVT/utils v0.1.0 h1:Oq/sKHTKBVoAX+pLJMniYaZfv0ReDlQ+5E8qpKGiVjI=
github.com/PRYVT/utils v0.1.0/go.mod h1:RDgZFSTf1GPnpjVqnw0PSY68bzyp+WTK/wgAklOBFxY=
github.com/PRYVT/utils v0.1.1 h1:Y/WHkTHID0T40O2XfzlLM1QsDyQWE8FtH8ncaU4ags8=
github.com/PRYVT/utils v0.1.1/go.mod h1:b7zk2FAGwJ8BPJx2JQ8qd+bA59g5EY7Y1vZQPWZHK3s=
github.com/PRYVT/utils v0.1.2 h1:U9qhq+18iIblQDrM4I0fmJkvlZ+BCY+DIjjKI4ebtlk=
github.com/PRYVT/utils v0.1.2/go.mod h1:b7zk2FAGwJ8BPJx2JQ8qd+bA59g5EY7Y1vZQPWZHK3s=
github.com/PRYVT/utils v0.2.0-rc-1 h1:CwYscVZqozFxc8vdtZnoNv6XYfu7RPODZ7g3ecNvKPE=
github.com/PRYVT/utils v0.2.0-rc-1/go.mod h1:j61GmoyWWXgnCq/laZTIJm4yhD0PreLDMZnYQqjSv7w=
github.com/PRYVT/utils v0.2.0-rc-2 h1:7fp2kgp22HIQxBCNrYStxPuiReCwbgrqIuWCZ0pBsBM=
github.com/PRYVT/utils v0.2.0-rc-2/go.mod h1:j61GmoyWWXgnCq/laZTIJm4yhD0PreLDMZnYQqjSv7w=
github.com/PRYVT/utils v0.2.0 h1:hWdHchXlGOYlJ1nfMmGffq/EjFn3ncvzTgsGCLUpiEE=
github.com/PRYVT/utils v0.2.0/go.mod h1:j61GmoyWWXgnCq/laZTIJm4yhD0PreLDMZnYQqjSv7w=
github.com/PRYVT/utils v0.2.1 h1:GiTbziM3lqRLc4EWGV28+T/aKaY+B80KTqnkBklf9q0=
github.com/PRYVT/utils v0.2.1/go.mod h1:j61GmoyWWXgnCq/laZTIJm4yhD0PreLDMZnYQqjSv7w=
github.com/PRYVT/utils v0.3.0 h1:E0q08Gba+TdIsflKBA2XJLEE/RqbB8u3oXxy1wM7l+s=
github.com/PRYVT/utils v0.3.0/go.mod h1:j61GmoyWWXgnCq/laZTIJm4yhD0PreLDMZnYQqjSv7w=
github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0=
github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
github.com/bytedance/sonic v1.12.2 h1:oaMFuRTpMHYLpCntGca65YWt5ny+wAceDERTkT2L9lg=
Expand Down
15 changes: 7 additions & 8 deletions pkg/query/httphandler/controller/user_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ import (
)

type UserController struct {
userRepo *repository.UserRepository
tokenManager *auth.TokenManager
userRepo *repository.UserRepository
}

func NewUserController(userRepo *repository.UserRepository, tokenManager *auth.TokenManager) *UserController {
return &UserController{userRepo: userRepo, tokenManager: tokenManager}
func NewUserController(userRepo *repository.UserRepository) *UserController {
return &UserController{userRepo: userRepo}
}

func (ctrl *UserController) GetToken(c *gin.Context) {
Expand All @@ -32,7 +31,7 @@ func (ctrl *UserController) GetToken(c *gin.Context) {
userUuid := hash.GenerateGUID(tokenReq.UserName)

user, err := ctrl.userRepo.GetUserById(userUuid)
if err != nil {
if err != nil || user == nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "User not found"})
return
}
Expand All @@ -42,7 +41,7 @@ func (ctrl *UserController) GetToken(c *gin.Context) {
c.JSON(http.StatusUnauthorized, gin.H{"error": "Unauthorized"})
return
}
token, err := ctrl.tokenManager.CreateToken(userUuid)
token, err := auth.CreateToken(userUuid)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
Expand All @@ -52,12 +51,12 @@ func (ctrl *UserController) GetToken(c *gin.Context) {
func (ctrl *UserController) RefreshToken(c *gin.Context) {

tokenStr := auth.GetTokenFromHeader(c)
userUuid, err := ctrl.tokenManager.GetUserUuidFromToken(tokenStr)
userUuid, err := auth.GetUserUuidFromToken(tokenStr)
if err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": "Unauthorized"})
return
}
token, err := ctrl.tokenManager.CreateToken(userUuid)
token, err := auth.CreateToken(userUuid)

if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
Expand Down