Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
FIX: Update docker-compose.prod.yml to use volume mounts for keys
Browse files Browse the repository at this point in the history
  • Loading branch information
930C committed Jan 18, 2024
1 parent 138b04a commit 1e92f3c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
8 changes: 5 additions & 3 deletions deployments/docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ services:

app:
image: "${SERVER_IMAGE:-ghcr.io/wwi21seb-projekt/server-alpha:main}" # It's possible to specify the image to use in the environment, default is the latest image from the github container registry
user: ${UID}:${GID}
restart: unless-stopped # Restart the container unless it was stopped by the user
depends_on:
- db
Expand All @@ -34,18 +35,19 @@ services:
- DB_NAME=${DB_NAME}
- DB_USER=${DB_USER}
- DB_PASS=${DB_PASS}
- JWT_PRIVATE_KEY=${JWT_PRIVATE_KEY}
- JWT_PUBLIC_KEY=${JWT_PUBLIC_KEY}
- MAILGUN_API_KEY=${MAILGUN_API_KEY}
ports:
- "${APP_PORT}:8080"
volumes:
- ${PWD}/private_key.pem:/private_key.pem
- ${PWD}/public_key.pem:/public_key.pem
networks:
- traefik_proxy
- default
labels:
- "traefik.enable=true"
- "traefik.http.routers.alpha.entrypoints=websecure"
- "traefik.http.routers.alpha.rule=Host(`alpha.c930.net`)"
- "traefik.http.routers.alpha.rule=Host(`server-alpha.tech`)"
- "traefik.http.routers.alpha.tls=true"
- "traefik.http.routers.alpha.tls.certresolver=default"
- "traefik.http.routers.alpha.middlewares=secHeaders@file"
Expand Down
8 changes: 5 additions & 3 deletions internal/routing/handlers/user_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,12 +522,14 @@ func (handler *UserHandler) Subscribe(w http.ResponseWriter, r *http.Request) {
var subscriptionId uuid.UUID
if err := rows.Scan(&subscriptionId); err != nil {
if !errors.Is(err, pgx.ErrNoRows) {
utils.WriteAndLogError(w, schemas.SubscriptionAlreadyExists, http.StatusConflict, err)
utils.WriteAndLogError(w, schemas.DatabaseError, http.StatusInternalServerError, err)
return
}
utils.WriteAndLogError(w, schemas.DatabaseError, http.StatusInternalServerError, err)
return
}

if subscriptionId != uuid.Nil {
utils.WriteAndLogError(w, schemas.SubscriptionAlreadyExists, http.StatusConflict, errors.New("subscription already exists"))
return
}

// Subscribe the user
Expand Down
12 changes: 7 additions & 5 deletions internal/routing/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func InitRouter(databaseMgr managers.DatabaseMgr, mailMgr managers.MailMgr, jwtM
})

// Initialize user routes
r.Route("/api/users", userRouter(&databaseMgr, &jwtMgr, &mailMgr))
r.Route("/api/users", userRouter(&databaseMgr, jwtMgr, &mailMgr))

// Initialize feed routes
r.Route("/api/feed", func(r chi.Router) {
Expand All @@ -97,16 +97,18 @@ func InitRouter(databaseMgr managers.DatabaseMgr, mailMgr managers.MailMgr, jwtM
return r
}

func userRouter(databaseMgr *managers.DatabaseMgr, jwtMgr *managers.JWTMgr, mailMgr *managers.MailMgr) func(chi.Router) {
func userRouter(databaseMgr *managers.DatabaseMgr, jwtMgr managers.JWTMgr, mailMgr *managers.MailMgr) func(chi.Router) {
return func(r chi.Router) {
userHdl := handlers.NewUserHandler(databaseMgr, jwtMgr, mailMgr)
userHdl := handlers.NewUserHandler(databaseMgr, &jwtMgr, mailMgr)

r.Post("/", userHdl.RegisterUser)
r.Put("/", userHdl.ChangeTrivialInformation)
r.Patch("/", userHdl.ChangePassword)
r.With(jwtMgr.JWTMiddleware).Get("/", userHdl.SearchUsers)
r.With(jwtMgr.JWTMiddleware).Put("/", userHdl.ChangeTrivialInformation)
r.With(jwtMgr.JWTMiddleware).Patch("/", userHdl.ChangePassword)
r.Post("/login", userHdl.LoginUser)
r.Post("/refresh", userHdl.RefreshToken)
r.Post("/{username}/activate", userHdl.ActivateUser)
r.Delete("/{username}/activate", userHdl.ResendToken)
r.With(jwtMgr.JWTMiddleware).Get("/{username}", userHdl.HandleGetUserRequest)
}
}
4 changes: 2 additions & 2 deletions internal/routing/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func TestUserRegistration(t *testing.T) {

// Assert that the response status code is 201 and the response body contains the expected values
expect := httpexpect.Default(t, server.URL)
request := expect.POST("/api/v1/users").WithJSON(tc.user)
request := expect.POST("/api/users").WithJSON(tc.user)
response := request.Expect().Status(tc.status)
response.JSON().IsEqual(tc.responseBody)

Expand Down Expand Up @@ -210,7 +210,7 @@ func TestUserLogin(t *testing.T) {

// Assert that the response status code is 200 and the response body contains the expected values
expect := httpexpect.Default(t, server.URL)
request := expect.POST("/api/v1/users/login").WithJSON(tc.user)
request := expect.POST("/api/users/login").WithJSON(tc.user)
request.Expect().Status(tc.status)

if err := poolMock.ExpectationsWereMet(); err != nil {
Expand Down

0 comments on commit 1e92f3c

Please sign in to comment.