Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjusting Deployment to work with Keycloak Client Secret #34

Merged
merged 3 commits into from
Dec 26, 2024
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
7 changes: 6 additions & 1 deletion .github/workflows/deploy-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,14 @@ jobs:
echo "DB_NAME=${{ vars.DB_NAME }}" >> .env.prod
echo "DB_USER=${{ vars.DB_USER }}" >> .env.prod
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> .env.prod


echo "KEYCLOAK_HOST=${{ vars.KEYCLOAK_HOST }}" >> .env.prod
echo "KEYCLOAK_REALM_NAME=${{ vars.KEYCLOAK_REALM_NAME }}" >> .env.prod
echo "KEYCLOAK_REALM=${{ vars.KEYCLOAK_REALM_NAME }}" >> .env.prod
echo "KEYCLOAK_CLIENT_ID=${{ vars.KEYCLOAK_CLIENT_ID }}" >> .env.prod
echo "KEYCLOAK_CLIENT_SECRET=${{ secrets.KEYCLOAK_CLIENT_SECRET }}" >> .env.prod
echo "KEYCLOAK_ID_OF_CLIENT=${{ secrets.KEYCLOAK_ID_OF_SERVER_CLIENT }}" >> .env.prod

echo "SERVER_IMAGE_TAG=${{ inputs.server_image_tag }}" >> .env.prod
echo "CORE_IMAGE_TAG=${{ inputs.core_image_tag }}" >> .env.prod
echo "TEMPLATE_IMAGE_TAG=${{ inputs.template_image_tag }}" >> .env.prod
Expand Down
5 changes: 5 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ services:
- DB_HOST
- DB_PORT
- DB_NAME
- KEYCLOAK_HOST
- KEYCLOAK_REALM
- KEYCLOAK_CLIENT_ID
- KEYCLOAK_CLIENT_SECRET
- KEYCLOAK_ID_OF_CLIENT
networks:
- prompt-network

Expand Down
24 changes: 24 additions & 0 deletions server/applicationAdministration/main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package applicationAdministration

import (
"context"

"github.com/gin-gonic/gin"
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgxpool"
db "github.com/niclasheun/prompt2.0/db/sqlc"
"github.com/niclasheun/prompt2.0/keycloak"
"github.com/niclasheun/prompt2.0/permissionValidation"
log "github.com/sirupsen/logrus"
)

func InitApplicationAdministrationModule(routerGroup *gin.RouterGroup, queries db.Queries, conn *pgxpool.Pool) {
Expand All @@ -14,6 +18,26 @@ func InitApplicationAdministrationModule(routerGroup *gin.RouterGroup, queries d
queries: queries,
conn: conn,
}

// check if the application module exists in the types
ctx := context.Background()
exists, err := ApplicationServiceSingleton.queries.TestApplicationPhaseTypeExists(ctx)
if err != nil {
log.Error("failed to check if application phase type exists: ", err)
}
if !exists {
// create the application module
newApplicationPhaseType := db.CreateCoursePhaseTypeParams{
ID: uuid.New(),
Name: "Application",
}
err := ApplicationServiceSingleton.queries.CreateCoursePhaseType(ctx, newApplicationPhaseType)
if err != nil {
log.Error("failed to create application module: ", err)
}
} else {
log.Debug("application module already exists")
}
}

// initializes the handler func with CheckCoursePermissions
Expand Down
13 changes: 12 additions & 1 deletion server/db/query/course_phase_type.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
-- name: GetAllCoursePhaseTypes :many
SELECT * FROM course_phase_type;
SELECT * FROM course_phase_type;

-- name: TestApplicationPhaseTypeExists :one
SELECT EXISTS (
SELECT 1
FROM course_phase_type
WHERE name = 'Application'
) AS does_exist;

-- name: CreateCoursePhaseType :exec
INSERT INTO course_phase_type (id, name)
VALUES ($1, $2);
32 changes: 32 additions & 0 deletions server/db/sqlc/course_phase_type.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ func runMigrations(databaseURL string) {
}

func initKeycloak() {
baseURL := utils.GetEnv("KEYCLOAK_BASE_URL", "http://localhost:8081")
baseURL := utils.GetEnv("KEYCLOAK_HOST", "http://localhost:8081")
realm := utils.GetEnv("KEYCLOAK_REALM", "prompt")
clientID := utils.GetEnv("KEYCLOAK_CLIENT_ID", "prompt-server")
clientSecret := utils.GetEnv("KEYCLOAK_CLIENT_SECRET", "")
idOfClient := utils.GetEnv("KEYCLOAK_ID_OF_CLIENT", "")

log.Debug("Debugging: baseURL: ", baseURL, " realm: ", realm, " clientID: ", clientID, " idOfClient: ", idOfClient)

err := keycloak.InitKeycloak(context.Background(), baseURL, realm, clientID, clientSecret, idOfClient)
if err != nil {
log.Error("Failed to initialize keycloak: ", err)
Expand Down
Loading