Skip to content

Commit

Permalink
Changes for new Keycloak version
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesLichtenberger committed Jul 10, 2024
1 parent 6141df9 commit 12bff40
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 13 deletions.
29 changes: 28 additions & 1 deletion tests/resources/create-sirix-users.sh
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
/opt/jboss/keycloak/bin/add-user-keycloak.sh -r sirixdb -u admin -p admin --roles create,modify,delete,view
#!/bin/bash

KEYCLOAK_HOME="/opt/keycloak"
REALM="sirixdb"
USERNAME="admin"
PASSWORD="admin"
ROLES="create,modify,delete,view"

user_exists() {
$KEYCLOAK_HOME/bin/kcadm.sh get users -r "$REALM" -q "username=$USERNAME" --fields username | grep -q "\"username\" : \"$USERNAME\""
}

$KEYCLOAK_HOME/bin/kcadm.sh config credentials --server http://localhost:8080 --realm master --user "$USERNAME" --password "$PASSWORD"

if user_exists; then
echo "User '$USERNAME' already exists in realm '$REALM'."
else
if $KEYCLOAK_HOME/bin/kcadm.sh create users -r "$REALM" -s username="$USERNAME" -s enabled=true && \
$KEYCLOAK_HOME/bin/kcadm.sh set-password -r "$REALM" --username "$USERNAME" --new-password "$PASSWORD" && \
for role in $(echo $ROLES | tr "," "\n"); do
$KEYCLOAK_HOME/bin/kcadm.sh add-roles -r "$REALM" --uusername "$USERNAME" --rolename "$role"
done; then
echo "User '$USERNAME' added to realm '$REALM'."
else
echo "Failed to add user '$USERNAME' to realm '$REALM'."
exit 1
fi
fi
37 changes: 26 additions & 11 deletions tests/resources/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
version: '3'
version: '3.4'
services:
keycloak:
image: jboss/keycloak:7.0.1
build: .
ports:
- 8080:8080
environment:
- KEYCLOAK_USER=admin
- KEYCLOAK_PASSWORD=admin
- KEYCLOAK_LOGLEVEL=DEBUG
- KEYCLOAK_IMPORT=/opt/keycloak/realm-export.json
- KEYCLOAK_ADMIN=admin
- KEYCLOAK_ADMIN_PASSWORD=admin
- KC_LOG_LEVEL=DEBUG
- KC_IMPORT=/opt/keycloak/data/import/realm-export.json
restart: always
volumes:
- ./realm-export.json:/opt/keycloak/realm-export.json
- ./create-sirix-users.sh:/opt/jboss/startup-scripts/create-sirix-users.sh
command:
- "-b 0.0.0.0"
- "-bmanagement 0.0.0.0"
- ./realm-export.json:/opt/keycloak/data/import/realm-export.json
entrypoint: ["/opt/keycloak/scripts/wait-for-keycloak.sh"]
command: >
start-dev
--import-realm
--http-relative-path=/
--hostname-strict=false
--proxy=edge
networks:
- auth-network
healthcheck:
test: "curl -f http://localhost:8080/ || exit 1"
timeout: 3s
start_period: 10s
retries: 20
server:
image: sirixdb/sirix
ports:
Expand All @@ -25,3 +35,8 @@ services:
- /opt/sirix/sirix-data:/opt/sirix/sirix-data
- ./sirix-conf.json:/opt/sirix/sirix-conf.json
- ./logback-test.xml:/opt/sirix/sirix-data/logback-test.xml
networks:
- auth-network
networks:
auth-network:
driver: bridge
16 changes: 16 additions & 0 deletions tests/resources/wait-for-keycloak.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# Start Keycloak in the background
/opt/keycloak/bin/kc.sh "$@" &

# Wait for Keycloak to be ready
until curl -sf http://localhost:8080 > /dev/null; do
echo "Waiting for Keycloak to be ready..."
sleep 5
done

# Keycloak is ready, run the create-sirix-users.sh script
/opt/keycloak/scripts/create-sirix-users.sh

# Keep the container running
wait
2 changes: 1 addition & 1 deletion tests/test_json_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def setup_function():
global client
global sirix
global store
client = httpx.Client(base_url=base_url)
client = httpx.Client(base_url=base_url,timeout=None)
sirix = pysirix.sirix_sync("admin", "admin", client)
db = sirix.database("First", DBType.JSON)
store = db.json_store("test_resource")
Expand Down

0 comments on commit 12bff40

Please sign in to comment.